@event4u/agent-config 14.21.0 → 14.23.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/.augment-plugin/marketplace.json +3 -3
- package/.augment-plugin/plugin.json +1 -1
- package/.claude-plugin/marketplace.json +1 -1
- package/CHANGELOG.md +164 -187
- package/CREDITS.md +37 -0
- package/README.md +1 -1
- package/dist/agent-src/commands/analyze/inbox.md +380 -5
- package/dist/agent-src/commands/analyze/repo.md +4 -2
- package/dist/agent-src/commands/pr/merge.md +47 -38
- package/dist/agent-src/commands/roadmap/next.md +8 -0
- package/dist/agent-src/contexts/communication/rules-auto/token-efficiency-mechanics.md +69 -0
- package/dist/agent-src/contexts/execution/auto-dispatch-classification.md +5 -5
- package/dist/agent-src/contexts/execution/autonomy-mechanics.md +12 -0
- package/dist/agent-src/rules/external-code-graph-interop.md +19 -14
- package/dist/agent-src/rules/notes-first-reasoning.md +36 -25
- package/dist/agent-src/rules/token-efficiency.md +26 -3
- package/dist/agent-src/scripts/_cli_entry.ts +51 -0
- package/dist/agent-src/scripts/archive_completed_roadmaps.ts +120 -27
- package/dist/agent-src/scripts/roadmap_gates.ts +4 -20
- package/dist/agent-src/scripts/roadmap_set_step.ts +5 -2
- package/dist/agent-src/scripts/stubs_due.ts +4 -18
- package/dist/agent-src/scripts/update_roadmap_progress.ts +7 -24
- package/dist/agent-src/skills/code-intelligence/SKILL.md +82 -1
- package/dist/agent-src/skills/git-workflow/references/push-closes-its-loop.md +9 -0
- package/dist/agent-src/skills/roadmap-writing/SKILL.md +17 -0
- package/dist/agent-src/skills/tailwind-engineer/SKILL.md +52 -2
- package/dist/agent-src/templates/agent-settings.md +0 -1
- package/dist/agent-src/templates/agents/agent-project-settings.example.yml +1 -1
- package/dist/cli/registry.js +1 -1
- package/dist/cli-delegate/_cli_entry.js +8 -0
- package/dist/cli-delegate/_lib/pin_resolver.js +170 -0
- package/dist/cli-delegate/archival_sweep.js +8 -0
- package/dist/cli-delegate/archive_completed_roadmaps.js +542 -0
- package/dist/cli-delegate/check_update_banner.js +923 -0
- package/dist/cli-delegate/{chunk-ZVBOHSVF.js → chunk-2KKXJW25.js} +23 -9
- package/dist/cli-delegate/chunk-5EK5WQN6.js +28 -0
- package/dist/cli-delegate/chunk-7XGD2OEU.js +96 -0
- package/dist/cli-delegate/chunk-DBH4AHDK.js +155 -0
- package/dist/cli-delegate/{chunk-4FS4WRXP.js → chunk-IAI3XL43.js} +15 -3
- package/dist/cli-delegate/chunk-JO25G5H7.js +20 -0
- package/dist/cli-delegate/{chunk-643Z7FIC.js → chunk-KCNTUSPI.js} +7 -1
- package/dist/cli-delegate/chunk-LTYVIY76.js +7961 -0
- package/dist/cli-delegate/chunk-QAJS5YWY.js +999 -0
- package/dist/cli-delegate/{chunk-YS6XTLEK.js → chunk-TYSY33MD.js} +56 -6
- package/dist/cli-delegate/chunk-ULET4BYS.js +328 -0
- package/dist/cli-delegate/chunk-YDQSHTD7.js +187 -0
- package/dist/cli-delegate/chunk-YWVXLR44.js +48 -0
- package/dist/cli-delegate/chunk-ZZQBUHFK.js +273 -0
- package/dist/cli-delegate/cmd_conformance.js +2 -2
- package/dist/cli-delegate/cmd_export.js +2 -2
- package/dist/cli-delegate/cmd_handoff.js +45 -13
- package/dist/cli-delegate/cmd_prune.js +2 -2
- package/dist/cli-delegate/cmd_session_recycle.js +4 -14
- package/dist/cli-delegate/cmd_settings_migrate.js +2 -2
- package/dist/cli-delegate/cmd_settings_set.js +1 -1
- package/dist/cli-delegate/cmd_sync.js +2 -2
- package/dist/cli-delegate/cmd_uninstall.js +2 -2
- package/dist/cli-delegate/cmd_validate.js +2 -2
- package/dist/cli-delegate/dashboard_mode.js +16 -0
- package/dist/cli-delegate/gate_budget.js +24 -0
- package/dist/cli-delegate/gate_execute.js +25 -0
- package/dist/cli-delegate/guarded_baseline.js +18 -0
- package/dist/cli-delegate/resume_probe.js +22 -0
- package/dist/cli-delegate/roadmap_gates.js +638 -0
- package/dist/cli-delegate/roadmap_set_step.js +173 -0
- package/dist/cli-delegate/stub_queue.js +47 -0
- package/dist/cli-delegate/stubs_due.js +38 -0
- package/dist/cli-delegate/ticket_bundles.js +59 -0
- package/dist/cli-delegate/update_roadmap_progress.js +60 -0
- package/dist/discovery/deprecation-report.md +1 -1
- package/dist/discovery/discovery-manifest.json +13 -13
- package/dist/discovery/discovery-manifest.json.sha256 +1 -1
- package/dist/discovery/discovery-manifest.summary.md +1 -1
- package/dist/discovery/dormancy-report.md +1 -1
- package/dist/discovery/orphan-report.md +1 -1
- package/dist/discovery/packs.json +2 -2
- package/dist/discovery/trust-report.md +1 -1
- package/dist/discovery/workspaces.json +2 -2
- package/dist/hooks/dispatch.js +1813 -946
- package/dist/install/claudeLayerCarriage.js +237 -0
- package/dist/install/claudePathsPlan.js +79 -0
- package/dist/install/hostLayerFingerprint.js +1 -1
- package/dist/install/install.mjs +21 -3
- package/dist/install/partitionEligibility.js +231 -117
- package/dist/install/ruleLayerPartition.js +10 -7
- package/dist/mcp/registry-manifest.json +2 -2
- package/dist/mcp/server.json +2 -2
- package/dist/mcp/server.mjs +10870 -7641
- package/dist/scripts/_lib/lean_projection_mode.js +108 -0
- package/dist/scripts/_lib/router_match.js +243 -0
- package/dist/scripts/_lib/rule_injection.js +216 -0
- package/dist/scripts/condense.js +52 -45
- package/dist/scripts/project_thin_rules.js +139 -19
- package/dist/server/schemas/settings.js +16 -3
- package/docs/MIGRATION.md +105 -1
- package/docs/contracts/settings-classes.md +40 -8
- package/docs/guidelines/agent-infra/minimal-safe-diff-mechanics.md +73 -0
- package/docs/guidelines/agent-infra/notes-horizon-mechanics.md +90 -0
- package/llms.txt +1 -1
- package/package.json +7 -4
- package/src/agent-src/scripts/_cli_entry.ts +51 -0
- package/src/agent-src/scripts/archive_completed_roadmaps.ts +120 -27
- package/src/agent-src/scripts/roadmap_gates.ts +4 -20
- package/src/agent-src/scripts/roadmap_set_step.ts +5 -2
- package/src/agent-src/scripts/stubs_due.ts +4 -18
- package/src/agent-src/scripts/update_roadmap_progress.ts +7 -24
- package/src/config/agent-settings.template.yml +47 -1
- package/src/config/continuity-surface.json +516 -0
- package/src/config/estate-count-budget.json +1 -1
- package/src/config/evaluator-budgets.json +4 -4
- package/src/config/gate-coverage.yml +29 -8
- package/src/config/gate-violation-baselines.json +8 -8
- package/src/config/gitignore-block.txt +19 -0
- package/src/config/hook-token-budget.json +7 -6
- package/src/config/host-injection-effect.json +73 -0
- package/src/config/packed-binary-manifest.json +33 -0
- package/src/config/preamble-payload-budget.json +112 -105
- package/src/config/publish-surface.json +4 -2
- package/src/config/routing-coverage-seed.json +9 -2
- package/src/install/claudeLayerCarriage.ts +273 -0
- package/src/install/claudePathsPlan.ts +76 -0
- package/src/install/hostLayerFingerprint.ts +1 -1
- package/src/install/partitionEligibility.ts +261 -127
- package/src/install/ruleLayerPartition.ts +19 -23
- package/src/scripts/_cli/cmd_session_recycle.ts +2 -25
- package/src/scripts/_cli/handoff_sessions.ts +14 -44
- package/src/scripts/_dispatch.bash +77 -27
- package/src/scripts/_lib/auto_dispatch.ts +2 -2
- package/src/scripts/_lib/catalogue_layer_parity.ts +146 -0
- package/src/scripts/_lib/continuity_slot.ts +295 -0
- package/src/scripts/_lib/continuity_surface.ts +296 -0
- package/src/scripts/_lib/continuity_writer.ts +253 -0
- package/src/scripts/_lib/corpus_manifest.ts +26 -9
- package/src/scripts/_lib/hook_settings.ts +86 -1
- package/src/scripts/_lib/injection_effect.ts +151 -0
- package/src/scripts/_lib/layer_overlap_notice.ts +50 -6
- package/src/scripts/_lib/lean_projection_mode.ts +127 -0
- package/src/scripts/_lib/packed_binary_predicate.ts +262 -0
- package/src/scripts/_lib/pin_resolver.ts +13 -0
- package/src/scripts/_lib/recycle_envelope_paths.ts +109 -21
- package/src/scripts/_lib/regression_neighbourhood.ts +159 -22
- package/src/scripts/_lib/retired_status.ts +74 -0
- package/src/scripts/_lib/session_eol.ts +44 -0
- package/src/scripts/_lib/session_index_trust.ts +346 -0
- package/src/scripts/_lib/skill_catalogue.ts +156 -21
- package/src/scripts/_lib/standing_bound_ratchet.ts +154 -0
- package/src/scripts/_lib/subagent_capsule.ts +117 -8
- package/src/scripts/_lib/vendored_grammar_upstream.ts +280 -0
- package/src/scripts/ai_council/api_transport.ts +5 -0
- package/src/scripts/ai_council/deliberation_metrics.ts +353 -0
- package/src/scripts/ai_council/prompts.ts +9 -0
- package/src/scripts/ai_council/synthesis_disagreement.ts +206 -0
- package/src/scripts/audit_mcp_tools.ts +69 -25
- package/src/scripts/build_mcp_catalog.ts +24 -1
- package/src/scripts/capture_skill_catalogue.ts +24 -11
- package/src/scripts/check_candidate_lines.ts +499 -0
- package/src/scripts/check_continuity_surface.ts +475 -0
- package/src/scripts/check_dependency_floors.ts +13 -6
- package/src/scripts/check_estate_count.ts +40 -79
- package/src/scripts/check_host_tree_parity.ts +291 -0
- package/src/scripts/check_pack_size.ts +262 -23
- package/src/scripts/check_preamble_payload_budget.ts +136 -7
- package/src/scripts/check_roadmap_trackable.ts +19 -16
- package/src/scripts/check_rule_layer_partition.ts +54 -34
- package/src/scripts/check_rule_projection_integrity.ts +102 -2
- package/src/scripts/check_single_delivery.ts +97 -31
- package/src/scripts/check_update_banner.ts +13 -0
- package/src/scripts/ci_settle.ts +205 -5
- package/src/scripts/code_graph/build.ts +217 -15
- package/src/scripts/code_graph/cli.ts +334 -15
- package/src/scripts/code_graph/detect.ts +38 -0
- package/src/scripts/code_graph/extract.ts +11 -0
- package/src/scripts/code_graph/grammar_probe.ts +43 -0
- package/src/scripts/code_graph/loader.ts +88 -14
- package/src/scripts/code_graph/query.ts +144 -11
- package/src/scripts/code_graph/resolution_tiers.ts +238 -0
- package/src/scripts/code_graph/sqlite_store.ts +262 -6
- package/src/scripts/code_graph/types.ts +117 -3
- package/src/scripts/code_graph/validate.ts +26 -1
- package/src/scripts/code_graph/verbs.ts +590 -0
- package/src/scripts/condense.ts +54 -42
- package/src/scripts/corpus_manifest.ts +5 -5
- package/src/scripts/council_cli.ts +11 -12
- package/src/scripts/count_intent_disagreement.ts +426 -0
- package/src/scripts/handoff_context_hook.ts +118 -1
- package/src/scripts/hook_effect_doctor.ts +82 -1
- package/src/scripts/hook_manifest.json +1 -1
- package/src/scripts/hook_manifest.yaml +87 -12
- package/src/scripts/hooks/block_speaking_inbox_dir.ts +182 -16
- package/src/scripts/hooks/chain_nudge_hook.ts +282 -0
- package/src/scripts/hooks/code_graph_context_hook.ts +201 -0
- package/src/scripts/hooks/concern_registry.ts +4 -2
- package/src/scripts/hooks/host_semantics.ts +1 -1
- package/src/scripts/hooks/orchestration_record_hook.ts +2 -2
- package/src/scripts/hooks/push_settle_hook.ts +3 -2
- package/src/scripts/hooks/rule_inject_hook.ts +108 -21
- package/src/scripts/hooks/session_eol_hook.ts +120 -2
- package/src/scripts/hooks/skill_route_hook.ts +11 -4
- package/src/scripts/hot_context_hook.ts +62 -7
- package/src/scripts/inbox_source_census.ts +322 -0
- package/src/scripts/install-hooks.sh +82 -0
- package/src/scripts/{lint_carrier_integrity.ts → lint_deferral_integrity.ts} +60 -214
- package/src/scripts/lint_plan_risk_register.ts +13 -17
- package/src/scripts/lint_roadmap_blockers.ts +164 -1
- package/src/scripts/mcp_server/consumer_tool_catalog.json +152 -2
- package/src/scripts/mcp_server/graph_tools.ts +294 -0
- package/src/scripts/mcp_server/path_util.ts +31 -0
- package/src/scripts/mcp_server/suggest_skill.ts +72 -0
- package/src/scripts/mcp_server/tool_catalog_source.ts +7 -1
- package/src/scripts/mcp_server/tools.ts +5 -69
- package/src/scripts/media/lib/adapter-contract.md +7 -2
- package/src/scripts/media/lib/fixtures/flux/asset-0001.png +0 -0
- package/src/scripts/media/lib/fixtures/gemini-image/asset-0001.png +0 -0
- package/src/scripts/media/lib/fixtures/ideogram/asset-0001.png +0 -0
- package/src/scripts/model_rule_injection.ts +61 -4
- package/src/scripts/project_thin_rules.ts +149 -16
- package/src/scripts/rdp_candidates_delta.ts +276 -0
- package/src/scripts/rdp_quality_eval.ts +217 -19
- package/src/scripts/release_mix_taxonomy.json +3 -2
- package/src/scripts/report_host_injection_effect.ts +189 -0
- package/src/scripts/report_layer_overlap.ts +41 -0
- package/src/scripts/report_skill_menu_census.ts +341 -0
- package/src/scripts/report_standing_payload_by_host.ts +650 -0
- package/src/scripts/schemas/agent-settings.schema.json +7 -1
- package/src/scripts/session_memory_index.ts +81 -8
- package/src/scripts/skill_tools/score_skill_relevance.ts +70 -6
- package/src/scripts/skill_tools/suggest_skill_for_task.ts +37 -3
- package/src/server/schemas/settings.ts +23 -4
- package/src/vendor/grammars/README.md +86 -0
- package/src/vendor/grammars/tree-sitter-javascript.wasm +0 -0
- package/src/vendor/grammars/tree-sitter-php.wasm +0 -0
- package/src/vendor/grammars/tree-sitter-typescript.wasm +0 -0
- package/src/scripts/_lib/carrier_status.ts +0 -118
- package/src/scripts/_lib/estate_carrier_cases.ts +0 -72
- package/src/scripts/hooks/code_graph_nudge_hook.ts +0 -191
|
@@ -22,7 +22,13 @@
|
|
|
22
22
|
*
|
|
23
23
|
* Refuses: a Write/Edit/NotebookEdit (or cross-platform equivalent) whose
|
|
24
24
|
* target path introduces a **new** first-level directory under `agents/tmp/`
|
|
25
|
-
* or `agents/tmp.old/` whose name is not an opaque round identifier
|
|
25
|
+
* or `agents/tmp.old/` whose name is not an opaque round identifier — and a
|
|
26
|
+
* shell command carrying its path. Two narrowings bring the code closer to
|
|
27
|
+
* that sentence without classifying commands: a read tool's `file_path` is
|
|
28
|
+
* filtered by `_READ_ONLY_TOOLS`, and a directory name that is a GLOB over an
|
|
29
|
+
* acceptable one is not a creatable literal
|
|
30
|
+
* ({@link isGlobOverAcceptableInboxDir}). Both were judged unconditionally
|
|
31
|
+
* before, which is what refused a read command in this guard's own workflow.
|
|
26
32
|
*
|
|
27
33
|
* Allowed, deliberately:
|
|
28
34
|
*
|
|
@@ -62,6 +68,7 @@ import * as path from 'node:path';
|
|
|
62
68
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
63
69
|
|
|
64
70
|
import { isNonHarvestTmpDir, isOpaqueRoundId } from '../_lib/source_shape.js';
|
|
71
|
+
import { invokedSegments } from './git_command_classifier.js';
|
|
65
72
|
import { readHookStdin } from './hook_stdin.js';
|
|
66
73
|
|
|
67
74
|
const _HERE = fileURLToPath(import.meta.url);
|
|
@@ -76,10 +83,146 @@ const _PATH_KEYS: readonly string[] = [
|
|
|
76
83
|
'file_path', 'path', 'target_file', 'filename', 'filePath', 'notebook_path',
|
|
77
84
|
];
|
|
78
85
|
|
|
86
|
+
/**
|
|
87
|
+
* Tools whose `file_path` names something to READ, never something to write.
|
|
88
|
+
*
|
|
89
|
+
* `_PATH_KEYS` covers `file_path` and `path`, which is exactly what a Read,
|
|
90
|
+
* Grep or Glob call carries — so a search under a speaking round that does not
|
|
91
|
+
* exist yet was refused by a guard whose own docstring scopes itself to
|
|
92
|
+
* `Write/Edit/NotebookEdit`. Filtering here rather than through the manifest's
|
|
93
|
+
* `tools:` key on purpose: that key is an exact match on the host's own tool
|
|
94
|
+
* name, so an allowlist written in Claude's vocabulary would silence this
|
|
95
|
+
* guard on every host that spells its write tools differently. A DENY-list of
|
|
96
|
+
* read tools fails the other way — an unrecognised tool is still judged.
|
|
97
|
+
*
|
|
98
|
+
* An envelope with no tool name is judged too, for the same reason
|
|
99
|
+
* `_concern_matches_tool` runs a concern when the field is absent: a key that
|
|
100
|
+
* cannot decide must not be what silences a blocking guard.
|
|
101
|
+
*/
|
|
102
|
+
const _READ_ONLY_TOOLS: ReadonlySet<string> = new Set([
|
|
103
|
+
'read', 'grep', 'glob', 'notebookread', 'ls', 'view', 'search',
|
|
104
|
+
'codebase-retrieval', 'codebase_retrieval', 'file_search', 'grep_search',
|
|
105
|
+
'read_file', 'list_dir', 'semantic_search',
|
|
106
|
+
]);
|
|
107
|
+
|
|
79
108
|
function _isObject(v: JsonValue | undefined): v is JsonObject {
|
|
80
109
|
return v !== null && v !== undefined && typeof v === 'object' && !Array.isArray(v);
|
|
81
110
|
}
|
|
82
111
|
|
|
112
|
+
/**
|
|
113
|
+
* A directory name that is a GLOB over an already-acceptable name.
|
|
114
|
+
*
|
|
115
|
+
* READING IS NOT CREATING, AND THE COMMAND SCAN DID NOT KNOW IT. Measured
|
|
116
|
+
* twice in one session while running the inbox flow over a real round:
|
|
117
|
+
* `ls -d agents/tmp/inbox-2026-09-*` — the command the naming rule tells an
|
|
118
|
+
* operator to run to find a free round identifier — was refused, because the
|
|
119
|
+
* scan in `main` offered every whitespace token to the same verdict that judges
|
|
120
|
+
* a Write target and `inbox-2026-09-*` is not an opaque identifier: the `*`
|
|
121
|
+
* fails the 1-3 char disambiguator. So the guard stood between the operator and
|
|
122
|
+
* the rule it exists to enforce.
|
|
123
|
+
*
|
|
124
|
+
* WHY THIS AXIS AND NOT THE VERB. The first two attempts classified the
|
|
125
|
+
* COMMAND — an allowlist of read-only verbs, then per-verb writing markers.
|
|
126
|
+
* Two rounds of neutral review took that apart from both ends: round 1 found
|
|
127
|
+
* `sed -i`, `find -exec` and `awk system()` allowed where the plain token scan
|
|
128
|
+
* had blocked them; round 2 found the siblings the resulting deny-list did not
|
|
129
|
+
* reach (`sed`'s `s///w`, `awk`'s output pipe, `sort -o`, `yq -i`), a false
|
|
130
|
+
* positive the awk marker reintroduced by running past the program into a shell
|
|
131
|
+
* redirect, mention-blocking on heredoc bodies, and a fail-OPEN when the
|
|
132
|
+
* segmenter returned nothing. Its handoff named the shape of the problem:
|
|
133
|
+
* *"3 and 5 pull in opposite directions, so patching them one probe at a time
|
|
134
|
+
* will keep oscillating."*
|
|
135
|
+
*
|
|
136
|
+
* It was the wrong axis, and the measured defect never needed it. What is
|
|
137
|
+
* actually decidable from the token alone is whether the name could be created
|
|
138
|
+
* AS WRITTEN, and a glob cannot: the shell expands it against what exists. The
|
|
139
|
+
* one thing that could — `mkdir 'inbox-2026-09-*'`, creating a literal
|
|
140
|
+
* directory with a `*` in it — produces a name this predicate accepts anyway,
|
|
141
|
+
* because its non-glob part is opaque and carries no source. So the carve-out
|
|
142
|
+
* is safe by construction rather than by enumeration, and every writing form
|
|
143
|
+
* above is judged again by the unchanged token scan.
|
|
144
|
+
*
|
|
145
|
+
* A pattern over a SPEAKING name (`my-source-*`) is not accepted: the glob
|
|
146
|
+
* characters are removed and the remainder must itself pass.
|
|
147
|
+
*/
|
|
148
|
+
function isGlobOverAcceptableInboxDir(name: string): boolean {
|
|
149
|
+
if (!/[*?[\]]/.test(name)) {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
const literal = name.replace(/[*?]|\[[^\]]*\]/g, '');
|
|
153
|
+
const trimmed = literal.replace(/-+$/, '');
|
|
154
|
+
return trimmed !== '' && isAcceptableInboxDir(trimmed);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* The paths a redirect inside one segment would create.
|
|
159
|
+
*
|
|
160
|
+
* `splitOutsideQuotes` treats `;`, `|`, `&` and newline as separators and `>`
|
|
161
|
+
* as ordinary text, so a redirect target stays inside its segment. Collected
|
|
162
|
+
* separately from the token scan because the quotes matter: the token split
|
|
163
|
+
* removes them, this does not, and both inbox regexes need `agents` at a `/`
|
|
164
|
+
* or at the start — so `> "agents/tmp/<name>/x"` read as not-an-inbox-path
|
|
165
|
+
* until the strip below. Also run over the RAW command, because the heredoc
|
|
166
|
+
* regex in `invokedSegments` swallows a redirect that follows the delimiter.
|
|
167
|
+
*/
|
|
168
|
+
function _redirectTargets(segment: string): string[] {
|
|
169
|
+
const out: string[] = [];
|
|
170
|
+
const re = /(?:^|[^0-9<>&])[0-9]*>>?\s*([^\s|&;<>]+)/g;
|
|
171
|
+
let m: RegExpExecArray | null = re.exec(segment);
|
|
172
|
+
while (m !== null) {
|
|
173
|
+
// The character class stops at whitespace and separators but NOT at a
|
|
174
|
+
// quote, while both inbox regexes require `agents` at a `/` or at the
|
|
175
|
+
// start of the string. So `> "agents/tmp/<name>/x"` came back as
|
|
176
|
+
// `"agents/tmp/…` and read as not-an-inbox-path — allowed, where the
|
|
177
|
+
// unquoted form blocked. A neutral review probed it; stripping the
|
|
178
|
+
// quotes is the whole fix.
|
|
179
|
+
const target = (m[1] ?? '').replace(/^['"`]+|['"`]+$/g, '');
|
|
180
|
+
if (target) {
|
|
181
|
+
out.push(target);
|
|
182
|
+
}
|
|
183
|
+
m = re.exec(segment);
|
|
184
|
+
}
|
|
185
|
+
return out;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* The tokens of a shell command whose CREATION this guard should judge.
|
|
190
|
+
*
|
|
191
|
+
* Every whitespace token, exactly as before this change — the classification
|
|
192
|
+
* that tried to be cleverer than this is gone, and the docstring on
|
|
193
|
+
* {@link isGlobOverAcceptableInboxDir} records why. The two things kept are
|
|
194
|
+
* the ones no review disputed: the RAW command is scanned as well, because
|
|
195
|
+
* `invokedSegments` strips heredoc bodies as data and a `python3 - <<PY` body
|
|
196
|
+
* calling `makedirs` is precisely this guard's input; and redirect targets are
|
|
197
|
+
* collected separately with their quotes stripped, because `>` is not a
|
|
198
|
+
* segment separator and `> "path"` otherwise read as not-a-path.
|
|
199
|
+
*
|
|
200
|
+
* Scanning the raw command in addition to the segments is deliberately
|
|
201
|
+
* redundant rather than conditional: a heredoc predicate is one more thing to
|
|
202
|
+
* get wrong, the extra tokens can only ever matter if one of them names a
|
|
203
|
+
* speaking inbox directory, and the mention-blocking a review found came from
|
|
204
|
+
* the read-only SKIP being dropped for heredocs — not from the extra scan.
|
|
205
|
+
*
|
|
206
|
+
* Exported so the harness can pin the polarity pair on the tokens themselves,
|
|
207
|
+
* without an envelope.
|
|
208
|
+
*/
|
|
209
|
+
export function creatableTokens(command: string): string[] {
|
|
210
|
+
const out: string[] = [];
|
|
211
|
+
const segments = invokedSegments(command);
|
|
212
|
+
for (const seg of segments) {
|
|
213
|
+
out.push(..._redirectTargets(seg));
|
|
214
|
+
}
|
|
215
|
+
out.push(..._redirectTargets(command));
|
|
216
|
+
for (const text of [...segments, command]) {
|
|
217
|
+
for (const tok of text.split(/[\s"'`(){};|&<>]+/)) {
|
|
218
|
+
if (tok) {
|
|
219
|
+
out.push(tok);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return out;
|
|
224
|
+
}
|
|
225
|
+
|
|
83
226
|
/** `agents/tmp/<name>/…` or `agents/tmp.old/<name>/…`, after normalisation. */
|
|
84
227
|
const INBOX_RE = /(?:^|\/)agents\/tmp(?:\.old)?\/([^/]+)\/./;
|
|
85
228
|
|
|
@@ -145,6 +288,9 @@ export function verdictFor(
|
|
|
145
288
|
if (isAcceptableInboxDir(dir)) {
|
|
146
289
|
return { block: false, dir, reason: 'opaque round identifier or named working set' };
|
|
147
290
|
}
|
|
291
|
+
if (isGlobOverAcceptableInboxDir(dir)) {
|
|
292
|
+
return { block: false, dir, reason: 'glob over an acceptable name — not a creatable literal' };
|
|
293
|
+
}
|
|
148
294
|
// Already created — a rename is the fix, and refusing every later write
|
|
149
295
|
// would wedge the round without removing the name.
|
|
150
296
|
//
|
|
@@ -153,17 +299,36 @@ export function verdictFor(
|
|
|
153
299
|
// `agents/tmp-notes/` and `agents/tmpfiles/`, and taking the FIRST
|
|
154
300
|
// occurrence meant a path carrying a decoy earlier segment probed the wrong
|
|
155
301
|
// directory — in either direction. Found by the R2 review of this branch.
|
|
302
|
+
// THE CAPTURE CARRIES THE PATH'S OWN PREFIX, and it did not. Anchoring the
|
|
303
|
+
// group at `agents/` discarded everything before it, so a nested inbox —
|
|
304
|
+
// `app/Modules/<m>/agents/tmp/<round>/…`, the shape a module-per-package
|
|
305
|
+
// tree produces — probed `<repoRoot>/agents/tmp/<round>`, a directory that
|
|
306
|
+
// does not exist. The already-exists carve-out could therefore never fire
|
|
307
|
+
// there, and every write into a nested speaking round was refused forever
|
|
308
|
+
// instead of once.
|
|
309
|
+
//
|
|
310
|
+
// The prefix group is `??` — optional AND preferring ABSENT — and that is
|
|
311
|
+
// the half a neutral review had to point out. A greedy `(?:.*\/)?`
|
|
312
|
+
// resolves to the LAST inbox segment in the path while `inboxDirName`
|
|
313
|
+
// reads the FIRST, so a path carrying two of them judged one directory and
|
|
314
|
+
// probed another, reporting "already exists" for a name that does not.
|
|
315
|
+
// Making only `.*` lazy is NOT enough: `(...)?` still prefers one
|
|
316
|
+
// repetition, so the engine grows the prefix rather than trying the
|
|
317
|
+
// no-prefix branch, and the long match wins anyway — the test for this
|
|
318
|
+
// caught exactly that. `??` tries no-prefix first, so both reads agree.
|
|
319
|
+
// The decoy case below still resolves: `agents/tmp-notes/` fails the `/`
|
|
320
|
+
// after `tmp`, so the no-prefix branch is rejected and the match advances.
|
|
156
321
|
const normalized = filePath.replace(/\\/g, '/').replace(/^(\.\/)+/, '');
|
|
157
322
|
const m =
|
|
158
|
-
|
|
159
|
-
|
|
323
|
+
/^((?:.*?\/)??agents\/tmp(?:\.old)?\/[^/]+)\//.exec(normalized) ??
|
|
324
|
+
/^((?:.*?\/)??agents\/tmp(?:\.old)?\/[^/.]+)\/?$/.exec(normalized);
|
|
160
325
|
if (m === null) {
|
|
161
326
|
// `inboxDirName` matched but this did not — treat as unattributable and
|
|
162
327
|
// BLOCK, since the name is speaking and we cannot prove it pre-exists.
|
|
163
328
|
return { block: true, dir, reason: 'new inbox directory with a speaking name (path not re-anchorable)' };
|
|
164
329
|
}
|
|
165
330
|
const upto = m[1] as string;
|
|
166
|
-
const probe = repoRoot === '' ? upto : path.join(repoRoot, upto);
|
|
331
|
+
const probe = repoRoot === '' || path.isAbsolute(upto) ? upto : path.join(repoRoot, upto);
|
|
167
332
|
if (exists(probe)) {
|
|
168
333
|
return { block: false, dir, reason: 'directory already exists — rename, do not re-refuse' };
|
|
169
334
|
}
|
|
@@ -216,11 +381,15 @@ export function main(): number {
|
|
|
216
381
|
return 0;
|
|
217
382
|
}
|
|
218
383
|
const repoRoot = typeof envelope['project_dir'] === 'string' ? envelope['project_dir'] : '';
|
|
384
|
+
const rawTool = payload['tool_name'] ?? envelope['tool_name'];
|
|
385
|
+
const toolName = typeof rawTool === 'string' ? rawTool.trim().toLowerCase() : '';
|
|
219
386
|
const candidates: string[] = [];
|
|
220
|
-
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
|
|
387
|
+
if (!_READ_ONLY_TOOLS.has(toolName)) {
|
|
388
|
+
for (const key of _PATH_KEYS) {
|
|
389
|
+
const v = ti[key];
|
|
390
|
+
if (typeof v === 'string' && v) {
|
|
391
|
+
candidates.push(v);
|
|
392
|
+
}
|
|
224
393
|
}
|
|
225
394
|
}
|
|
226
395
|
// A shell command creates the directory just as effectively as a Write,
|
|
@@ -228,16 +397,13 @@ export function main(): number {
|
|
|
228
397
|
// agents/tmp/<speaking-name>`, a `git mv` into one, or a redirect
|
|
229
398
|
// bypassed it entirely. Both siblings on this slot (`block_no_verify`,
|
|
230
399
|
// `block_kernel_rule_writes`) parse the command string; this one did
|
|
231
|
-
// not, and the R2 review of this branch caught it.
|
|
232
|
-
//
|
|
233
|
-
// decision logic is shared rather than duplicated
|
|
400
|
+
// not, and the R2 review of this branch caught it. The tokens that
|
|
401
|
+
// could CREATE something are offered to the same pure verdict, so the
|
|
402
|
+
// decision logic is shared rather than duplicated — see
|
|
403
|
+
// `creatableTokens` for why "every whitespace token" was too many.
|
|
234
404
|
const cmd = ti['command'] ?? (_isObject(envelope['payload']) ? (envelope['payload'] as JsonObject)['command'] : undefined);
|
|
235
405
|
if (typeof cmd === 'string' && cmd) {
|
|
236
|
-
|
|
237
|
-
if (tok) {
|
|
238
|
-
candidates.push(tok);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
406
|
+
candidates.push(...creatableTokens(cmd));
|
|
241
407
|
}
|
|
242
408
|
for (const v of candidates) {
|
|
243
409
|
const verdict = verdictFor(v, (p) => fs.existsSync(p), repoRoot);
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
#!/usr/bin/env tsx
|
|
2
|
+
/**
|
|
3
|
+
* PreToolUse chain nudge — deterministic, warn-only.
|
|
4
|
+
*
|
|
5
|
+
* WHY A CARRIER EXISTS AT ALL. `token-efficiency` § One command per Bash call
|
|
6
|
+
* is `type: auto`, so its triggers match the PROMPT, and no prompt announces
|
|
7
|
+
* that the next tool call will be a chained Bash command. The obligation
|
|
8
|
+
* applies at tool-call time and was reachable by nothing there. This concern
|
|
9
|
+
* is that reach, and it is the only thing in the tree that reads
|
|
10
|
+
* `tool_input.command` for this purpose.
|
|
11
|
+
*
|
|
12
|
+
* WHAT IT IS FOR, MEASURED. The host splits a compound command on `&&`, `||`,
|
|
13
|
+
* `;`, `|`, `|&`, `&` and newlines and requires each segment to match the
|
|
14
|
+
* allowlist independently, so one unmatched segment sends the whole call down
|
|
15
|
+
* the permission path even when every other segment was already allowed. Over
|
|
16
|
+
* 40,268 real Bash calls on the maintainer's machine, 17.9 % had a head token
|
|
17
|
+
* matching no pattern and 5,037 of those were a leading `VAR=…` assignment —
|
|
18
|
+
* a shape that cannot be written as an allowlist pattern at all. That class
|
|
19
|
+
* shrinks only by not writing it.
|
|
20
|
+
*
|
|
21
|
+
* WHAT IT DOES NOT FLAG, DELIBERATELY. A pipe of ordinary filters
|
|
22
|
+
* (`grep foo file | head`) is one command with a filter, not two work steps.
|
|
23
|
+
* A redirect has its target checked against the file rules on its own. A
|
|
24
|
+
* heredoc is a command with input. Flagging any of those would make the
|
|
25
|
+
* nudge noise, and a nudge that fires on correct usage is worse than none.
|
|
26
|
+
*
|
|
27
|
+
* NEVER BLOCKS. The dispatcher contract is 0 allow · 2 warn, and a warn on
|
|
28
|
+
* `pre_tool_use` with `severity: advisory` is an injection, not a deny — the
|
|
29
|
+
* same channel `code-graph-nudge` and `ui-route-nudge` already use. Every
|
|
30
|
+
* failure path returns allow: unreadable stdin, malformed JSON, unwritable
|
|
31
|
+
* latch. A token optimisation must never break a tool call.
|
|
32
|
+
*
|
|
33
|
+
* ONCE PER SESSION. A latch keyed by session id, in the state directory
|
|
34
|
+
* `code-graph-nudge.json` already occupies. The rule body reaches the model
|
|
35
|
+
* once, early, on the first chained call — repeating it every call would be
|
|
36
|
+
* the nagging this codebase refuses elsewhere.
|
|
37
|
+
*
|
|
38
|
+
* ON BY DEFAULT, WITH AN OPT-OUT. Unlike `code-graph-nudge`, which gates on a
|
|
39
|
+
* project capability that may not exist, the fact this nudge carries is a
|
|
40
|
+
* property of the HOST's permission matcher and is therefore true in every
|
|
41
|
+
* consumer. `hooks.chain_nudge.enabled: false` turns it off.
|
|
42
|
+
*/
|
|
43
|
+
import fs from 'node:fs';
|
|
44
|
+
import path from 'node:path';
|
|
45
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
46
|
+
|
|
47
|
+
import { readHookStdin } from './hook_stdin.js';
|
|
48
|
+
|
|
49
|
+
const SETTINGS_FILE = '.agent-settings.yml';
|
|
50
|
+
const EXIT_ALLOW = 0;
|
|
51
|
+
const EXIT_WARN = 2;
|
|
52
|
+
|
|
53
|
+
type JsonValue = string | number | boolean | null | JsonValue[] | { [k: string]: JsonValue };
|
|
54
|
+
type JsonObject = { [k: string]: JsonValue };
|
|
55
|
+
|
|
56
|
+
function isObject(v: unknown): v is JsonObject {
|
|
57
|
+
return typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* `hooks.chain_nudge.enabled: false` mini-parser. Absent means ON, which is
|
|
62
|
+
* the inverse of `code_graph_nudge.enabled` and stated in the header: the
|
|
63
|
+
* fact carried here holds on every host, so absent-means-off would ship a
|
|
64
|
+
* carrier nobody receives.
|
|
65
|
+
*/
|
|
66
|
+
export function enabled(root: string): boolean {
|
|
67
|
+
let text: string;
|
|
68
|
+
try {
|
|
69
|
+
const f = path.join(root, SETTINGS_FILE);
|
|
70
|
+
if (!fs.statSync(f).isFile()) return true;
|
|
71
|
+
text = fs.readFileSync(f, 'utf-8');
|
|
72
|
+
} catch {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
let inHooks = false;
|
|
76
|
+
let inCn = false;
|
|
77
|
+
for (const raw of text.split(/\r\n|\r|\n/)) {
|
|
78
|
+
const line = raw.replace(/\s+$/, '');
|
|
79
|
+
if (!line || line.replace(/^\s+/, '').startsWith('#')) continue;
|
|
80
|
+
if (!(line.startsWith(' ') || line.startsWith('\t'))) {
|
|
81
|
+
inHooks = /^hooks\s*:\s*$/.test(line);
|
|
82
|
+
inCn = false;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (inHooks) {
|
|
86
|
+
if (/^\s+chain_nudge\s*:\s*$/.test(line)) {
|
|
87
|
+
inCn = true;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (inCn && /^\s{0,3}\S/.test(line)) inCn = false;
|
|
91
|
+
}
|
|
92
|
+
if (inCn && /^\s+enabled\s*:\s*false\b/.test(line)) return false;
|
|
93
|
+
}
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Strip quoted spans and heredoc bodies so an operator inside a string
|
|
99
|
+
* literal cannot be read as chaining. `grep "a && b" f` is one command, and a
|
|
100
|
+
* scanner that misses that fires on correct usage — the failure this concern
|
|
101
|
+
* must not have.
|
|
102
|
+
*/
|
|
103
|
+
export function stripLiterals(cmd: string): string {
|
|
104
|
+
let out = '';
|
|
105
|
+
let i = 0;
|
|
106
|
+
let quote: string | null = null;
|
|
107
|
+
while (i < cmd.length) {
|
|
108
|
+
const c = cmd[i] as string;
|
|
109
|
+
if (quote) {
|
|
110
|
+
if (c === '\\' && quote === '"') {
|
|
111
|
+
i += 2;
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (c === quote) quote = null;
|
|
115
|
+
i += 1;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (c === '\\') {
|
|
119
|
+
i += 2;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (c === '"' || c === "'") {
|
|
123
|
+
quote = c;
|
|
124
|
+
i += 1;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
const heredoc = /^<<-?\s*'?"?([A-Za-z_][A-Za-z0-9_]*)'?"?/.exec(cmd.slice(i));
|
|
128
|
+
if (heredoc) {
|
|
129
|
+
const tag = heredoc[1] as string;
|
|
130
|
+
const end = cmd.indexOf(`\n${tag}`, i);
|
|
131
|
+
i = end === -1 ? cmd.length : end + tag.length + 1;
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
out += c;
|
|
135
|
+
i += 1;
|
|
136
|
+
}
|
|
137
|
+
return out;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** What the nudge saw, or null when the command is not chained work. */
|
|
141
|
+
export function detectChaining(command: string): string | null {
|
|
142
|
+
const bare = stripLiterals(command);
|
|
143
|
+
if (/^\s*[A-Za-z_][A-Za-z0-9_]*=/.test(bare) && /[;\n]/.test(bare)) {
|
|
144
|
+
return 'a leading `VAR=…` assignment carrying state into a later segment';
|
|
145
|
+
}
|
|
146
|
+
if (/&&|\|\|/.test(bare)) return 'work steps chained with `&&` / `||`';
|
|
147
|
+
if (/;\s*\S/.test(bare)) return 'work steps chained with `;`';
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Tools that carry a shell command. Mirrors `ship_diff_volume_hook` and
|
|
153
|
+
* `git_command_classifier` rather than hardcoding `Bash`: the tool name is
|
|
154
|
+
* host-specific, and the manifest's own `code-graph-nudge` block warns about
|
|
155
|
+
* exactly this spread. A named tool outside the set is declined; a payload
|
|
156
|
+
* naming no tool still reads, which is the bare-host shape.
|
|
157
|
+
*/
|
|
158
|
+
const COMMAND_TOOLS: ReadonlySet<string> = new Set([
|
|
159
|
+
'launch-process',
|
|
160
|
+
'launch_process',
|
|
161
|
+
'Bash',
|
|
162
|
+
'BashTool',
|
|
163
|
+
'run-process',
|
|
164
|
+
'runProcess',
|
|
165
|
+
'shell',
|
|
166
|
+
'execute_shell',
|
|
167
|
+
'RunShellCommand',
|
|
168
|
+
]);
|
|
169
|
+
|
|
170
|
+
/** The shell command this call carries, or '' when it carries none. */
|
|
171
|
+
export function bashCommand(envelope: JsonObject): string {
|
|
172
|
+
const payload = isObject(envelope['payload']) ? envelope['payload'] : envelope;
|
|
173
|
+
const nameVal = payload['tool_name'] ?? payload['toolName'] ?? payload['tool'];
|
|
174
|
+
if (typeof nameVal === 'string' && !COMMAND_TOOLS.has(nameVal)) return '';
|
|
175
|
+
const ti = payload['tool_input'] ?? payload['toolInput'];
|
|
176
|
+
if (isObject(ti)) {
|
|
177
|
+
const c = ti['command'];
|
|
178
|
+
if (typeof c === 'string') return c;
|
|
179
|
+
}
|
|
180
|
+
const c = payload['command'];
|
|
181
|
+
return typeof c === 'string' ? c : '';
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function sessionId(envelope: JsonObject): string {
|
|
185
|
+
const s = envelope['session_id'] ?? envelope['sessionId'];
|
|
186
|
+
return typeof s === 'string' && s ? s : 'default';
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function latchFile(root: string): string {
|
|
190
|
+
return path.join(root, 'agents', 'runtime', 'state', 'chain-nudge.json');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function alreadyNudged(root: string, session: string): boolean {
|
|
194
|
+
try {
|
|
195
|
+
const state = JSON.parse(fs.readFileSync(latchFile(root), 'utf-8')) as Record<string, boolean>;
|
|
196
|
+
return state[session] === true;
|
|
197
|
+
} catch {
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function latch(root: string, session: string): void {
|
|
203
|
+
try {
|
|
204
|
+
const p = latchFile(root);
|
|
205
|
+
let state: Record<string, boolean> = {};
|
|
206
|
+
try {
|
|
207
|
+
state = JSON.parse(fs.readFileSync(p, 'utf-8')) as Record<string, boolean>;
|
|
208
|
+
} catch {
|
|
209
|
+
/* fresh */
|
|
210
|
+
}
|
|
211
|
+
state[session] = true;
|
|
212
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
213
|
+
fs.writeFileSync(p, JSON.stringify(state));
|
|
214
|
+
} catch {
|
|
215
|
+
/* fail-open: a persistence failure must not break the tool call */
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** The nudge line — one line, names what was seen and what to do instead. */
|
|
220
|
+
export function nudgeReason(seen: string): string {
|
|
221
|
+
return (
|
|
222
|
+
`This Bash call chains work: ${seen}. The host matches each segment against ` +
|
|
223
|
+
'the allowlist independently, so one unmatched segment sends the whole call ' +
|
|
224
|
+
'down the permission path. Send N commands as N Bash calls in ONE block — ' +
|
|
225
|
+
'that is the batch. `D=/repo; cd $D && git status` is `git -C /repo status`. ' +
|
|
226
|
+
'Pipes of filters, redirects and heredocs are fine and are not what this flags. ' +
|
|
227
|
+
'See `token-efficiency` § One command per Bash call.'
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export function main(): number {
|
|
232
|
+
let envelope: JsonValue;
|
|
233
|
+
try {
|
|
234
|
+
const raw = readHookStdin();
|
|
235
|
+
envelope = raw.trim() ? (JSON.parse(raw) as JsonValue) : {};
|
|
236
|
+
} catch {
|
|
237
|
+
return EXIT_ALLOW;
|
|
238
|
+
}
|
|
239
|
+
if (!isObject(envelope)) return EXIT_ALLOW;
|
|
240
|
+
|
|
241
|
+
// ORDER IS LOAD-BEARING, and getting it wrong cost 26 ms at p95. Every
|
|
242
|
+
// predicate below that touches the filesystem runs AFTER the in-memory
|
|
243
|
+
// ones, so the overwhelming majority of tool calls — every non-shell
|
|
244
|
+
// call, and every unchained shell call — exit having read no file at all.
|
|
245
|
+
// The first draft called `enabled()` first, which put a settings read in
|
|
246
|
+
// front of every single pre_tool_use event on the host.
|
|
247
|
+
const command = bashCommand(envelope);
|
|
248
|
+
if (!command) return EXIT_ALLOW;
|
|
249
|
+
|
|
250
|
+
const seen = detectChaining(command);
|
|
251
|
+
if (!seen) return EXIT_ALLOW;
|
|
252
|
+
|
|
253
|
+
const cwd = envelope['cwd'];
|
|
254
|
+
const pr = envelope['workspace_root'] ?? envelope['project_root'];
|
|
255
|
+
const root = typeof cwd === 'string' && cwd ? cwd : typeof pr === 'string' && pr ? pr : '.';
|
|
256
|
+
if (!enabled(root)) return EXIT_ALLOW;
|
|
257
|
+
|
|
258
|
+
const session = sessionId(envelope);
|
|
259
|
+
if (alreadyNudged(root, session)) return EXIT_ALLOW;
|
|
260
|
+
|
|
261
|
+
latch(root, session);
|
|
262
|
+
process.stdout.write(`${JSON.stringify({ decision: 'warn', reason: nudgeReason(seen) })}\n`);
|
|
263
|
+
return EXIT_WARN;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Bundle-safety: never auto-run when inlined into an esbuild bundle, where
|
|
267
|
+
// every module shares the bundle's `import.meta.url` (see cmd_migrate.ts).
|
|
268
|
+
declare const __AGENT_CONFIG_BUNDLE__: boolean | undefined;
|
|
269
|
+
function isCliEntry(): boolean {
|
|
270
|
+
if (typeof __AGENT_CONFIG_BUNDLE__ !== 'undefined' && __AGENT_CONFIG_BUNDLE__) {
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
273
|
+
if (process.argv[1] === undefined) return false;
|
|
274
|
+
const argvUrl = pathToFileURL(path.resolve(process.argv[1])).href;
|
|
275
|
+
if (import.meta.url === argvUrl) return true;
|
|
276
|
+
try {
|
|
277
|
+
return fs.realpathSync(fileURLToPath(import.meta.url)) === fs.realpathSync(path.resolve(process.argv[1]));
|
|
278
|
+
} catch {
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
if (isCliEntry()) process.exit(main());
|