@event4u/agent-config 14.18.0 → 14.20.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.
Files changed (210) hide show
  1. package/.augment-plugin/marketplace.json +3 -3
  2. package/.augment-plugin/plugin.json +1 -1
  3. package/.claude-plugin/marketplace.json +1 -1
  4. package/CHANGELOG.md +120 -129
  5. package/README.md +71 -149
  6. package/dist/agent-src/README.md +1 -1
  7. package/dist/agent-src/commands/agent-handoff.md +44 -43
  8. package/dist/agent-src/commands/review/changes.md +19 -19
  9. package/dist/agent-src/commands/review.md +2 -2
  10. package/dist/agent-src/contexts/execution/host-capability-manifest.md +37 -4
  11. package/dist/agent-src/rules/autonomous-execution.md +1 -1
  12. package/dist/agent-src/rules/git-history-discipline.md +2 -2
  13. package/dist/agent-src/rules/guidelines.md +1 -1
  14. package/dist/agent-src/rules/session-canary.md +2 -2
  15. package/dist/agent-src/rules/token-efficiency.md +1 -1
  16. package/dist/agent-src/rules/untrusted-input-defense.md +0 -2
  17. package/dist/agent-src/skills/adversarial-review/SKILL.md +0 -8
  18. package/dist/agent-src/skills/canvas-design/SKILL.md +1 -1
  19. package/dist/agent-src/skills/design-intelligence/SKILL.md +1 -1
  20. package/dist/agent-src/skills/design-intelligence/data/app-interface.csv +1 -1
  21. package/dist/agent-src/skills/design-intelligence/data/motion.csv +17 -17
  22. package/dist/agent-src/skills/design-intelligence/data/ux-guidelines.csv +2 -2
  23. package/dist/agent-src/skills/design-intelligence/references/context-and-registers.md +17 -0
  24. package/dist/agent-src/skills/design-intelligence/references/design-rules-checklist.md +4 -4
  25. package/dist/agent-src/skills/design-review/SKILL.md +1 -1
  26. package/dist/agent-src/skills/design-variations/SKILL.md +1 -1
  27. package/dist/agent-src/skills/evaluate-llm-feature/SKILL.md +1 -1
  28. package/dist/agent-src/skills/existing-ui-audit/SKILL.md +1 -1
  29. package/dist/agent-src/skills/fe-design/SKILL.md +32 -5
  30. package/dist/agent-src/skills/fe-design/references/craft-floor.md +7 -0
  31. package/dist/agent-src/skills/fe-design/references/design-patterns.md +47 -2
  32. package/dist/agent-src/skills/laravel-scheduling/SKILL.md +3 -1
  33. package/dist/agent-src/skills/markitdown/SKILL.md +1 -1
  34. package/dist/agent-src/skills/project-analyzer/SKILL.md +0 -6
  35. package/dist/agent-src/skills/react-native-setup/SKILL.md +3 -3
  36. package/dist/agent-src/skills/react-shadcn-ui/SKILL.md +1 -1
  37. package/dist/agent-src/skills/sequential-thinking/SKILL.md +18 -8
  38. package/dist/agent-src/skills/skill-improvement-pipeline/SKILL.md +28 -6
  39. package/dist/agent-src/skills/tailwind-engineer/SKILL.md +1 -1
  40. package/dist/agent-src/skills/test-driven-development/SKILL.md +1 -3
  41. package/dist/agent-src/skills/ui-apply-generic/SKILL.md +1 -1
  42. package/dist/agent-src/skills/ui-component-architect/SKILL.md +1 -1
  43. package/dist/agent-src/skills/using-git-worktrees/SKILL.md +17 -2
  44. package/dist/agent-src/templates/agents/agent-project-settings.example.yml +1 -1
  45. package/dist/agent-src/templates/roadmaps.md +14 -1
  46. package/dist/agent-src/templates/scripts/telemetry/mcp_lite.ts +213 -0
  47. package/dist/agent-src/templates/scripts/telemetry/report_renderer.ts +16 -0
  48. package/dist/agent-src/templates/scripts/telemetry_report.ts +22 -2
  49. package/dist/cli/commands/recordTriggerEval.js +2 -2
  50. package/dist/cli/main.js +1 -1
  51. package/dist/cli/mcp/dispatch.js +10 -0
  52. package/dist/cli/mcp/stdio.js +33 -2
  53. package/dist/cli/mcp/telemetry.js +227 -0
  54. package/dist/cli-delegate/{chunk-AKJGUQNO.js → chunk-C6IPZRDA.js} +484 -353
  55. package/dist/cli-delegate/{chunk-CYH5SP6M.js → chunk-I6RHFQEG.js} +151 -16
  56. package/dist/cli-delegate/{chunk-7RXIKF62.js → chunk-NUMQHLS5.js} +304 -136
  57. package/dist/cli-delegate/{chunk-PMEKGDED.js → chunk-PI2GU3DP.js} +163 -1
  58. package/dist/cli-delegate/{chunk-7PRE6ZV2.js → chunk-YS6XTLEK.js} +199 -4
  59. package/dist/cli-delegate/chunk-ZVBOHSVF.js +1109 -0
  60. package/dist/cli-delegate/cmd_adr_effective.js +318 -81
  61. package/dist/cli-delegate/cmd_conformance.js +489 -121
  62. package/dist/cli-delegate/cmd_doctor.js +2 -2
  63. package/dist/cli-delegate/cmd_export.js +2 -2
  64. package/dist/cli-delegate/cmd_handoff.js +42 -12
  65. package/dist/cli-delegate/cmd_memory_get.js +1 -1
  66. package/dist/cli-delegate/cmd_prune.js +2 -2
  67. package/dist/cli-delegate/cmd_route_audit.js +2 -2
  68. package/dist/cli-delegate/cmd_session_recycle.js +59 -902
  69. package/dist/cli-delegate/cmd_settings_migrate.js +2 -2
  70. package/dist/cli-delegate/cmd_sync.js +2 -2
  71. package/dist/cli-delegate/cmd_uninstall.js +2 -2
  72. package/dist/cli-delegate/cmd_validate.js +2 -2
  73. package/dist/discovery/deprecation-report.md +1 -1
  74. package/dist/discovery/discovery-manifest.json +34 -33
  75. package/dist/discovery/discovery-manifest.json.sha256 +1 -1
  76. package/dist/discovery/discovery-manifest.summary.md +1 -1
  77. package/dist/discovery/dormancy-report.md +1 -1
  78. package/dist/discovery/orphan-report.md +1 -1
  79. package/dist/discovery/packs.json +2 -2
  80. package/dist/discovery/trust-report.md +1 -1
  81. package/dist/discovery/workspaces.json +2 -2
  82. package/dist/hooks/dispatch.js +4455 -3025
  83. package/dist/install/install.mjs +975 -689
  84. package/dist/mcp/registry-manifest.json +2 -2
  85. package/dist/mcp/server.json +2 -2
  86. package/dist/mcp/server.mjs +2087 -1134
  87. package/dist/scripts/_lib/model_tier.js +1 -1
  88. package/dist/scripts/mcp_server/telemetry.js +148 -0
  89. package/docs/guidelines/agent-infra/evaluator-independence-mechanics.md +1 -1
  90. package/docs/guidelines/agent-infra/naming.md +1 -1
  91. package/docs/guidelines/agent-infra/roadmap-progress-mechanics.md +1 -1
  92. package/docs/guidelines/agent-infra/security-lint-containment.md +46 -6
  93. package/docs/guidelines/agent-infra/self-improvement-pipeline.md +4 -4
  94. package/docs/guidelines/agent-infra/untrusted-input-spotlighting.md +1 -1
  95. package/docs/guidelines/design-antipatterns.md +87 -64
  96. package/docs/guidelines/redundancy-taxonomy.md +28 -0
  97. package/package.json +1 -1
  98. package/src/agent-src/README.md +1 -1
  99. package/src/agent-src/templates/scripts/telemetry/mcp_lite.ts +213 -0
  100. package/src/agent-src/templates/scripts/telemetry/report_renderer.ts +16 -0
  101. package/src/agent-src/templates/scripts/telemetry_report.ts +22 -2
  102. package/src/config/assurance-capability-registry.json +9 -0
  103. package/src/config/ci-local-parity.yml +6 -0
  104. package/src/config/gate-coverage.yml +225 -0
  105. package/src/config/gate-violation-baselines.json +18 -6
  106. package/src/config/release-gate-locality.yml +12 -0
  107. package/src/scripts/_cli/cmd_doctor.ts +2 -2
  108. package/src/scripts/_cli/cmd_handoff.ts +1 -1
  109. package/src/scripts/_cli/cmd_session_recycle.ts +51 -3
  110. package/src/scripts/_cli/cmd_update.ts +1 -1
  111. package/src/scripts/_cli/cmd_versions.ts +1 -1
  112. package/src/scripts/_lib/adr_frontmatter.ts +44 -0
  113. package/src/scripts/_lib/audit_field_provenance.ts +44 -3
  114. package/src/scripts/_lib/consequence_objects.ts +152 -0
  115. package/src/scripts/_lib/exec_evidence.ts +7 -0
  116. package/src/scripts/_lib/global_deploy_inventory.ts +2 -2
  117. package/src/scripts/_lib/host_capability.ts +38 -0
  118. package/src/scripts/_lib/host_permission_checks.ts +251 -0
  119. package/src/scripts/_lib/install_reach_checks.ts +33 -1
  120. package/src/scripts/_lib/mcp_bridge.ts +222 -10
  121. package/src/scripts/_lib/mcp_consent_residual.ts +173 -0
  122. package/src/scripts/_lib/model_tier.ts +1 -1
  123. package/src/scripts/_lib/obligation_frequency.ts +2 -2
  124. package/src/scripts/_lib/orchestration_record.ts +23 -1
  125. package/src/scripts/_lib/recycle_envelope_paths.ts +190 -0
  126. package/src/scripts/_lib/release_highlights.ts +93 -0
  127. package/src/scripts/_lib/release_material.ts +64 -1
  128. package/src/scripts/_lib/release_position.ts +96 -0
  129. package/src/scripts/_lib/review_skipped_record.ts +17 -1
  130. package/src/scripts/_lib/runtime_journal.ts +26 -3
  131. package/src/scripts/_lib/runtime_wiring_checks.ts +12 -1
  132. package/src/scripts/_lib/security_lint.ts +179 -7
  133. package/src/scripts/_lib/self_repair.ts +141 -6
  134. package/src/scripts/_lib/self_repair_store.ts +273 -7
  135. package/src/scripts/_lib/session_register.ts +11 -6
  136. package/src/scripts/_lib/sqlite_schema.ts +22 -0
  137. package/src/scripts/_lib/subagent_capsule.ts +155 -3
  138. package/src/scripts/_lib/surface.ts +86 -0
  139. package/src/scripts/_lib/ui_authority.ts +116 -0
  140. package/src/scripts/adr/regenerate_index.ts +54 -1
  141. package/src/scripts/adr_cite_check.ts +71 -15
  142. package/src/scripts/ai_council/clients.ts +1 -1
  143. package/src/scripts/autonomy_friction_corpus.ts +229 -0
  144. package/src/scripts/build_proof.ts +15 -2
  145. package/src/scripts/build_rule_trigger_matrix.ts +5 -0
  146. package/src/scripts/check_beta_review_markers.ts +141 -17
  147. package/src/scripts/check_enforcement_coverage.ts +1 -1
  148. package/src/scripts/check_enforcement_denominator.ts +121 -11
  149. package/src/scripts/check_finding_dispositions.ts +66 -9
  150. package/src/scripts/check_gate_coverage.ts +96 -0
  151. package/src/scripts/check_mcp_doc_drift.ts +217 -0
  152. package/src/scripts/check_pack_size.ts +321 -3
  153. package/src/scripts/check_release_highlights.ts +74 -1
  154. package/src/scripts/check_skill_activation_claim.ts +179 -0
  155. package/src/scripts/check_trigger_evals.ts +1 -1
  156. package/src/scripts/conformance_scan.ts +44 -3
  157. package/src/scripts/explain_run.ts +1 -1
  158. package/src/scripts/generate_capability_matrix.ts +1 -1
  159. package/src/scripts/git_authorization_hook.ts +75 -1
  160. package/src/scripts/handoff_context_hook.ts +54 -7
  161. package/src/scripts/hook_manifest.json +1 -1
  162. package/src/scripts/hook_manifest.yaml +14 -11
  163. package/src/scripts/hooks/augment-dispatcher.sh +1 -1
  164. package/src/scripts/hooks/category_a.ts +291 -0
  165. package/src/scripts/hooks/cline-dispatcher.sh +1 -1
  166. package/src/scripts/hooks/cursor-dispatcher.sh +11 -5
  167. package/src/scripts/hooks/dispatch_hook.ts +17 -22
  168. package/src/scripts/hooks/git_command_classifier.ts +156 -1
  169. package/src/scripts/hooks/host_lowering.ts +215 -0
  170. package/src/scripts/hooks/host_lowering.yaml +185 -0
  171. package/src/scripts/hooks/host_semantics.ts +105 -37
  172. package/src/scripts/hooks/journal_record_hook.ts +10 -0
  173. package/src/scripts/hooks/permission_gate.ts +117 -0
  174. package/src/scripts/hooks/session_eol_hook.ts +18 -7
  175. package/src/scripts/hooks_status.ts +12 -10
  176. package/src/scripts/install.ts +57 -86
  177. package/src/scripts/install_anthropic_key.sh +2 -2
  178. package/src/scripts/lint_agent_security.ts +316 -25
  179. package/src/scripts/lint_confusables.ts +42 -6
  180. package/src/scripts/lint_design_antipattern_parity.ts +80 -0
  181. package/src/scripts/lint_evidence_artifacts.ts +45 -1
  182. package/src/scripts/lint_handoffs.ts +0 -132
  183. package/src/scripts/lint_hidden_unicode.ts +49 -7
  184. package/src/scripts/lint_hook_manifest.ts +87 -3
  185. package/src/scripts/lint_instruction_smuggling.ts +42 -6
  186. package/src/scripts/lint_mcp_config_security.ts +42 -6
  187. package/src/scripts/lint_motion_authority_drift.ts +731 -0
  188. package/src/scripts/lint_readme_size.ts +158 -12
  189. package/src/scripts/lint_reasoning_fixtures.ts +216 -0
  190. package/src/scripts/lint_roadmap_later_disposition.ts +217 -27
  191. package/src/scripts/lint_skill_frontmatter_safety.ts +43 -7
  192. package/src/scripts/lint_skill_trigger_contradiction.ts +161 -0
  193. package/src/scripts/mcp_server/resources.ts +41 -0
  194. package/src/scripts/mcp_server/telemetry.ts +19 -4
  195. package/src/scripts/measure_sibling_naming.ts +150 -0
  196. package/src/scripts/orchestration_record.ts +12 -1
  197. package/src/scripts/redact_hook_capture.ts +1 -1
  198. package/src/scripts/release.ts +24 -24
  199. package/src/scripts/release_publication.ts +6 -2
  200. package/src/scripts/report_skill_activation.ts +319 -7
  201. package/src/scripts/schemas/review-findings.schema.json +5 -0
  202. package/src/scripts/schemas/skill.schema.json +2 -2
  203. package/src/scripts/self_repair_cli.ts +31 -1
  204. package/src/scripts/session_canary_hook.ts +1 -1
  205. package/src/scripts/session_register_hook.ts +4 -3
  206. package/src/scripts/skill_scout.ts +69 -0
  207. package/src/scripts/trigger_eval_grandfather.json +5 -1
  208. package/src/scripts/validate_agent_settings.ts +1 -1
  209. package/dist/cli-delegate/chunk-2GNWGMAL.js +0 -172
  210. package/dist/cli-delegate/chunk-LPPWO5CE.js +0 -161
