@ngockhoale/ukit 3.4.22 → 3.4.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/manifests/platform.full.yaml +29 -0
  3. package/package.json +1 -1
  4. package/src/cli/commands/telemetry.js +67 -4
  5. package/src/cli/index.js +1 -1
  6. package/src/core/docContracts.js +60 -6
  7. package/src/core/observability/adapters/routeAdapter.js +48 -9
  8. package/src/core/observability/analytics/usageReadiness.js +342 -0
  9. package/src/core/observability/privacy/allowlist.js +10 -1
  10. package/src/core/observability/schema/constants.js +13 -0
  11. package/src/core/observability/schema/registry.js +20 -0
  12. package/src/core/observability/schema/validate.js +45 -2
  13. package/src/core/observability/segments/readSegments.js +23 -1
  14. package/template_project/.claude/agents/feature-implementer.md +10 -3
  15. package/template_project/.claude/commands/ukit/handoff-clear.md +27 -12
  16. package/template_project/.claude/commands/ukit/handoff-fullstack.md +65 -32
  17. package/template_project/.claude/commands/ukit/handoff-implement.md +44 -23
  18. package/template_project/.claude/hooks/handoff-resume.sh +36 -11
  19. package/template_project/.claude/hooks/protect-files.sh +10 -2
  20. package/template_project/.claude/hooks/vision-router.sh +11 -1
  21. package/template_project/.claude/ukit/index/cleanup-task-worktree.mjs +418 -0
  22. package/template_project/.claude/ukit/index/extract-image.mjs +77 -22
  23. package/template_project/.claude/ukit/index/land-worktree.mjs +543 -0
  24. package/template_project/.claude/ukit/index/stale-spec-check.mjs +48 -1
  25. package/template_project/.claude/ukit/runtime/handoff-intent.mjs +86 -28
  26. package/template_project/.claude/ukit/runtime/hook-chain-runner.mjs +60 -0
  27. package/template_project/.claude/ukit/runtime/observability-emit.mjs +53 -2
  28. package/template_project/.claude/ukit/runtime/output-compression.mjs +46 -20
  29. package/template_project/.claude/ukit/runtime/stop-coordinator.mjs +16 -2
  30. package/template_project/.omp/agents/feature-implementer.md +10 -3
@@ -462,43 +462,65 @@ them back a second time is what blows up the orchestrator's context window and k
462
462
  run mid-pipeline.
463
463
  ```
464
464
 
465
- **3c — Copy changes back + delete worktrees** (orchestrator, after each task reports):
465
+ **3c — Land each task's work + hand off worktree state** (orchestrator, after each task reports):
466
+
467
+ Landing is **task-scoped, base-relative and receipt-backed** — never an ad-hoc cp loop.
468
+ `land-worktree.mjs` snapshots the source worktree's FINAL content against the immutable
469
+ `$BASE` (committed milestone + staged + unstaged + nonignored untracked), so committed and
470
+ staged work is never dropped, deletions and rename origins are applied, and binary /
471
+ executable / symlink semantics and unusual filenames (space / newline / literal backslash)
472
+ survive. The helper refuses on any destination conflict, scope drift or identity drift
473
+ **before mutating anything** and writes no receipt on refusal.
466
474
 
467
475
  For **PASS + EXECUTOR_MODEL present:**
468
476
  ```bash
477
+ TASK="TASK-xxx"
469
478
  WORKTREE=".worktrees/task-xxx"
470
479
 
