Skip to content

Commit 6bc8dd2

Browse files
authored
refactor: Remove WEAVER_DEV and derive mode from metrics_repo (#9)
* refactor: derive mode from metrics_repo, remove WEAVER_DEV * Update ship status and record PR URL
1 parent a979e00 commit 6bc8dd2

13 files changed

Lines changed: 477 additions & 84 deletions

File tree

docs/memory/configuration/config-system.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Overview
44

5-
Configuration is managed via INI-style `.conf` files (`src/config.ts`). A layered system merges defaults from the package (`tu.default.conf`) with user overrides (`~/.tu.conf`). The `WEAVER_DEV` env var switches the default config to `tu.default.weaver.conf` (pre-configured for multi mode with the wvrdz metrics repo).
5+
Configuration is managed via INI-style `.conf` files (`src/node/core/config.ts`). A layered system merges defaults from the package (`tu.default.conf`) with user overrides (`~/.tu.conf`). The `TU_METRICS_REPO` env var can override `metrics_repo` from config files, enabling multi-machine mode without editing config.
66

77
## Requirements
88

@@ -12,18 +12,23 @@ Configuration is managed via INI-style `.conf` files (`src/config.ts`). A layere
1212
- Config version MUST be tracked (`version` field, current: 2); warn if newer than supported
1313
- Sentinel values MUST be expanded at runtime: `$HOSTNAME` -> `os.hostname()`, `$USER` -> `os.userInfo().username`
1414
- `~` prefix in paths MUST be resolved to `homedir()`
15-
- `TuConfig` interface fields: `version`, `mode` (single/multi), `metricsRepo`, `metricsDir`, `machine`, `user`, `autoSync`
16-
- `mode=multi` without `metrics_repo` MUST warn and fall back to single
15+
- `TuConfig` interface fields: `version`, `mode` (single/multi, derived), `metricsRepo`, `metricsDir`, `machine`, `user`, `autoSync`
16+
- `mode` MUST be derived from `metricsRepo` presence: non-empty → `"multi"`, empty → `"single"`
17+
- `TU_METRICS_REPO` env var (when non-empty) MUST take precedence over config file `metrics_repo`
18+
- `mode` field in config files MUST be silently ignored (backward compat)
1719
- `auto_sync` MUST default to true; only `"false"` or `"0"` disable it
1820
- `init-conf` MUST scaffold `~/.tu.conf` from defaults if missing, or append missing fields if present
1921
- `init-conf` MUST detect commented-out fields and suggest uncommenting them
22+
- `init-conf` scaffold MUST NOT include a `mode` field
2023
- `status` command MUST display mode, user, machine, config path, metrics path, last sync time, auto-sync state
2124
- Last sync time MUST be formatted as relative time (e.g., "3h ago") with ISO timestamp
2225

2326
## Design Decisions
2427

2528
- **INI over YAML/JSON**: Simpler to hand-edit, no indentation issues, trivial to parse. Good fit for a small number of flat config fields.
26-
- **Layered defaults**: The package ships `tu.default.conf` so the tool works out of the box in single mode. Users only need to override fields they want to change. `tu.default.weaver.conf` provides team-specific defaults.
29+
- **Layered defaults**: The package ships `tu.default.conf` so the tool works out of the box in single mode. Users only need to override fields they want to change.
30+
- **Derived mode**: `mode` is computed from `metricsRepo !== ""` rather than stored as a config field. This eliminates the redundancy where `mode=multi` without `metrics_repo` was meaningless, and makes the config surface smaller.
31+
- **TU_METRICS_REPO env var**: Replaces the old `WEAVER_DEV` mechanism. Any user or CI can set `TU_METRICS_REPO` to enable multi mode without editing config files. Empty string is treated as unset.
2732
- **Sentinel expansion**: `$HOSTNAME` and `$USER` sentinels allow the same config file to work across machines without per-machine customization.
2833
- **Version field**: Enables future config migrations. Currently only warns on newer versions.
2934
- **Home directory `~/.tu/`**: All runtime state (cache, metrics, sync markers) lives under `~/.tu/`. Config file is at `~/.tu.conf` (top level, not nested).
@@ -32,4 +37,5 @@ Configuration is managed via INI-style `.conf` files (`src/config.ts`). A layere
3237

3338
| Date | Change |
3439
|------|--------|
40+
| 2026-04-01 | Removed WEAVER_DEV env var and tu.default.weaver.conf. Mode now derived from metrics_repo presence. Added TU_METRICS_REPO env var override. Removed mode from config file format and init-conf scaffold. |
3541
| 2026-03-06 | Generated from code analysis |
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{"action":"enter","driver":"fab-new","event":"stage-transition","stage":"intake","ts":"2026-04-01T05:54:26Z"}
2+
{"args":"Remove WEAVER_DEV env var and tu.default.weaver.conf; derive mode from metrics_repo presence","cmd":"fab-new","event":"command","ts":"2026-04-01T05:54:26Z"}
3+
{"delta":"+4.7","event":"confidence","score":4.7,"trigger":"calc-score","ts":"2026-04-01T05:55:22Z"}
4+
{"delta":"+0.0","event":"confidence","score":4.7,"trigger":"calc-score","ts":"2026-04-01T05:55:27Z"}
5+
{"cmd":"fab-switch","event":"command","ts":"2026-04-01T05:56:17Z"}
6+
{"cmd":"fab-fff","event":"command","ts":"2026-04-01T05:57:37Z"}
7+
{"action":"enter","driver":"fab-fff","event":"stage-transition","stage":"spec","ts":"2026-04-01T05:58:17Z"}
8+
{"delta":"+0.3","event":"confidence","score":5,"trigger":"calc-score","ts":"2026-04-01T05:59:12Z"}
9+
{"delta":"+0.0","event":"confidence","score":5,"trigger":"calc-score","ts":"2026-04-01T05:59:16Z"}
10+
{"action":"enter","driver":"fab-fff","event":"stage-transition","stage":"tasks","ts":"2026-04-01T05:59:25Z"}
11+
{"action":"enter","driver":"fab-fff","event":"stage-transition","stage":"apply","ts":"2026-04-01T06:00:04Z"}
12+
{"action":"enter","driver":"fab-fff","event":"stage-transition","stage":"review","ts":"2026-04-01T06:07:07Z"}
13+
{"action":"enter","driver":"fab-fff","event":"stage-transition","stage":"hydrate","ts":"2026-04-01T06:10:45Z"}
14+
{"event":"review","result":"passed","ts":"2026-04-01T06:10:45Z"}
15+
{"action":"enter","driver":"fab-fff","event":"stage-transition","stage":"ship","ts":"2026-04-01T06:11:27Z"}
16+
{"action":"enter","driver":"git-pr","event":"stage-transition","stage":"review-pr","ts":"2026-04-01T06:12:54Z"}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
id: jufw
2+
name: 260401-jufw-remove-weaver-dev-derive-mode
3+
created: 2026-04-01T05:54:26Z
4+
created_by: sahil-weaver
5+
change_type: refactor
6+
issues: []
7+
progress:
8+
intake: done
9+
spec: done
10+
tasks: done
11+
apply: done
12+
review: done
13+
hydrate: done
14+
ship: done
15+
review-pr: active
16+
checklist:
17+
generated: true
18+
path: checklist.md
19+
completed: 0
20+
total: 25
21+
confidence:
22+
certain: 9
23+
confident: 0
24+
tentative: 0
25+
unresolved: 0
26+
score: 5.0
27+
fuzzy: true
28+
dimensions:
29+
signal: 90.6
30+
reversibility: 87.2
31+
competence: 91.7
32+
disambiguation: 93.3
33+
stage_metrics:
34+
intake: {started_at: "2026-04-01T05:54:26Z", driver: fab-new, iterations: 1, completed_at: "2026-04-01T05:58:17Z"}
35+
spec: {started_at: "2026-04-01T05:58:17Z", driver: fab-fff, iterations: 1, completed_at: "2026-04-01T05:59:25Z"}
36+
tasks: {started_at: "2026-04-01T05:59:25Z", driver: fab-fff, iterations: 1, completed_at: "2026-04-01T06:00:04Z"}
37+
apply: {started_at: "2026-04-01T06:00:04Z", driver: fab-fff, iterations: 1, completed_at: "2026-04-01T06:07:07Z"}
38+
review: {started_at: "2026-04-01T06:07:07Z", driver: fab-fff, iterations: 1, completed_at: "2026-04-01T06:10:45Z"}
39+
hydrate: {started_at: "2026-04-01T06:10:45Z", driver: fab-fff, iterations: 1, completed_at: "2026-04-01T06:11:27Z"}
40+
ship: {started_at: "2026-04-01T06:11:27Z", driver: fab-fff, iterations: 1, completed_at: "2026-04-01T06:12:54Z"}
41+
review-pr: {started_at: "2026-04-01T06:12:54Z", driver: git-pr, iterations: 1}
42+
prs:
43+
- https://github.com/wvrdz/tu/pull/9
44+
last_updated: 2026-04-01T06:12:54Z
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Quality Checklist: Remove WEAVER_DEV and derive mode from metrics_repo
2+
3+
**Change**: 260401-jufw-remove-weaver-dev-derive-mode
4+
**Generated**: 2026-04-01
5+
**Spec**: `spec.md`
6+
7+
## Functional Completeness
8+
- [x] CHK-001 Mode derivation: `readConfig()` returns `mode=multi` when `metrics_repo` is set, `mode=single` when absent
9+
- [x] CHK-002 TU_METRICS_REPO override: env var takes precedence over config file `metrics_repo`
10+
- [x] CHK-003 Empty TU_METRICS_REPO: empty string does not override config file value
11+
- [x] CHK-004 DEFAULT_CONFIG_PATH: always resolves to `tu.default.conf` unconditionally
12+
- [x] CHK-005 init-conf scaffold: generated `~/.tu.conf` has no `mode` line
13+
- [x] CHK-006 Error messages: `runSync` and `runInitMetrics` reference `metrics_repo`/`TU_METRICS_REPO`
14+
15+
## Behavioral Correctness
16+
- [x] CHK-007 Mode field ignored: config files with `mode = single` + `metrics_repo` set produce `mode=multi`
17+
- [x] CHK-008 Mode field ignored: config files with `mode = multi` + no `metrics_repo` produce `mode=single`
18+
- [x] CHK-009 Backward compat: existing `~/.tu.conf` with `mode` lines loads without error
19+
- [x] CHK-010 TuConfig interface: `mode` field still present, downstream consumers unchanged
20+
21+
## Removal Verification
22+
- [x] CHK-011 WEAVER_DEV: no references to `WEAVER_DEV` in source code
23+
- [x] CHK-012 tu.default.weaver.conf: file deleted from repository
24+
- [x] CHK-013 mode in FIELD_BLOCKS: `mode` entry removed from init-conf scaffold
25+
- [x] CHK-014 mode=multi warning: old "mode=multi but no metrics_repo" warning removed
26+
27+
## Scenario Coverage
28+
- [x] CHK-015 Test: metrics_repo set → mode=multi
29+
- [x] CHK-016 Test: no metrics_repo → mode=single
30+
- [x] CHK-017 Test: TU_METRICS_REPO env var override
31+
- [x] CHK-018 Test: empty TU_METRICS_REPO ignored
32+
- [x] CHK-019 Test: real default conf (no WEAVER_DEV branching)
33+
34+
## Edge Cases & Error Handling
35+
- [x] CHK-020 Both config files missing: graceful fallback to single mode
36+
- [x] CHK-021 Config with only mode field (no metrics_repo): produces single mode, no crash
37+
38+
## Code Quality
39+
- [x] CHK-022 Pattern consistency: new code follows functional style, `node:` prefixed imports
40+
- [x] CHK-023 No unnecessary duplication: TU_METRICS_REPO check is a single point in readConfig
41+
- [x] CHK-024 No dynamic import: no new `import()` calls introduced
42+
- [x] CHK-025 Error paths warn on stderr: any new error/warning uses stderr
43+
44+
## Notes
45+
46+
- Check items as you review: `- [x]`
47+
- All items must pass before `/fab-continue` (hydrate)
48+
- If an item is not applicable, mark checked and prefix with **N/A**: `- [x] CHK-008 **N/A**: {reason}`
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Intake: Remove WEAVER_DEV and derive mode from metrics_repo
2+
3+
**Change**: 260401-jufw-remove-weaver-dev-derive-mode
4+
**Created**: 2026-04-01
5+
**Status**: Draft
6+
7+
## Origin
8+
9+
> User described this change with full implementation decisions pre-made from a prior discussion. The input specifies exactly which files change, what the new runtime behavior is, and which config artifacts are deleted. This is a detailed, decision-complete request.
10+
11+
## Why
12+
13+
The `WEAVER_DEV` env var and `tu.default.weaver.conf` file exist solely to configure the wvrdz team's multi-mode setup. This leaks a project-specific concern (the wvrdz metrics repo URL) into the generic codebase. Additionally, having `mode` as an explicit config field creates a redundancy: `mode=multi` is meaningless without `metrics_repo`, and `metrics_repo` being set implies multi mode. Deriving `mode` from `metrics_repo` presence eliminates both the redundancy and the project-specific config machinery, making the codebase fully generic.
14+
15+
Without this change, any fork or external user encounters a confusing `WEAVER_DEV` env var with no documentation, two defaults files with unclear selection logic, and a `mode` field that can desync from `metrics_repo`.
16+
17+
## What Changes
18+
19+
### 1. Remove `WEAVER_DEV` env var detection (`src/node/core/config.ts`)
20+
21+
The `DEFAULT_CONFIG_PATH` export currently branches on `process.env.WEAVER_DEV` (line 33) to select between `tu.default.conf` and `tu.default.weaver.conf`. This branching is removed entirely. `DEFAULT_CONFIG_PATH` always resolves to `tu.default.conf`:
22+
23+
```typescript
24+
export const DEFAULT_CONFIG_PATH = resolve(_rootDir, "tu.default.conf");
25+
```
26+
27+
### 2. Add `TU_METRICS_REPO` env var (`src/node/core/config.ts`)
28+
29+
In `readConfig()`, after merging defaults and user config, check `process.env.TU_METRICS_REPO`. If set, it overrides the config file's `metrics_repo` value:
30+
31+
```typescript
32+
const metricsRepo = process.env.TU_METRICS_REPO || merged.metrics_repo || "";
33+
```
34+
35+
This is the generic replacement for what `WEAVER_DEV` + `tu.default.weaver.conf` did. Any user or CI can set `TU_METRICS_REPO` to enable multi mode without editing config files.
36+
37+
### 3. Derive `mode` at runtime (`src/node/core/config.ts`)
38+
39+
Remove the explicit `mode` parsing from the merged config. Instead, derive it from `metricsRepo` presence:
40+
41+
```typescript
42+
const mode: TuConfig["mode"] = metricsRepo !== "" ? "multi" : "single";
43+
```
44+
45+
The `mode` field remains on the `TuConfig` interface so all downstream consumers (cli.ts, sync.ts, etc.) are unchanged. The `mode=` line in user config files is silently ignored (the parser still reads it but `readConfig()` no longer uses it).
46+
47+
The existing warning for `mode=multi` without `metrics_repo` is removed since that state is now impossible.
48+
49+
### 4. Delete `tu.default.weaver.conf`
50+
51+
This file is deleted entirely. There is only one defaults file (`tu.default.conf`).
52+
53+
### 5. Update `tu.default.conf`
54+
55+
Remove the `mode = single` line. The `metrics_repo` line remains commented out (single mode by default, since no `metrics_repo` means `mode=single`). Config version stays at 2.
56+
57+
### 6. Update `init-conf` scaffold (`src/node/core/cli.ts`)
58+
59+
Remove the `mode` entry from `FIELD_BLOCKS` so the generated `~/.tu.conf` template does not include a `mode` line. The remaining fields are unchanged.
60+
61+
### 7. Update `init-metrics` mode check (`src/node/core/cli.ts`)
62+
63+
The `runInitMetrics` function currently checks `config.mode !== "multi"` and errors. After this change, `mode` is derived from `metricsRepo`, so this check naturally works: if `metrics_repo` is set, `mode` will be `multi`. The explicit error message should be updated to reference `metrics_repo` instead of `mode=multi`.
64+
65+
### 8. Update `runSync` error message (`src/node/core/cli.ts`)
66+
67+
The sync error message currently says "set mode=multi". Update to reference `metrics_repo` or `TU_METRICS_REPO` instead.
68+
69+
### 9. Update tests (`src/node/core/__tests__/config.test.ts`)
70+
71+
- Remove `WEAVER_DEV` branching in the "works with the real default conf" test (line 244). After this change, the real default conf always produces `mode=single` with empty `metricsRepo`.
72+
- Update tests that explicitly set `mode=multi` to verify that mode is now derived from `metrics_repo` presence rather than explicit `mode` field.
73+
- Add a test for `TU_METRICS_REPO` env var override.
74+
- Update the `STOCK_DEFAULTS` constant to remove the `mode = single` line.
75+
- Update the test "returns single mode when user sets mode=single" to verify that `mode` in config is ignored (metrics_repo drives mode).
76+
- Update the test "falls back to single mode when mode=multi but metrics_repo is missing" since the warning message changes (or is removed entirely).
77+
78+
## Affected Memory
79+
80+
- `configuration/config-system`: (modify) Remove WEAVER_DEV documentation, add TU_METRICS_REPO, document mode derivation from metrics_repo
81+
82+
## Impact
83+
84+
- **`src/node/core/config.ts`** — main changes: remove WEAVER_DEV branching, add TU_METRICS_REPO, derive mode from metricsRepo
85+
- **`src/node/core/cli.ts`** — update FIELD_BLOCKS (remove mode), update error messages referencing mode=multi
86+
- **`src/node/core/__tests__/config.test.ts`** — remove WEAVER_DEV branching, update mode derivation tests, add TU_METRICS_REPO test
87+
- **`tu.default.conf`** — remove mode line
88+
- **`tu.default.weaver.conf`** — delete entirely
89+
- **No breaking changes to downstream consumers**`TuConfig.mode` field and all its usages remain identical; only the derivation logic changes
90+
91+
## Open Questions
92+
93+
(none)
94+
95+
## Assumptions
96+
97+
| # | Grade | Decision | Rationale | Scores |
98+
|---|-------|----------|-----------|--------|
99+
| 1 | Certain | Config version stays at 2 | Explicitly stated in the description; no config schema change, only behavior change | S:95 R:90 A:95 D:95 |
100+
| 2 | Certain | `TuConfig` interface keeps `mode` field | Explicitly stated; all downstream consumers unchanged | S:95 R:85 A:95 D:95 |
101+
| 3 | Certain | `mode` lines in existing user configs are silently ignored | Explicitly stated; parseConf still reads them but readConfig does not use the value | S:90 R:90 A:90 D:90 |
102+
| 4 | Certain | `TU_METRICS_REPO` takes precedence over config file `metrics_repo` | Explicitly stated in the description | S:95 R:85 A:90 D:95 |
103+
| 5 | Certain | `tu.default.weaver.conf` is deleted, not deprecated | Explicitly stated in the description | S:95 R:80 A:90 D:95 |
104+
| 6 | Certain | `brew install wvrdz/tap/tu` hardcoding in cli.ts is out of scope | Explicitly stated in the description | S:95 R:95 A:95 D:95 |
105+
| 7 | Confident | Error messages in `runInitMetrics` and `runSync` should reference `metrics_repo`/`TU_METRICS_REPO` instead of `mode=multi` | Logical consequence of removing mode from config; user can no longer "set mode=multi" | S:70 R:85 A:80 D:80 |
106+
107+
7 assumptions (6 certain, 1 confident, 0 tentative, 0 unresolved).

0 commit comments

Comments
 (0)