@@ -1,172 +0,0 @@
1
- import { createRequire as __acCreateRequire } from 'node:module'; const require = globalThis.require ?? __acCreateRequire(import.meta.url);
2
- import {
3
- read_lockfile
4
- } from "./chunk-T7L2QK3K.js";
5
-
6
- // src/scripts/_lib/turn_end_refusals.ts
7
- import * as crypto from "node:crypto";
8
- import * as fs from "node:fs";
9
- import * as path from "node:path";
10
- var DETECTOR_IDS = [
11
- "promissory",
12
- "language",
13
- "verification",
14
- "completion"
15
- ];
16
- var REFUSAL_STATE_REL = path.join("agents", "runtime", "state", "turn-end-gate");
17
- function refusalStateDir(workspaceRoot) {
18
- return path.join(workspaceRoot, REFUSAL_STATE_REL);
19
- }
20
- function deriveSessionKey(sessionId) {
21
- return crypto.createHash("sha256").update(sessionId).digest("hex").slice(0, 32);
22
- }
23
- function sessionRefusalFile(workspaceRoot, sessionKey) {
24
- return path.join(refusalStateDir(workspaceRoot), `${sessionKey}.json`);
25
- }
26
- function readSessionCounts(workspaceRoot, sessionId) {
27
- try {
28
- const raw = fs.readFileSync(
29
- sessionRefusalFile(workspaceRoot, deriveSessionKey(sessionId)),
30
- "utf-8"
31
- );
32
- const rec = parseRecord(raw);
33
- return rec === null ? null : countsOf(rec);
34
- } catch {
35
- return null;
36
- }
37
- }
38
- function emptyCounts() {
39
- return { promissory: 0, language: 0, verification: 0, completion: 0 };
40
- }
41
- function isDetector(v) {
42
- return typeof v === "string" && DETECTOR_IDS.includes(v);
43
- }
44
- function parseRecord(raw) {
45
- let decoded;
46
- try {
47
- decoded = JSON.parse(raw);
48
- } catch {
49
- return null;
50
- }
51
- if (typeof decoded !== "object" || decoded === null || Array.isArray(decoded)) return null;
52
- const o = decoded;
53
- if (typeof o["refused_at"] !== "string") return null;
54
- if (typeof o["refused_turn"] !== "number") return null;
55
- if (!isDetector(o["detector"])) return null;
56
- const rec = {
57
- refused_at: o["refused_at"],
58
- refused_turn: o["refused_turn"],
59
- detector: o["detector"]
60
- };
61
- if (typeof o["first_refused_at"] === "string") rec.first_refused_at = o["first_refused_at"];
62
- if (typeof o["agent_config_version"] === "string") {
63
- rec.agent_config_version = o["agent_config_version"];
64
- }
65
- const counts = o["counts"];
66
- if (typeof counts === "object" && counts !== null && !Array.isArray(counts)) {
67
- const parsed = {};
68
- for (const id of DETECTOR_IDS) {
69
- const n = counts[id];
70
- if (typeof n === "number" && Number.isFinite(n) && n >= 0) parsed[id] = n;
71
- }
72
- rec.counts = parsed;
73
- }
74
- return rec;
75
- }
76
- function countsOf(rec) {
77
- const out = emptyCounts();
78
- if (rec.counts === void 0) {
79
- out[rec.detector] = 1;
80
- return out;
81
- }
82
- let any = false;
83
- for (const id of DETECTOR_IDS) {
84
- const n = rec.counts[id];
85
- if (typeof n === "number" && n > 0) {
86
- out[id] = n;
87
- any = true;
88
- }
89
- }
90
- if (!any) out[rec.detector] = 1;
91
- return out;
92
- }
93
- function foldRefusal(prev, input) {
94
- const counts = prev === null ? emptyCounts() : countsOf(prev);
95
- for (const d of input.detectors) counts[d] += 1;
96
- const primary = input.detectors[0] ?? prev?.detector ?? "verification";
97
- const rec = {
98
- refused_at: input.at,
99
- refused_turn: input.turnOrdinal,
100
- detector: primary,
101
- first_refused_at: prev?.first_refused_at ?? prev?.refused_at ?? input.at,
102
- counts
103
- };
104
- if (input.version !== void 0) rec.agent_config_version = input.version;
105
- else if (prev?.agent_config_version !== void 0) {
106
- rec.agent_config_version = prev.agent_config_version;
107
- }
108
- return rec;
109
- }
110
- function readInstallBoundary() {
111
- try {
112
- const lock = read_lockfile();
113
- if (lock === null) return { version: null, installed_at: null };
114
- return {
115
- version: lock.agent_config_version ?? null,
116
- installed_at: lock.installed_at ?? null
117
- };
118
- } catch {
119
- return { version: null, installed_at: null };
120
- }
121
- }
122
- var REFUSAL_STATE_MAX_AGE_DAYS = 90;
123
- function pruneAgedRefusalState(workspaceRoot, opts = {}) {
124
- const maxAgeDays = opts.maxAgeDays ?? REFUSAL_STATE_MAX_AGE_DAYS;
125
- const now = opts.now ?? /* @__PURE__ */ new Date();
126
- const dir = refusalStateDir(workspaceRoot);
127
- const result = { scanned: 0, pruned: 0, kept: 0 };
128
- let entries;
129
- try {
130
- entries = fs.readdirSync(dir);
131
- } catch {
132
- return result;
133
- }
134
- const cutoffMs = now.getTime() - maxAgeDays * 24 * 60 * 60 * 1e3;
135
- for (const name of entries) {
136
- if (!name.endsWith(".json")) continue;
137
- result.scanned += 1;
138
- const file = path.join(dir, name);
139
- let rec = null;
140
- try {
141
- rec = parseRecord(fs.readFileSync(file, "utf-8"));
142
- } catch {
143
- rec = null;
144
- }
145
- if (rec === null) {
146
- result.kept += 1;
147
- continue;
148
- }
149
- const at = Date.parse(rec.refused_at);
150
- if (!Number.isFinite(at) || at >= cutoffMs) {
151
- result.kept += 1;
152
- continue;
153
- }
154
- try {
155
- fs.unlinkSync(file);
156
- result.pruned += 1;
157
- } catch {
158
- result.kept += 1;
159
- }
160
- }
161
- return result;
162
- }
163
-
164
- export {
165
- deriveSessionKey,
166
- sessionRefusalFile,
167
- readSessionCounts,
168
- parseRecord,
169
- foldRefusal,
170
- readInstallBoundary,
171
- pruneAgedRefusalState
172
- };
@@ -1,161 +0,0 @@
1
- import { createRequire as __acCreateRequire } from 'node:module'; const require = globalThis.require ?? __acCreateRequire(import.meta.url);
2
- import {
3
- statePathFor
4
- } from "./chunk-7PRE6ZV2.js";
5
- import {
6
- git_common_dir
7
- } from "./chunk-E4XIZDIB.js";
8
-
9
- // src/scripts/_lib/envelope_grounding.ts
10
- import { execFileSync } from "node:child_process";
11
- import * as fs from "node:fs";
12
- import * as path from "node:path";
13
-
14
- // src/scripts/_lib/git_env.ts
15
- var GIT_DISCOVERY_VARS = [
16
- "GIT_DIR",
17
- "GIT_WORK_TREE",
18
- "GIT_INDEX_FILE",
19
- "GIT_OBJECT_DIRECTORY",
20
- "GIT_ALTERNATE_OBJECT_DIRECTORIES",
21
- "GIT_COMMON_DIR",
22
- "GIT_NAMESPACE",
23
- "GIT_PREFIX"
24
- ];
25
- function gitEnv(base = process.env) {
26
- const env = { ...base };
27
- for (const key of GIT_DISCOVERY_VARS) {
28
- delete env[key];
29
- }
30
- return env;
31
- }
32
-
33
- // src/scripts/_lib/envelope_grounding.ts
34
- var MAX_FIELD_CHARS = 200;
35
- var MAX_PATHS = 40;
36
- function git(root, args) {
37
- try {
38
- return execFileSync("git", args, {
39
- cwd: root,
40
- env: gitEnv(),
41
- encoding: "utf-8",
42
- stdio: ["ignore", "pipe", "ignore"]
43
- }).trim();
44
- } catch {
45
- return null;
46
- }
47
- }
48
- function canonicalizeRepoIdentity(raw) {
49
- let s = raw.trim();
50
- s = s.replace(/^[a-z][a-z0-9+.-]*:\/\//i, "");
51
- s = s.replace(/^[^/@]+@/, "");
52
- s = s.replace(/^([^/:]+):(?!\/)/, "$1/");
53
- s = s.replace(/\/+$/, "");
54
- s = s.replace(/\.git$/i, "");
55
- const slash = s.indexOf("/");
56
- if (slash > 0) {
57
- s = s.slice(0, slash).toLowerCase() + s.slice(slash);
58
- } else {
59
- s = s.toLowerCase();
60
- }
61
- return s;
62
- }
63
- function collectRepoAnchor(root) {
64
- const remote = git(root, ["config", "--get", "remote.origin.url"]);
65
- let identity = null;
66
- if (remote) {
67
- identity = canonicalizeRepoIdentity(remote);
68
- } else {
69
- const common = git_common_dir(root);
70
- if (common !== null) {
71
- try {
72
- identity = fs.realpathSync(common);
73
- } catch {
74
- identity = common;
75
- }
76
- }
77
- }
78
- return {
79
- repo_identity: identity ? identity.slice(0, MAX_FIELD_CHARS) : null,
80
- branch: git(root, ["rev-parse", "--abbrev-ref", "HEAD"]),
81
- head: git(root, ["rev-parse", "HEAD"])
82
- };
83
- }
84
- function readLastVerify(root, session_id) {
85
- if (typeof session_id !== "string" || session_id.trim() === "") return null;
86
- try {
87
- const raw = fs.readFileSync(path.join(root, statePathFor(session_id)), "utf-8");
88
- const state = JSON.parse(raw);
89
- const lv = state["last_verification"];
90
- if (typeof lv !== "object" || lv === null || Array.isArray(lv)) return null;
91
- const rec = lv;
92
- const command = typeof rec["command"] === "string" ? rec["command"] : null;
93
- if (!command) return null;
94
- const at = typeof rec["at"] === "string" ? rec["at"] : "unknown time";
95
- const flat = `${command} @ ${at} (no exit status is recorded anywhere)`.replace(/\s+/g, " ").trim();
96
- return flat.slice(0, MAX_FIELD_CHARS);
97
- } catch {
98
- return null;
99
- }
100
- }
101
- function collectGrounding(root, session_id) {
102
- const anchor = collectRepoAnchor(root);
103
- const porcelain = git(root, ["status", "--porcelain"]);
104
- if (porcelain === null) {
105
- return { ...anchor, uncommitted_paths: [], status_summary: null, last_verify: readLastVerify(root, session_id) };
106
- }
107
- const lines = porcelain.split("\n").filter((l) => l.trim().length > 0);
108
- const paths = lines.map((l) => l.slice(3).trim()).filter((p) => p.length > 0 && p.length <= MAX_FIELD_CHARS).slice(0, MAX_PATHS);
109
- return {
110
- ...anchor,
111
- uncommitted_paths: paths,
112
- status_summary: lines.length === 0 ? "clean working tree" : `${lines.length} uncommitted path(s)${lines.length > MAX_PATHS ? `, first ${MAX_PATHS} listed` : ""}`,
113
- last_verify: readLastVerify(root, session_id)
114
- };
115
- }
116
- function describeDrift(envelope, actual) {
117
- if (typeof envelope !== "object" || envelope === null || Array.isArray(envelope)) return [];
118
- const e = envelope;
119
- const drift = [];
120
- const recordedIdentity = typeof e["repo_identity"] === "string" ? e["repo_identity"] : null;
121
- if (recordedIdentity && actual.repo_identity && recordedIdentity !== actual.repo_identity) {
122
- drift.push(
123
- `IDENTITY DRIFT: this envelope was written in "${recordedIdentity}", you are in "${actual.repo_identity}". Re-verify every path before acting \u2014 same branch name does not mean same working tree.`
124
- );
125
- }
126
- const recordedBranch = typeof e["branch"] === "string" ? e["branch"] : null;
127
- if (recordedBranch && actual.branch && recordedBranch !== actual.branch) {
128
- drift.push(
129
- `BRANCH DRIFT: envelope written on "${recordedBranch}", checkout is on "${actual.branch}".`
130
- );
131
- }
132
- const recordedHead = typeof e["head"] === "string" ? e["head"] : null;
133
- if (recordedHead && actual.head && recordedHead !== actual.head) {
134
- drift.push(
135
- `COMMIT DRIFT: envelope written at ${recordedHead.slice(0, 12)}, HEAD is now ${actual.head.slice(0, 12)} \u2014 re-read anything the envelope quotes.`
136
- );
137
- }
138
- return drift;
139
- }
140
-
141
- // src/scripts/_lib/recycle_envelope_paths.ts
142
- import * as path2 from "node:path";
143
- var RECYCLE_ENVELOPE_REL = path2.join("agents", "runtime", "state", "recycle-envelope.json");
144
- var RECYCLE_CONSUMED_REL = path2.join(
145
- "agents",
146
- "runtime",
147
- "state",
148
- "recycle-envelope.consumed.json"
149
- );
150
- var RECYCLE_MAX_AGE_HOURS = 48;
151
- var RECYCLE_ENVELOPE_MAX_BYTES = 6144;
152
-
153
- export {
154
- collectRepoAnchor,
155
- collectGrounding,
156
- describeDrift,
157
- RECYCLE_ENVELOPE_REL,
158
- RECYCLE_CONSUMED_REL,
159
- RECYCLE_MAX_AGE_HOURS,
160
- RECYCLE_ENVELOPE_MAX_BYTES
161
- };