471
- # Copy modified tracked files to main working tree
472
- git -C "$WORKTREE" diff --name-only | while read f; do
473
- mkdir -p "$(dirname "$f")"
474
- cp "$WORKTREE/$f" "$f"
475
- done
476
-
477
- # Copy new untracked files
478
- git -C "$WORKTREE" ls-files --others --exclude-standard | while read f; do
479
- mkdir -p "$(dirname "$f")"
480
- cp "$WORKTREE/$f" "$f"
481
- done
482
-
483
- # Delete worktree and branch immediately
484
- git worktree remove "$WORKTREE" --force
485
- git branch -D handoff/task-xxx
480
+ # Scope = the exact task-approved target paths (both rename endpoints).
481
+ # Written outside the source worktree AND outside the target set.
482
+ cat > ".worktrees/$TASK-scope.json" <<JSON
483
+ {
484
+ "schemaVersion": 1,
485
+ "taskId": "$TASK",
486
+ "baseCommit": "$(git rev-parse $BASE)",
487
+ "sourceRoot": "$(git -C "$WORKTREE" rev-parse --show-toplevel)",
488
+ "destinationRoot": "$(git rev-parse --show-toplevel)",
489
+ "sourceHead": "$(git -C "$WORKTREE" rev-parse HEAD)",
490
+ "destinationHead": "$(git rev-parse HEAD)",
491
+ "targetPaths": ["<each approved path>"]
492
+ }
493
+ JSON
494
+
495
+ node .claude/ukit/index/land-worktree.mjs \
496
+ --scope ".worktrees/$TASK-scope.json" \
497
+ --receipt "docs/AI_HANDOFF/benchmark/$TASK-landing.json"
498
+ # exit 0 → landed (receipt written); exit 2 → refused, both repos untouched;
499
+ # exit 1 → apply/receipt failure, source retained, never a success claim.
500
+ # After each exit-0 landing, checkpoint-commit the landed paths (receipt stays outside the target set)
501
+ # BEFORE landing the next task: the helper refuses a destination with tracked modifications
502
+ # (destination-dirty), so uncommitted landed work would block every later task in the wave.
503
+ git add -- <landed paths> && git commit -m "checkpoint: $TASK landed"
504
+
505
+ # update INDEX.md: status → pending_review
486
506
  ```
487
507
 
488
508
  For **FAIL:**
489
509
  ```bash
490
- git worktree remove .worktrees/task-xxx --force
491
- git branch -D handoff/task-xxx
510
+ # Landing is refused by contract (no EXECUTOR_REPORT). Retain the worktree and branch
511
+ # as recovery evidence and mark it in INDEX.md:
512
+ # status → blocked, reason "FAIL"
492
513
  ```
493
514
 
494
515
  For **EXECUTOR_MODEL missing:**
495
516
  ```bash
496
- git worktree remove .worktrees/task-xxx --force
497
- git branch -D handoff/task-xxx
498
- # mark needs_executor_report in INDEX
517
+ # No model attestation → no landing authority. Retain the worktree and branch:
518
+ # status → needs_executor_report
499
519
  ```
500
520
 
501
- Worktrees are **always deleted immediately** — no exceptions.
521
+ A refused or retained worktree keeps its source recovery evidence. Removal is a separate,
522
+ receipt-gated step (`cleanup-task-worktree.mjs`); it is never an unconditional forced
523
+ removal or branch deletion sitting on the same page as the landing.
502
524
 
503
525
  **3d — Wave boundary: commit + context checkpoint** (orchestrator, after every wave)
504
526
 
@@ -546,12 +568,15 @@ logs used to cost. That difference is what makes a multi-wave cycle finish in on
546
568
  - EXECUTOR_MODEL missing → `needs_executor_report`
547
569
  Then **verify the write** (read back the updated status column).
548
570
 
549
- 2. Verify cleanup:
571
+ 2. Verify cleanup with the **retained-reason report** — not an only-main assertion:
550
572
  ```bash
551
- git worktree list # must show only main worktree
552
- git branch | grep handoff # must be empty
573
+ git worktree list # every remaining .worktrees/* entry must be named in the retained-reason report
574
+ git branch | grep handoff # every handoff/* branch must be named in the retained-reason report
553
575
  git diff --stat # summary of all uncommitted changes
