@event4u/agent-config 14.7.0 → 14.9.0
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.
- package/.claude-plugin/marketplace.json +1 -1
- package/CHANGELOG.md +175 -390
- package/README.md +1 -1
- package/agents/templates/.ai-council.yml.example +34 -4
- package/dist/agent-src/commands/evals/git-pr-merge.json +13 -0
- package/dist/agent-src/commands/evals/roadmap.json +17 -1
- package/dist/agent-src/commands/pr/create.md +14 -2
- package/dist/agent-src/commands/pr/merge.md +383 -0
- package/dist/agent-src/commands/review/changes.md +95 -14
- package/dist/agent-src/commands/roadmap/process-full.md +157 -3
- package/dist/agent-src/commands/roadmap.md +1 -1
- package/dist/agent-src/contexts/execution/auto-dispatch-classification.md +46 -36
- package/dist/agent-src/contexts/execution/autonomy-mechanics.md +37 -2
- package/dist/agent-src/contexts/execution/host-capability-manifest.md +77 -0
- package/dist/agent-src/contexts/execution/roadmap-execution-contract.md +100 -2
- package/dist/agent-src/contexts/execution/roadmap-process-loop.md +154 -2
- package/dist/agent-src/contexts/execution/subagent-response-contract.md +80 -0
- package/dist/agent-src/rules/artifact-drafting-protocol.md +5 -1
- package/dist/agent-src/rules/decision-revisit-gate.md +65 -33
- package/dist/agent-src/rules/recurring-criticism.md +1 -1
- package/dist/agent-src/rules/roadmap-progress-sync.md +19 -0
- package/dist/agent-src/rules/source-confidentiality.md +1 -1
- package/dist/agent-src/rules/untrusted-input-defense.md +9 -3
- package/dist/agent-src/scripts/archive_completed_roadmaps.ts +7 -4
- package/dist/agent-src/scripts/dashboard_mode.ts +212 -0
- package/dist/agent-src/scripts/update_roadmap_progress.ts +47 -48
- package/dist/agent-src/skills/adr-create/SKILL.md +124 -5
- package/dist/agent-src/skills/code-review/evals/evals.json +87 -46
- package/dist/agent-src/skills/decision-record/SKILL.md +61 -3
- package/dist/agent-src/skills/decision-review/SKILL.md +65 -0
- package/dist/agent-src/skills/humanizer/SKILL.md +39 -0
- package/dist/agent-src/skills/humanizer/evals/strip_fixtures.json +57 -0
- package/dist/agent-src/skills/humanizer/references/fixtures.md +54 -0
- package/dist/agent-src/skills/judge-spec-compliance/SKILL.md +154 -0
- package/dist/agent-src/skills/judge-synthesis/SKILL.md +45 -0
- package/dist/agent-src/skills/merge-conflicts/SKILL.md +26 -0
- package/dist/agent-src/skills/roadmap-writing/SKILL.md +18 -18
- package/dist/agent-src/skills/security/SKILL.md +8 -0
- package/dist/agent-src/skills/security-audit/SKILL.md +12 -1
- package/dist/agent-src/templates/agents/agent-project-settings.example.yml +1 -1
- package/dist/agent-src/templates/roadmaps.md +28 -2
- package/dist/cli/registry.js +3 -0
- package/dist/cli/registry.js.map +1 -1
- package/dist/cli-delegate/{chunk-FBKL6JWT.js → chunk-77GR3VD4.js} +68 -43
- package/dist/cli-delegate/{chunk-JZ4NR2TW.js → chunk-7PRE6ZV2.js} +1 -1
- package/dist/cli-delegate/{chunk-UEZ7D35A.js → chunk-CYH5SP6M.js} +4 -23
- package/dist/cli-delegate/{chunk-Q26HT4QT.js → chunk-E46KPN6K.js} +251 -150
- package/dist/cli-delegate/{chunk-74E3TKWV.js → chunk-H4VIVD4C.js} +5 -5
- package/dist/cli-delegate/chunk-I3EIN2YG.js +36 -0
- package/dist/cli-delegate/{chunk-4VR4ORQ6.js → chunk-LPPWO5CE.js} +4 -3
- package/dist/cli-delegate/{chunk-7F3VYSM2.js → chunk-PLSG6UL5.js} +14 -14
- package/dist/cli-delegate/cmd_adr_effective.js +1162 -0
- package/dist/cli-delegate/cmd_conformance.js +101 -25
- package/dist/cli-delegate/cmd_converge.js +3 -3
- package/dist/cli-delegate/cmd_doctor.js +7 -7
- package/dist/cli-delegate/cmd_export.js +6 -6
- package/dist/cli-delegate/cmd_handoff.js +7 -6
- package/dist/cli-delegate/cmd_memory_get.js +2 -1
- package/dist/cli-delegate/cmd_migrate.js +2 -2
- package/dist/cli-delegate/cmd_preflight.js +5 -5
- package/dist/cli-delegate/cmd_prune.js +6 -6
- package/dist/cli-delegate/cmd_route_audit.js +6 -5
- package/dist/cli-delegate/cmd_route_explain.js +3 -3
- package/dist/cli-delegate/cmd_session_recycle.js +3 -3
- package/dist/cli-delegate/cmd_settings_get.js +4 -4
- package/dist/cli-delegate/cmd_settings_migrate.js +6 -6
- package/dist/cli-delegate/cmd_settings_set.js +1 -1
- package/dist/cli-delegate/cmd_sync.js +6 -6
- package/dist/cli-delegate/cmd_uninstall.js +6 -6
- package/dist/cli-delegate/cmd_update.js +3 -3
- package/dist/cli-delegate/cmd_upgrade.js +3 -3
- package/dist/cli-delegate/cmd_validate.js +6 -6
- package/dist/cli-delegate/cmd_versions.js +3 -3
- package/dist/discovery/deprecation-report.md +1 -1
- package/dist/discovery/discovery-manifest.json +83 -30
- package/dist/discovery/discovery-manifest.json.sha256 +1 -1
- package/dist/discovery/discovery-manifest.summary.md +4 -4
- package/dist/discovery/dormancy-report.md +1 -1
- package/dist/discovery/orphan-report.md +1 -1
- package/dist/discovery/packs.json +11 -9
- package/dist/discovery/trust-report.md +2 -2
- package/dist/discovery/workspaces.json +9 -7
- package/dist/hooks/dispatch.js +1295 -812
- package/dist/install/globalRuleLayers.js +169 -0
- package/dist/install/globalRuleLayers.js.map +1 -0
- package/dist/install/partitionEligibility.js +156 -0
- package/dist/install/partitionEligibility.js.map +1 -1
- package/dist/install/ruleLayerPartition.js +157 -0
- package/dist/install/ruleLayerPartition.js.map +1 -0
- package/dist/mcp/registry-manifest.json +3 -3
- package/dist/mcp/server.json +2 -2
- package/dist/mcp/server.mjs +1358 -805
- package/dist/scripts/_lib/claude_plugin.js +162 -0
- package/dist/scripts/_lib/claude_plugin.js.map +1 -0
- package/dist/scripts/_lib/environment_detector.js +397 -0
- package/dist/scripts/_lib/environment_detector.js.map +1 -0
- package/dist/scripts/_lib/prune_empty_dirs.js +85 -0
- package/dist/scripts/_lib/prune_empty_dirs.js.map +1 -0
- package/dist/scripts/_lib/spawn_env.js +129 -0
- package/dist/scripts/_lib/spawn_env.js.map +1 -0
- package/dist/scripts/ai_council/modes.js +199 -0
- package/dist/scripts/ai_council/modes.js.map +1 -0
- package/dist/scripts/ai_council/transport_resolver.js +418 -0
- package/dist/scripts/ai_council/transport_resolver.js.map +1 -0
- package/dist/scripts/condense.js +52 -89
- package/dist/scripts/condense.js.map +1 -1
- package/dist/server/routes/wizard.js +3 -2
- package/dist/server/routes/wizard.js.map +1 -1
- package/dist/ui/assets/index-Cxgy63kz.js +26 -0
- package/dist/ui/assets/index-Cxgy63kz.js.map +1 -0
- package/dist/ui/index.html +1 -1
- package/docs/guidelines/agent-infra/artifact-drafting-protocol-mechanics.md +45 -1
- package/docs/guidelines/agent-infra/false-green.md +47 -1
- package/docs/guidelines/agent-infra/traceability-field-mechanics.md +50 -0
- package/docs/guidelines/agent-infra/untrusted-input-spotlighting.md +17 -0
- package/package.json +7 -3
- package/src/agent-src/scripts/archive_completed_roadmaps.ts +7 -4
- package/src/agent-src/scripts/dashboard_mode.ts +212 -0
- package/src/agent-src/scripts/update_roadmap_progress.ts +47 -48
- package/src/config/ci-local-parity.yml +21 -0
- package/src/config/estate-count-budget.json +13 -471
- package/src/config/evaluator-budgets.json +4 -4
- package/src/config/gate-coverage.yml +458 -12
- package/src/config/gate-violation-baselines.json +18 -8
- package/src/config/gitignore-block.txt +15 -2
- package/src/config/hook-latency-budget.json +5 -0
- package/src/config/publish-surface.json +60 -0
- package/src/config/requirements-trace-budget.json +32 -0
- package/src/config/rule-stub-ceilings.json +25 -4
- package/src/install/globalRuleLayers.ts +197 -0
- package/src/install/partitionEligibility.ts +177 -0
- package/src/install/ruleLayerPartition.ts +212 -0
- package/src/scripts/_cli/cmd_adr_effective.ts +484 -0
- package/src/scripts/_dispatch.bash +18 -0
- package/src/scripts/_lib/adr_frontmatter.test.ts +365 -0
- package/src/scripts/_lib/adr_frontmatter.ts +459 -0
- package/src/scripts/_lib/base_tree.ts +175 -0
- package/src/scripts/_lib/billing_grant.ts +165 -0
- package/src/scripts/_lib/billing_grant_cli.ts +123 -0
- package/src/scripts/_lib/council_fallback_posture.ts +53 -6
- package/src/scripts/_lib/council_fallback_wiring.ts +61 -1
- package/src/scripts/_lib/envelope_grounding.ts +11 -1
- package/src/scripts/_lib/host_capability.ts +59 -5
- package/src/scripts/_lib/layer_overlap_notice.ts +11 -2
- package/src/scripts/_lib/prune_empty_dirs.ts +80 -0
- package/src/scripts/_lib/quota_parked.ts +133 -0
- package/src/scripts/_lib/retrieval_sanitize.ts +62 -0
- package/src/scripts/_lib/review_telemetry.ts +196 -0
- package/src/scripts/_lib/subagent_response.ts +92 -0
- package/src/scripts/adr/evidence_census.ts +899 -0
- package/src/scripts/adr/regenerate_index.ts +25 -38
- package/src/scripts/adr_cite_check.ts +540 -39
- package/src/scripts/ai_council/clients.ts +12 -1
- package/src/scripts/ai_council/config.ts +72 -115
- package/src/scripts/ai_council/fallback_config.ts +19 -7
- package/src/scripts/ai_council/mid_flight_fallback.ts +88 -7
- package/src/scripts/ai_council/orchestrator.ts +2 -2
- package/src/scripts/ai_council/py_format.ts +124 -0
- package/src/scripts/ai_council/transport_resolver.ts +65 -2
- package/src/scripts/audit_adr_coverage.ts +134 -21
- package/src/scripts/bench_hook_latency.ts +204 -0
- package/src/scripts/build_archive_index.ts +34 -0
- package/src/scripts/check_adr_frontmatter.ts +574 -39
- package/src/scripts/check_council_pin_staleness.ts +300 -0
- package/src/scripts/check_estate_count.ts +420 -293
- package/src/scripts/check_gate_coverage.ts +91 -0
- package/src/scripts/check_hook_bundle_content.ts +219 -0
- package/src/scripts/check_new_adr_evidence.ts +529 -0
- package/src/scripts/check_no_stub_inventory_table.ts +292 -0
- package/src/scripts/check_pack_size.ts +234 -1
- package/src/scripts/check_publish_surface.ts +297 -0
- package/src/scripts/check_references.ts +18 -0
- package/src/scripts/check_requirements_trace.ts +378 -0
- package/src/scripts/check_rule_layer_partition.ts +531 -0
- package/src/scripts/check_secret_leak.ts +166 -12
- package/src/scripts/check_single_delivery.ts +137 -4
- package/src/scripts/check_standing_rule_delivery.ts +8 -2
- package/src/scripts/code_graph/cli.ts +44 -5
- package/src/scripts/code_graph/extract.ts +87 -0
- package/src/scripts/condense.ts +61 -91
- package/src/scripts/council_cli.ts +12 -16
- package/src/scripts/detect_ai_tells.ts +87 -0
- package/src/scripts/dispatch_r2_reviewer.ts +42 -0
- package/src/scripts/external_sources_denylist.json +4 -1
- package/src/scripts/generate_capabilities_index.ts +41 -0
- package/src/scripts/git_authorization_hook.ts +54 -4
- package/src/scripts/hooks/block_unauthorized_git.ts +41 -3
- package/src/scripts/hooks/dispatch_hook.ts +154 -187
- package/src/scripts/hooks/dispatch_issues.ts +38 -19
- package/src/scripts/hooks/fallback_yaml.ts +66 -0
- package/src/scripts/hooks/host_semantics.ts +21 -0
- package/src/scripts/hooks/injection_budget.ts +13 -3
- package/src/scripts/hooks/py_json_dumps.ts +103 -0
- package/src/scripts/hooks/run_continuation_hook.ts +3 -1
- package/src/scripts/hooks/state_io.ts +88 -1
- package/src/scripts/hooks/stdin_failure_policy.ts +96 -0
- package/src/scripts/hooks/subagent_ledger_hook.ts +76 -11
- package/src/scripts/injection_scan_hook.ts +257 -15
- package/src/scripts/lint_adr_sweep_routing.ts +365 -0
- package/src/scripts/lint_hook_manifest.ts +49 -0
- package/src/scripts/lint_provenance_vocabulary.ts +472 -4
- package/src/scripts/lint_workflow_security.ts +53 -10
- package/src/scripts/lint_workflow_security_allowlist.json +2 -18
- package/src/scripts/report_envelope_rate.ts +166 -0
- package/src/scripts/review_axis_report.ts +218 -0
- package/src/scripts/routing_doctor.ts +5 -1
- package/src/scripts/run_supervise.ts +46 -1
- package/src/scripts/schemas/evals.schema.json +5 -0
- package/src/scripts/sync_pr_branch.ts +170 -20
- package/dist/cli/commands/commands.candidates.test.js +0 -257
- package/dist/cli/commands/commands.candidates.test.js.map +0 -1
- package/dist/cli/commands/profiles.test.js +0 -88
- package/dist/cli/commands/profiles.test.js.map +0 -1
- package/dist/cli/commands/recordTriggerEval.test.js +0 -113
- package/dist/cli/commands/recordTriggerEval.test.js.map +0 -1
- package/dist/cli/configRoot.test.js +0 -97
- package/dist/cli/configRoot.test.js.map +0 -1
- package/dist/cli/mcp/content.test.js +0 -54
- package/dist/cli/mcp/content.test.js.map +0 -1
- package/dist/cli/mcp/dispatch.test.js +0 -108
- package/dist/cli/mcp/dispatch.test.js.map +0 -1
- package/dist/server/writeRoot.test.js +0 -91
- package/dist/server/writeRoot.test.js.map +0 -1
- package/dist/shared/capabilities.test.js +0 -39
- package/dist/shared/capabilities.test.js.map +0 -1
- package/dist/ui/assets/index-C1pBRm1f.js +0 -26
- package/dist/ui/assets/index-C1pBRm1f.js.map +0 -1
- package/dist/cli-delegate/{chunk-PPQO4NGR.js → chunk-6RJA2F5A.js} +3 -3
- package/dist/cli-delegate/{chunk-6EOCNQAM.js → chunk-E4XIZDIB.js} +0 -0
- package/dist/cli-delegate/{chunk-GJ5BVHXM.js → chunk-PMEKGDED.js} +3 -3
|
@@ -166,6 +166,31 @@ export function partitionVerdict(inputs: PartitionInputs): PartitionVerdict {
|
|
|
166
166
|
* artefact is NOT package-only, so it is delivered globally and withheld from
|
|
167
167
|
* the project layer. Both defaults resolve toward "the artefact is generally
|
|
168
168
|
* useful"; only one of them is about withholding.
|
|
169
|
+
*
|
|
170
|
+
* ## The state space, MEASURED rather than enumerated defensively (2026-08-21)
|
|
171
|
+
*
|
|
172
|
+
* Three of this function's branches — unreadable file, absent `workspaces:`,
|
|
173
|
+
* empty list — all resolve to `false`, and the closure review asked whether one
|
|
174
|
+
* of them was resolving by accident. Counted over all 119 files in `src/rules/`:
|
|
175
|
+
*
|
|
176
|
+
* absent=0 · empty=0 · maintainer-only=16 · mixed=103 · scalar-or-other=0
|
|
177
|
+
*
|
|
178
|
+
* So exactly TWO states occur today, both deliberate, and the 16 is the figure
|
|
179
|
+
* ADR-236 partitions on.
|
|
180
|
+
*
|
|
181
|
+
* **The other three branches are CURRENTLY ABSENT from the generated tree, not
|
|
182
|
+
* unreachable** — an earlier revision of this note said "the state space is
|
|
183
|
+
* closed by that count", and a neutral review was right to refuse it. A file can
|
|
184
|
+
* become unreadable at runtime (permissions, a partial write, a truncated
|
|
185
|
+
* checkout) and a rule can acquire a malformed `workspaces:` on any commit. The
|
|
186
|
+
* count is a current inventory, never a proof of impossibility.
|
|
187
|
+
*
|
|
188
|
+
* What the count DOES buy is a bound on the defensive work worth doing now:
|
|
189
|
+
* fixtures for the absent and malformed cases would pin behaviour on inputs no
|
|
190
|
+
* committed rule produces, so they were not written. All three branches already
|
|
191
|
+
* resolve to `false` — deliver globally, withhold from the project layer — which
|
|
192
|
+
* is the over-delivery direction rather than the losing one, so the untested
|
|
193
|
+
* branches fail safe. Should that count move, this note is the thing that dates.
|
|
169
194
|
*/
|
|
170
195
|
export function isExclusivelyPackageOnly(source_path: string): boolean {
|
|
171
196
|
let meta: Record<string, unknown>;
|
|
@@ -323,3 +348,155 @@ export function stampHostLayerFingerprint(
|
|
|
323
348
|
return null;
|
|
324
349
|
}
|
|
325
350
|
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Per-tool-directory persona list under the partition — ADR-236's closure for the
|
|
354
|
+
* one family it never reached.
|
|
355
|
+
*
|
|
356
|
+
* The partition shipped for rules and skills and stopped there, so
|
|
357
|
+
* `<repo>/.claude/personas` kept being written while `~/.claude/personas` was
|
|
358
|
+
* installed from `_CLAUDE_SKILL_BUNDLE` (`install.ts:1916-1921`). Measured
|
|
359
|
+
* 2026-08-21 on a freshly regenerated tree with the partition ACTIVE: **29 shared
|
|
360
|
+
* names**, and neither `check_single_delivery` nor `_lib/layer_overlap_notice`
|
|
361
|
+
* looked, because `personas` was in neither's `TYPES`.
|
|
362
|
+
*
|
|
363
|
+
* ## Two properties the caller depends on
|
|
364
|
+
*
|
|
365
|
+
* **Scoped to `.claude/` only.** {@link partitionActive} verifies the CLAUDE host
|
|
366
|
+
* layer against `installed.lock`. It says nothing about `~/.cursor`, so
|
|
367
|
+
* withholding a cursor persona on the strength of a claude fingerprint would
|
|
368
|
+
* deliver it nowhere — the one failure the fail-safe design exists to prevent.
|
|
369
|
+
* Every other tool directory keeps the full projection.
|
|
370
|
+
*
|
|
371
|
+
* **Reconciliation is the empty list, not a second code path.** The caller's
|
|
372
|
+
* stale-symlink sweep removes any link whose name is absent from the list it was
|
|
373
|
+
* given for that directory, so returning `[]` empties a directory an earlier
|
|
374
|
+
* version populated. A gate that only declined to WRITE would leave the existing
|
|
375
|
+
* duplicate standing — a partition that stops new duplication and keeps the old
|
|
376
|
+
* is not a partition.
|
|
377
|
+
*
|
|
378
|
+
* Verified before shipping: every one of the 29 project personas is present in
|
|
379
|
+
* the global layer (32 there, a strict superset). The partition is a removal and
|
|
380
|
+
* has no repair path, so withholding is only safe once the surviving layer is
|
|
381
|
+
* known to carry what is withheld.
|
|
382
|
+
*/
|
|
383
|
+
export function personaPartition(
|
|
384
|
+
projectRoot: string,
|
|
385
|
+
all: readonly string[],
|
|
386
|
+
): {
|
|
387
|
+
readonly all: readonly string[];
|
|
388
|
+
listFor: (toolDir: string) => readonly string[];
|
|
389
|
+
readonly note: string;
|
|
390
|
+
/**
|
|
391
|
+
* Per-directory count, for the caller's success line.
|
|
392
|
+
*
|
|
393
|
+
* Added after a neutral review (2026-08-21) caught the message claiming
|
|
394
|
+
* `N personas each` across every tool directory while `.claude/` had
|
|
395
|
+
* received zero. The suffix said "withheld" and the count contradicted it in
|
|
396
|
+
* the same sentence — a reader trusting the number is misled by a line that
|
|
397
|
+
* also carries its own correction.
|
|
398
|
+
*/
|
|
399
|
+
countFor: (toolDir: string) => number;
|
|
400
|
+
} {
|
|
401
|
+
const active = partitionActive(projectRoot);
|
|
402
|
+
return {
|
|
403
|
+
all,
|
|
404
|
+
listFor: (toolDir) => (personaWithheldFor(toolDir, active) ? [] : all),
|
|
405
|
+
note: active ? ' — .claude/ withheld: ADR-236 partition, personas arrive from ~/.claude' : '',
|
|
406
|
+
countFor: (toolDir) => (personaWithheldFor(toolDir, active) ? 0 : all.length),
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* The pure half of {@link personaPartition}: withhold iff the partition is active
|
|
412
|
+
* AND this is a Claude tool directory.
|
|
413
|
+
*
|
|
414
|
+
* Split out so the decision is testable in BOTH directions. `personaPartition`
|
|
415
|
+
* reads `installed.lock` through a memoized `partitionActive`, so a test over it
|
|
416
|
+
* can only assert whatever this machine happens to be — which is a test that
|
|
417
|
+
* passes either way and therefore proves nothing. The two properties worth
|
|
418
|
+
* pinning are exactly the two this signature exposes: `.claude/` is withheld when
|
|
419
|
+
* active, and NOTHING else ever is.
|
|
420
|
+
*/
|
|
421
|
+
export function personaWithheldFor(toolDir: string, active: boolean): boolean {
|
|
422
|
+
return active && toolDir.startsWith('.claude/');
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Does the project layer withhold the colon-form `/cluster:sub` commands?
|
|
427
|
+
*
|
|
428
|
+
* ## The claim this replaces, and the measurement that revised it
|
|
429
|
+
*
|
|
430
|
+
* `generate_claude_project_commands` was written on the reasoning that "Claude
|
|
431
|
+
* Code dedupes project and user scope by name, so the two copies of
|
|
432
|
+
* `/cluster:sub` collapse" — a host-behaviour claim with no first-party
|
|
433
|
+
* observation behind it. Its sibling claim about skills WAS probed under
|
|
434
|
+
* ADR-236's roadmap (Phase 5.2, `claudeMdExcludes`) and came back negative, so
|
|
435
|
+
* an unprobed host assumption in the same area was not a safe default.
|
|
436
|
+
*
|
|
437
|
+
* **MEASURED 2026-08-21, Claude Code 2.1.238.** Fixture: `/analyze:inbox`
|
|
438
|
+
* present in BOTH `~/.claude/commands/analyze/` and a temp project's
|
|
439
|
+
* `.claude/commands/analyze/`. The session reports `COUNT=1`. A control second
|
|
440
|
+
* entry (`/analyze:inboxctl`, project-only) makes the same probe report
|
|
441
|
+
* `COUNT=2` — so the 1 is an observation, not a probe that can only say one.
|
|
442
|
+
*
|
|
443
|
+
* **The half nobody had checked: the surviving copy is the GLOBAL one.** Asked
|
|
444
|
+
* for the command's description, the session returned the global body, not the
|
|
445
|
+
* project fixture's. So the dedup claim holds and its unstated corollary
|
|
446
|
+
* inverts the value of the project-layer copy: where a verified global layer
|
|
447
|
+
* exists, those 40 symlinks are written, deduped away, and LOSE. They are dead
|
|
448
|
+
* weight there — not a second listing, and not a reachability guarantee either.
|
|
449
|
+
*
|
|
450
|
+
* ## Why `partitionActive` is the right predicate rather than a new one
|
|
451
|
+
*
|
|
452
|
+
* It is true exactly when a global layer is present and verified against
|
|
453
|
+
* `installed.lock`, which is exactly the case where the project copy loses; and
|
|
454
|
+
* false on a fresh checkout, an unverified install, or a version mismatch —
|
|
455
|
+
* every case where the project copy is the only reachable one. So the
|
|
456
|
+
* fail-safe direction the whole module is built around already matches the
|
|
457
|
+
* measurement, and withholding needs no separate switch.
|
|
458
|
+
*
|
|
459
|
+
* ## Honest limits
|
|
460
|
+
*
|
|
461
|
+
* Self-report, n=1 per condition, one host version, one machine. What is NOT
|
|
462
|
+
* claimed: that older or newer hosts dedupe the same way, or that precedence is
|
|
463
|
+
* stable across them.
|
|
464
|
+
*
|
|
465
|
+
* **And a claim that WAS made here has been withdrawn as false** (neutral review,
|
|
466
|
+
* 2026-08-21). It read: *"A host that stopped deduping would show up as a
|
|
467
|
+
* double-listing, and `check_single_delivery` reports the overlap either way."*
|
|
468
|
+
* It cannot. When this predicate returns true the project copy is never written,
|
|
469
|
+
* so there is no second copy for the host to double-list or for the gate to
|
|
470
|
+
* count — it would report zero overlap while the assumption underneath had
|
|
471
|
+
* failed. Worse, `partitionActive` verifies the INSTALL (version + content
|
|
472
|
+
* fingerprint), never the HOST version whose behaviour was measured, so a host
|
|
473
|
+
* upgrade changes the premise and moves nothing this code reads.
|
|
474
|
+
*
|
|
475
|
+
* What actually holds: reachability survives a dedup change either way, because
|
|
476
|
+
* the global copy is delivered regardless. What is lost is only the project
|
|
477
|
+
* copy's redundancy, and nothing detects that. A real detector would have to
|
|
478
|
+
* pin the host version this measurement was taken against and re-probe when it
|
|
479
|
+
* moves — not built here, and named as absent rather than implied away.
|
|
480
|
+
*/
|
|
481
|
+
export function commandsWithheld(projectRoot: string): boolean {
|
|
482
|
+
return partitionActive(projectRoot);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* ## The caller's early return, flagged by review and kept
|
|
487
|
+
*
|
|
488
|
+
* `generate_claude_project_commands` applies this predicate and then returns
|
|
489
|
+
* early when `src/domains/` is absent — BEFORE its stale-link sweep. So a tree
|
|
490
|
+
* with no `src/domains` keeps whatever `.claude/commands` it already had, even
|
|
491
|
+
* when the commands are now withheld.
|
|
492
|
+
*
|
|
493
|
+
* Invariant rather than oversight: this package always ships `src/domains/`, the
|
|
494
|
+
* generator only runs from a checkout that has it, and a consumer never reaches
|
|
495
|
+
* this path. Documented rather than reordered, because hoisting the sweep above
|
|
496
|
+
* the guard would make a non-package tree lose a directory this code did not
|
|
497
|
+
* write — a worse failure than the one being avoided, and on a tree we do not own.
|
|
498
|
+
*
|
|
499
|
+
* The transition that DOES occur is covered: `partition_delivery_topology.test.ts`
|
|
500
|
+
* runs inactive→active over a fixture that has `src/domains`, and asserts both
|
|
501
|
+
* the links and the empty cluster directories are gone after one run.
|
|
502
|
+
*/
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ADR-236 rule partition, decided per HOST directory on that host's own
|
|
3
|
+
* evidence.
|
|
4
|
+
*
|
|
5
|
+
* ## Why the decision moved from per-run to per-directory
|
|
6
|
+
*
|
|
7
|
+
* The filter used to sit in `condense.ts::_scoped_rule_basenames()`, which runs
|
|
8
|
+
* once per generation, so `partitionActive` — a claude-only fingerprint against
|
|
9
|
+
* `installed.lock` — decided for every host at once. That contradicted
|
|
10
|
+
* `partitionEligibility.ts`'s own fail-safe reasoning, which refuses to withhold a
|
|
11
|
+
* cursor artefact on claude's evidence because it "would deliver it nowhere", and
|
|
12
|
+
* it was measurably wrong in both directions on 2026-08-22 (partition ACTIVE,
|
|
13
|
+
* freshly generated worktree):
|
|
14
|
+
*
|
|
15
|
+
* ```
|
|
16
|
+
* .claude/rules 13 files, 13 package-only, 0 global-only
|
|
17
|
+
* .clinerules 14 files, 13 package-only, 0 global-only ← narrowed on
|
|
18
|
+
* borrowed evidence
|
|
19
|
+
* .cursor/rules 126 files, 26 package-only, 100 global-only ← never narrowed
|
|
20
|
+
* .windsurf/rules 113 files, 13 package-only, 100 global-only ← never narrowed
|
|
21
|
+
* .augment/rules 118 files, 15 package-only, 103 global-only ← never narrowed
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* So the narrowing is per directory and gated on real evidence:
|
|
25
|
+
* {@link hostLayerCarries} reads that host's global directory and answers whether
|
|
26
|
+
* every name about to be withheld is actually there. No layer, an unreadable layer,
|
|
27
|
+
* or one missing a single name → the full projection is returned. A withhold now
|
|
28
|
+
* costs a directory read; the alternative cost a rule.
|
|
29
|
+
*
|
|
30
|
+
* ## Why it lives here rather than in condense.ts
|
|
31
|
+
*
|
|
32
|
+
* Four call sites consume it — the symlink emit plan, the cursor `.mdc` emitter,
|
|
33
|
+
* the windsurf emitter, the augment projector — and four sites deciding this
|
|
34
|
+
* separately is exactly how three of them came to disagree. It is in `src/install/`
|
|
35
|
+
* beside {@link partitionActive} and {@link hostLayerCarries}, the two predicates
|
|
36
|
+
* it composes, rather than in the 2,700-line generator that calls it.
|
|
37
|
+
*
|
|
38
|
+
* ## The classification source is the PROJECTION, not the authored tree
|
|
39
|
+
*
|
|
40
|
+
* `rulesSource` is `dist/agent-src/rules` at every call site, deliberately. A rule
|
|
41
|
+
* absent from `dist/` is compile-disabled and never projected, so it can be neither
|
|
42
|
+
* withheld nor duplicated — classifying from `src/rules` would count
|
|
43
|
+
* `telegraph-speak.md` (compile-disabled: 119 rules / 16 package-only in `src/`,
|
|
44
|
+
* 118 / 15 in `dist/`) and disagree with the emitter by exactly one file.
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
import * as fs from 'node:fs';
|
|
48
|
+
import * as os from 'node:os';
|
|
49
|
+
import * as path from 'node:path';
|
|
50
|
+
|
|
51
|
+
import { isExclusivelyPackageOnly, partitionActive } from './partitionEligibility.js';
|
|
52
|
+
import { hostLayerCarries, toolIdForProjectRuleDir } from './globalRuleLayers.js';
|
|
53
|
+
|
|
54
|
+
export interface PartitionRulesOptions {
|
|
55
|
+
/** Project-relative host directory, e.g. `.cursor/rules`. */
|
|
56
|
+
readonly toolDir: string;
|
|
57
|
+
/** Candidate rule basenames, already scope- and manual-filtered. */
|
|
58
|
+
readonly rules: readonly string[];
|
|
59
|
+
/** Absolute project root — what `partitionActive` verifies against. */
|
|
60
|
+
readonly projectRoot: string;
|
|
61
|
+
/** Absolute directory the basenames resolve against for classification. */
|
|
62
|
+
readonly rulesSource: string;
|
|
63
|
+
readonly userHome?: string;
|
|
64
|
+
/** Where the kept-full notice goes. Silent when omitted. */
|
|
65
|
+
readonly announce?: (message: string) => void;
|
|
66
|
+
/**
|
|
67
|
+
* Override the partition-active decision instead of reading `installed.lock`.
|
|
68
|
+
*
|
|
69
|
+
* Split out for the reason `partitionEligibility.ts` states about its own
|
|
70
|
+
* `personaWithheldFor`: "so the decision is testable in BOTH directions". A
|
|
71
|
+
* test over the un-injected path can only assert whatever the machine happens
|
|
72
|
+
* to be — and this one bit differs between a maintainer checkout (installed,
|
|
73
|
+
* so active) and CI (nothing installed, so inactive), which made the first
|
|
74
|
+
* version of `rule_partition_per_host.test.ts` green locally and red on every
|
|
75
|
+
* CI shard. That is the environment-dependent gate this whole change exists to
|
|
76
|
+
* remove, reproduced in its own test suite.
|
|
77
|
+
*
|
|
78
|
+
* Production callers omit it.
|
|
79
|
+
*/
|
|
80
|
+
readonly active?: boolean;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Narrow one directory's rule list to the package-only set — but only when THIS
|
|
85
|
+
* host's global layer is verified to carry what would be withheld.
|
|
86
|
+
*
|
|
87
|
+
* Returns a copy of `rules` unchanged in every uncertain case. That direction is
|
|
88
|
+
* the whole design: an unnecessary duplicate costs context, a wrong withhold costs
|
|
89
|
+
* the rule.
|
|
90
|
+
*/
|
|
91
|
+
export function partitionRulesForDir(opts: PartitionRulesOptions): string[] {
|
|
92
|
+
const { toolDir, rules, projectRoot, rulesSource } = opts;
|
|
93
|
+
const active = opts.active ?? partitionActive(projectRoot);
|
|
94
|
+
if (!active) {
|
|
95
|
+
return [...rules];
|
|
96
|
+
}
|
|
97
|
+
const toolId = toolIdForProjectRuleDir(toolDir);
|
|
98
|
+
if (toolId === null) {
|
|
99
|
+
// An unmapped directory has no global layer this code can point at, so
|
|
100
|
+
// there is no evidence to withhold on.
|
|
101
|
+
return [...rules];
|
|
102
|
+
}
|
|
103
|
+
const packageOnly = rules.filter((r) => isExclusivelyPackageOnly(path.join(rulesSource, r)));
|
|
104
|
+
const keep = new Set(packageOnly);
|
|
105
|
+
const withheld = rules.filter((r) => !keep.has(r));
|
|
106
|
+
const home = opts.userHome ?? process.env['HOME'] ?? os.homedir();
|
|
107
|
+
const verdict = hostLayerCarries(toolId, withheld, home);
|
|
108
|
+
if (!verdict.carries) {
|
|
109
|
+
opts.announce?.(
|
|
110
|
+
` ⚠️ ${toolDir}: full projection kept — ${toolId}'s global layer ${verdict.reason}` +
|
|
111
|
+
(verdict.missing.length > 0
|
|
112
|
+
? ` (${String(verdict.missing.length)} rule(s) not there, e.g. ` +
|
|
113
|
+
`${verdict.missing.slice(0, 3).join(', ')})`
|
|
114
|
+
: ''),
|
|
115
|
+
);
|
|
116
|
+
return [...rules];
|
|
117
|
+
}
|
|
118
|
+
return packageOnly;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// ── The older, weaker duplicate-avoidance mechanism ──────────────────────────
|
|
122
|
+
//
|
|
123
|
+
// `projection.scope_dedup` (default OFF) predates the partition and solves the
|
|
124
|
+
// same problem with a narrower method: skip a project copy only when its
|
|
125
|
+
// user-scope twin is BYTE-IDENTICAL. It moved here from condense.ts alongside the
|
|
126
|
+
// partition because the two are one subject — a reader deciding how a duplicate is
|
|
127
|
+
// avoided should find both in one file rather than one here and one in a
|
|
128
|
+
// 2,700-line generator. Behaviour is unchanged; only `MODULE_STATE` reads became
|
|
129
|
+
// parameters.
|
|
130
|
+
|
|
131
|
+
/** `fs.statSync(p).isFile()`, false on any error — condense.ts's `_isFile`. */
|
|
132
|
+
function isFile(p: string): boolean {
|
|
133
|
+
try {
|
|
134
|
+
return fs.statSync(p).isFile();
|
|
135
|
+
} catch {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Per-tool user-scope rule directory, for the scope-dedup below. Only tools
|
|
142
|
+
* whose host reads a user-scope rules directory can have a redundant twin;
|
|
143
|
+
* everything else has nothing to de-duplicate against.
|
|
144
|
+
*/
|
|
145
|
+
const USER_SCOPE_RULE_DIRS: Readonly<Record<string, string>> = {
|
|
146
|
+
'.claude/rules': path.join('.claude', 'rules'),
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Rules whose user-scope twin is BYTE-IDENTICAL to the source, i.e. safe to
|
|
151
|
+
* skip at project scope: the host still loads the same text, once instead of
|
|
152
|
+
* twice, so nothing the model sees changes.
|
|
153
|
+
*
|
|
154
|
+
* Byte-identity is the whole safety argument and is not negotiable. Keying on
|
|
155
|
+
* the filename alone would silently let a stale globally-installed copy win
|
|
156
|
+
* whenever the two scopes hold different versions — which is the NORMAL state
|
|
157
|
+
* while developing the package (measured: 110/110 shared filenames differing in
|
|
158
|
+
* bytes). This is deliberately not the thin-projection mechanism: no rule
|
|
159
|
+
* becomes trigger-gated, so the quality floor that disabled thin projection
|
|
160
|
+
* does not apply here.
|
|
161
|
+
*/
|
|
162
|
+
export interface DedupOptions {
|
|
163
|
+
readonly toolDir: string;
|
|
164
|
+
readonly rules: readonly string[];
|
|
165
|
+
readonly userHome: string;
|
|
166
|
+
/** Absolute directory the basenames resolve against, for the byte compare. */
|
|
167
|
+
readonly rulesSource: string;
|
|
168
|
+
readonly announce?: (message: string) => void;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export function dedupableRules(opts: DedupOptions): Set<string> {
|
|
172
|
+
const { toolDir: tool_dir, rules, userHome, rulesSource } = opts;
|
|
173
|
+
const relative = USER_SCOPE_RULE_DIRS[tool_dir];
|
|
174
|
+
if (relative === undefined) {
|
|
175
|
+
return new Set();
|
|
176
|
+
}
|
|
177
|
+
// A hostile or simply absent $HOME must make the dedup inert, not
|
|
178
|
+
// adventurous. In a container `$HOME` is often unset (so `homedir()` can
|
|
179
|
+
// resolve to `/`) or world-writable, and this function decides which rules
|
|
180
|
+
// to STOP emitting — reading an unexpected tree there is how a projection
|
|
181
|
+
// silently loses a rule. Council review of PR #1055 raised exactly this.
|
|
182
|
+
let userDirStat: fs.Stats;
|
|
183
|
+
const userDir = path.join(userHome, relative);
|
|
184
|
+
try {
|
|
185
|
+
userDirStat = fs.statSync(userDir);
|
|
186
|
+
} catch {
|
|
187
|
+
return new Set();
|
|
188
|
+
}
|
|
189
|
+
if (!userDirStat.isDirectory()) {
|
|
190
|
+
return new Set();
|
|
191
|
+
}
|
|
192
|
+
// World-writable user scope: anyone on the box could plant a byte-identical
|
|
193
|
+
// twin and thereby delete a rule from the project projection. Refuse.
|
|
194
|
+
if ((userDirStat.mode & 0o002) !== 0) {
|
|
195
|
+
opts.announce?.(` ⚠️ ${tool_dir}: user-scope rules dir is world-writable — scope-dedup skipped`);
|
|
196
|
+
return new Set();
|
|
197
|
+
}
|
|
198
|
+
const skip = new Set<string>();
|
|
199
|
+
for (const rule of rules) {
|
|
200
|
+
const twin = path.join(userDir, rule);
|
|
201
|
+
const source = path.join(rulesSource, rule);
|
|
202
|
+
try {
|
|
203
|
+
if (!isFile(twin) || !isFile(source)) continue;
|
|
204
|
+
if (fs.readFileSync(twin).equals(fs.readFileSync(source))) {
|
|
205
|
+
skip.add(rule);
|
|
206
|
+
}
|
|
207
|
+
} catch {
|
|
208
|
+
// An unreadable twin is simply not de-duplicable — emit the project copy.
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return skip;
|
|
212
|
+
}
|