554
576
  ```
577
+ A **retained-reason report** names every surviving worktree/branch and why it stays
578
+ (receipt missing, not approved, FAIL, missing model, dirty vs snapshot, unmerged
579
+ history). Unexplained leftovers fail the gate; nothing is removed by force.
555
580
 
556
581
  ---
557
582
 
@@ -744,19 +769,27 @@ start, and emit the Final Report below.
744
769
  Run at the very end of every cycle, regardless of outcome:
745
770
 
746
771
  ```bash
747
- git worktree list # must show ONLY main worktree
748
- git branch | grep handoff # must be EMPTY
772
+ git worktree list # every remaining .worktrees/* entry must be named in the retained-reason report
773
+ git branch | grep handoff # every handoff/* branch must be named in the retained-reason report
749
774
  git status # clean (fully approved + pushed) or expected partial state
750
775
  ```
751
776
 
752
- If any lingering worktrees or handoff branches found, force-remove them:
777
+ Every remaining `.worktrees/*` entry and every `handoff/*` branch must be named in a
778
+ **retained-reason report**: receipt missing, not approved, FAIL, missing model, dirty vs
779
+ snapshot, unmerged history. Unexplained leftovers fail the gate.
780
+
781
+ If a lingering worktree carries a verified, independently approved receipt whose source
782
+ still matches the snapshot and is Git-clean, retire it through the shared helper — never by
783
+ forcing it:
784
+
753
785
  ```bash
754
- # For each lingering worktree/branch:
755
- git worktree remove .worktrees/<name> --force
756
- git branch -D handoff/<name>
786
+ # For each lingering task worktree with a verified receipt + approval:
787
+ node .claude/ukit/index/cleanup-task-worktree.mjs \
788
+ --receipt <receipt-json> --approval <approval-json> --apply
789
+ # Anything without that authority is RETAINED and reported with its reason.
757
790
  ```
758
791
 
759
- Re-run assertions after removal to confirm clean state.
792
+ Re-run the assertions after cleanup to confirm the same named-retention state.
760
793
 
761
794
  ---
762
795
 
@@ -172,49 +172,64 @@ second time is what blows up the orchestrator's context window and kills the run
172
172
 
173
173
  > **For the human operator, on a tool with no agent support (Codex) — not an instruction to the model:** open each task in a separate session with the code model.
174
174
 
175
- ### 3c — Orchestrator: copy changes to main + IMMEDIATELY delete worktree
175
+ ### 3c — Orchestrator: land each task's work (task-scoped, receipt-backed)
176
+
177
+ Landing uses the shared helper, never an ad-hoc cp loop. `land-worktree.mjs` snapshots
178
+ the source worktree's FINAL content relative to the immutable `$BASE` — committed
179
+ milestone, staged, unstaged and nonignored untracked changes, with deletions, rename
180
+ origins and binary / executable / symlink semantics — and applies that exact delta to the
181
+ destination. It refuses (exit 2, no mutation, no receipt) on a dirty destination, a
182
+ target-path untracked collision, an out-of-scope change or identity drift.
176
183
 
177
184
  For each task that reported back:
178
185
 
179
186
  **PASS + EXECUTOR_MODEL present:**
180
187
  ```bash
188
+ TASK="TASK-xxx"
181
189
  WORKTREE=".worktrees/task-xxx"
182
190
 
183
- # Copy modified tracked files to main working tree
184
- git -C "$WORKTREE" diff --name-only | while read f; do
185
- mkdir -p "$(dirname "$f")"
186
- cp "$WORKTREE/$f" "$f"
187
- done
188
-
189
- # Copy new untracked files
190
- git -C "$WORKTREE" ls-files --others --exclude-standard | while read f; do
191
- mkdir -p "$(dirname "$f")"
192
- cp "$WORKTREE/$f" "$f"
193
- done
194
-
195
- # Delete worktree and branch immediately
196
- git worktree remove "$WORKTREE" --force
197
- git branch -D handoff/task-xxx
191
+ # Scope file: exact task-approved target paths (both rename endpoints). Written
192
+ # outside the source worktree AND outside the target set.
193
+ cat > ".worktrees/$TASK-scope.json" <<JSON
194
+ {
195
+ "schemaVersion": 1,
196
+ "taskId": "$TASK",
197
+ "baseCommit": "$BASE",
198
+ "sourceRoot": "$(git -C "$WORKTREE" rev-parse --show-toplevel)",
199
+ "destinationRoot": "$(git rev-parse --show-toplevel)",
200
+ "sourceHead": "$(git -C "$WORKTREE" rev-parse HEAD)",
201
+ "destinationHead": "$(git rev-parse HEAD)",
202
+ "targetPaths": ["<each approved path>"]
203
+ }
204
+ JSON
205
+
206
+ node .claude/ukit/index/land-worktree.mjs \
207
+ --scope ".worktrees/$TASK-scope.json" \
208
+ --receipt "docs/AI_HANDOFF/benchmark/$TASK-landing.json"
209
+ # exit 0 → landed; exit 2 → refused (untouched); exit 1 → apply/receipt failure.
210
+ # After each exit-0 landing, checkpoint-commit the landed paths (receipt stays outside the target set)
211
+ # BEFORE landing the next task: the helper refuses a destination with tracked modifications
212
+ # (destination-dirty), so uncommitted landed work would block every later task in the wave.
213
+ git add -- <landed paths> && git commit -m "checkpoint: $TASK landed"
198
214
 
199
215
  # update INDEX.md: status → pending_review
200
216
  ```
201
217
 
202
218
  **FAIL:**
203
219
  ```bash
204
- git worktree remove .worktrees/task-xxx --force
205
- git branch -D handoff/task-xxx
220
+ # No landing for a FAIL report — retain the worktree and branch as recovery evidence.
206
221
  # update INDEX.md: status → blocked
207
222
  ```
208
223
 
209
224
  **EXECUTOR_MODEL missing:**
210
225
  ```bash
211
- git worktree remove .worktrees/task-xxx --force
212
- git branch -D handoff/task-xxx
226
+ # No model attestation → no landing authority. Retain the worktree and branch.
213
227
  # update INDEX.md: status → needs_executor_report
214
228
  ```
215
229
 
216
230
  **Orchestrator writes INDEX.md** — agents never touch INDEX directly.
217
- **Worktrees are always deleted immediately** — no exceptions.
231
+ Worktree/branch removal is a separate, receipt-gated step (`cleanup-task-worktree.mjs`) —
232
+ never an unconditional forced removal or branch deletion sitting next to the landing.
218
233
 
219
234
  ### 3d — Wave boundary: commit + context checkpoint
220
235
 
@@ -246,12 +261,18 @@ Then create the next wave's worktrees from `$BASE` and repeat 3a–3c.
246
261
  All waves complete. Verify:
247
262
 
248
263
  ```bash
249
- git worktree list # must show only main worktree
250
- git branch | grep handoff # must be empty
264
+ git worktree list # every remaining .worktrees/* entry must be named in the retained-reason report
265
+ git branch | grep handoff # every handoff/* branch must be named in the retained-reason report
251
266
  git log --oneline -n 10 # one commit per wave
252
267
  git status # clean, or only trailing edits from the last wave
253
268
  ```
254
269
 
270
+ Every remaining `.worktrees/*` entry and every `handoff/*` branch must be named in a
271
+ **retained-reason report**: receipt missing, not approved, FAIL, missing model, dirty vs
272
+ snapshot, unmerged history. Unexplained leftovers fail the gate; nothing is removed by force.
273
+ An eligible task is retired only through the shared, receipt-gated helper
274
+ (`node .claude/ukit/index/cleanup-task-worktree.mjs --receipt <json> --approval <json> --apply`).
275
+
255
276
  All changes are committed as **one commit per wave on `$BASE`**, nothing pushed. No branches
256
277
  or worktrees remain. Set `Phase: done` in `docs/AI_HANDOFF/RUN.md`.
257
278
 
@@ -196,11 +196,21 @@ async function emitOrdinaryResume(payload, source) {
196
196
  // The session's CURRENT handoff intent — structured transcript evidence, the
197
197
  // same shared module the Stop gate uses. A session whose latest request is
198
198
  // planning (`/ukit:handoff-create`) must never be pushed into implementing a
199
- // stale RUN.md, compact or not. `known` false (no transcript path, unreadable,
200
- // module absent) keeps the existing resume behaviour.
199
+ // stale RUN.md, compact or not. `intent` is null when the read was unknown (no
200
+ // transcript path, unreadable, module absent), which the planning-cursor branch
201
+ // below treats the same as create — a NONTERMINAL `Command: handoff-create`
202
+ // cursor is the planner's file, so an unknown read resolves toward planning.
201
203
  const { intent } = await readHandoffIntent(
202
204
  typeof payload.transcript_path === 'string' ? payload.transcript_path : null,
203
205
  );
206
+ // A NONTERMINAL planning cursor is the one RUN.md the resume lane treats as
207
+ // planning rather than implementation (TASK-C97-006, FR-M2-003): its `Command`
208
+ // says a planner owns the file, so any latest intent that is NOT positively
209
+ // implementation (create, known-null, unknown) gets the planning note. Every
210
+ // other command — actual fullstack/implement/review — keeps the unchanged
211
+ // contract, and an unknown intent there still resolves toward the conservative
212
+ // resume, so a lost read never strands a real run.
213
+ const planningCursor = field('Command').trim().toLowerCase() === 'handoff-create';
204
214
 
205
215
  // A brand-new session (startup / clear) did not start this run and may be about
206
216
  // something else entirely (e.g. planning). Tell it the run exists, but do NOT
@@ -216,17 +226,32 @@ async function emitOrdinaryResume(payload, source) {
216
226
  process.exit(0);
217
227
  }
218
228
 
219
- // Planning intent outranks a live cursor: the user asked this session to plan,
220
- // so report the paused run and let the planning continue. This is the one place
221
- // an automatic resume must yield — /ukit:handoff-create is planning-only by
222
- // contract, and /ukit:handoff-fullstack remains the explicit way to resume.
223
- if (intent === 'create') {
229
+ // Planning outranks a live cursor: the user asked this session to plan (or the
230
+ // cursor itself is the planner's `handoff-create` RUN.md with no positive
231
+ // implementation intent), so report the paused run and let the planning
232
+ // continue. This is the one place an automatic resume must yield —
233
+ // /ukit:handoff-create is planning-only by contract, and /ukit:handoff-fullstack
234
+ // remains the explicit way to resume.
235
+ if (intent === 'create' || (planningCursor && intent !== 'fullstack')) {
236
+ // The reason is stated honestly either way — the session's own request is
237
+ // planning (create), or the cursor itself is the planner's `handoff-create`
238
+ // RUN.md with no positive implementation intent. Neither fabricates ownership.
239
+ const why = intent === 'create'
240
+ ? [
241
+ "but this session's current request",
242
+ 'is planning (/ukit:handoff-create). Stop gate and resume will not force the run here —',
243
+ 'finish the planning first. To resume implementation explicitly, run /ukit:handoff-fullstack;',
244
+ 'to discard the run, /ukit:handoff-clear.',
245
+ ]
246
+ : [
247
+ `and its cursor is planning-only (Command: ${field('Command')}). Neither the Stop gate nor this`,
248
+ 'resume will force implementation here. To resume implementation explicitly, run',
249
+ '/ukit:handoff-fullstack; to discard the run, /ukit:handoff-clear.',
250
+ ];
224
251
  process.stdout.write([
225
252
  'UKit note: docs/AI_HANDOFF/RUN.md has an unfinished handoff-fullstack run '
226
- + `(Phase: ${phase}; Next: ${next || 'not recorded'}), but this session's current request`,
227
- 'is planning (/ukit:handoff-create). Stop gate and resume will not force the run here —',
228
- 'finish the planning first. To resume implementation explicitly, run /ukit:handoff-fullstack;',
229
- 'to discard the run, /ukit:handoff-clear.',
253
+ + `(Phase: ${phase}; Next: ${next || 'not recorded'}),`,
254
+ ...why,
230
255
  ].join('\n') + '\n');
231
256
  process.exit(0);
232
257
  }
@@ -102,7 +102,15 @@ if [ -z "$FILE_PATH" ]; then
102
102
  exit 0
103
103
  fi
104
104
 
105
- BASENAME=$(basename "$FILE_PATH")
105
+ # TASK-C97-008 (FR-M3-002): match backslash / Windows-shaped spellings the same
106
+ # as forward-slash ones. Normalize separators for LEXICAL basename/component
107
+ # matching ONLY — no filesystem resolution, no path writes, and no native
108
+ # Windows claim. `${var//pat/rep}` is a bash builtin, so this holds with or
109
+ # without jq. The original path stays in the stderr diagnostic; stdout keeps the
110
+ # generic reason and never exposes it.
111
+ MATCH_PATH="${FILE_PATH//\\//}"
112
+
113
+ BASENAME=$(basename "$MATCH_PATH")
106
114
 
107
115
  # Allow .env.example explicitly
108
116
  if [[ "$BASENAME" == ".env.example" ]]; then
@@ -112,7 +120,7 @@ fi
112
120
  # Match exact sensitive filenames and directory components, never arbitrary substrings:
113
121
  # `.env.d.ts` and `app.envrc` are source files, not secrets. The old `*".env"*`
114
122
  # check blocked both, which could appear as a mysterious stopped edit.
115
- PATH_SLASHED="/${FILE_PATH#/}"
123
+ PATH_SLASHED="/${MATCH_PATH#/}"
116
124
  PROTECTED_MATCH=""
117
125
  case "$BASENAME" in
118
126
  .env|.env.local|.env.production|package-lock.json|yarn.lock)
@@ -326,6 +326,13 @@ async function readTextSafe(filePath) {
326
326
  const pendingMarkers = Array.isArray(extractorJson?.pendingMarkers)
327
327
  ? extractorJson.pendingMarkers
328
328
  : [];
329
+ // Additive (SPEC FR-M5-001 §7/§8): a currently-named input whose marker already
330
+ // existed is NOT newly armed, so it must not drive the NEW hint. It is still a
331
+ // KNOWN local ref, so it must not fall through to the unresolved-path advisory
332
+ // either. Absent (older extractor) degrades to [], i.e. today's behavior.
333
+ const alreadyPending = Array.isArray(extractorJson?.alreadyPending)
334
+ ? extractorJson.alreadyPending
335
+ : [];
329
336
  const analyzed = Array.isArray(extractorJson?.alreadyAnalyzed) ? extractorJson.alreadyAnalyzed : [];
330
337
  const sessionId = typeof extractorJson?.sessionId === 'string' && extractorJson.sessionId
331
338
  ? extractorJson.sessionId
@@ -334,9 +341,12 @@ async function readTextSafe(filePath) {
334
341
  const armedRefs = new Set(
335
342
  pendingMarkers.filter((m) => typeof m?.ref === 'string').map((m) => m.ref)
336
343
  );
344
+ const pendingRefs = new Set(
345
+ alreadyPending.filter((m) => typeof m?.ref === 'string').map((m) => m.ref)
346
+ );
337
347
  const analyzedRefs = new Set(analyzed.filter((a) => typeof a?.ref === 'string').map((a) => a.ref));
338
348
  const unresolvedLocal = localMatches.filter(
339
- (m) => !armedRefs.has(m.trim()) && !analyzedRefs.has(m.trim())
349
+ (m) => !armedRefs.has(m.trim()) && !pendingRefs.has(m.trim()) && !analyzedRefs.has(m.trim())
340
350
  );
341
351
  const cases = [];
342
352
  if (pendingMarkers.some((m) => !m?.source)) cases.push('pasted image');