@event4u/agent-config 17.2.1 → 17.4.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 (225) 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/.claude-plugin/skills/install-agent-config/SKILL.md +9 -9
  5. package/CHANGELOG.md +167 -193
  6. package/CREDITS.md +2 -2
  7. package/README.md +1 -1
  8. package/dist/agent-src/skills/code-intelligence/SKILL.md +16 -12
  9. package/dist/agent-src/templates/agents/agent-project-settings.example.yml +1 -1
  10. package/dist/agent-src/templates/scripts/check_memory.ts +1 -1
  11. package/dist/cli/commands/recordTriggerEval.js +1 -1
  12. package/dist/cli/registry.js +2 -2
  13. package/dist/cli-delegate/{chunk-KR5ZIFPO.js → chunk-5AYJGUA3.js} +1 -3
  14. package/dist/cli-delegate/chunk-DIFZBP4G.js +1336 -0
  15. package/dist/cli-delegate/chunk-E7ACTJTJ.js +6792 -0
  16. package/dist/cli-delegate/{chunk-VYZGJLCA.js → chunk-RKNT4LIK.js} +22 -1286
  17. package/dist/cli-delegate/{chunk-BZJ4Y3CI.js → chunk-WY5ZZPGL.js} +2 -2
  18. package/dist/cli-delegate/{chunk-CMZEKSNN.js → chunk-X6LZ7W5A.js} +73 -10
  19. package/dist/cli-delegate/cmd_conformance.js +190 -192
  20. package/dist/cli-delegate/cmd_doctor.js +5 -5
  21. package/dist/cli-delegate/cmd_doctor_neighbours.js +3 -3
  22. package/dist/cli-delegate/cmd_explain.js +1 -1
  23. package/dist/cli-delegate/cmd_export.js +2 -2
  24. package/dist/cli-delegate/cmd_handoff.js +2 -2
  25. package/dist/cli-delegate/cmd_memory_get.js +1 -1
  26. package/dist/cli-delegate/cmd_prune.js +2 -2
  27. package/dist/cli-delegate/cmd_route_audit.js +1 -1
  28. package/dist/cli-delegate/cmd_session_recycle.js +2 -2
  29. package/dist/cli-delegate/cmd_settings_migrate.js +2 -2
  30. package/dist/cli-delegate/cmd_settings_set.js +8 -4
  31. package/dist/cli-delegate/cmd_sync.js +2 -2
  32. package/dist/cli-delegate/cmd_uninstall.js +2 -2
  33. package/dist/cli-delegate/cmd_update.js +24 -13
  34. package/dist/cli-delegate/cmd_upgrade.js +2 -2
  35. package/dist/cli-delegate/cmd_validate.js +2 -2
  36. package/dist/cli-delegate/dist-25AZAHOP.js +3240 -0
  37. package/dist/cli-delegate/dist-P7MFPMF3.js +411 -0
  38. package/dist/cli-delegate/dist-XAS5ZLQB.js +6 -0
  39. package/dist/cli-delegate/{upgrade_unattended-VVL6JLSX.js → upgrade_unattended-QCWOKTUN.js} +178 -163
  40. package/dist/discovery/deprecation-report.md +1 -1
  41. package/dist/discovery/discovery-manifest.json +3 -3
  42. package/dist/discovery/discovery-manifest.json.sha256 +1 -1
  43. package/dist/discovery/discovery-manifest.summary.md +1 -1
  44. package/dist/discovery/dormancy-report.md +1 -1
  45. package/dist/discovery/orphan-report.md +1 -1
  46. package/dist/discovery/packs.json +2 -2
  47. package/dist/discovery/trust-report.md +1 -1
  48. package/dist/discovery/workspaces.json +2 -2
  49. package/dist/hooks/code_graph_refresh.chunk.cjs +443 -0
  50. package/dist/hooks/code_graph_refresh.chunk.cjs.sha256 +1 -0
  51. package/dist/hooks/dispatch.js +1001 -938
  52. package/dist/hooks/dispatch.sha256 +1 -1
  53. package/dist/hooks/egress_engine.chunk.cjs +57 -7
  54. package/dist/hooks/egress_engine.chunk.cjs.sha256 +1 -1
  55. package/dist/hooks/update_notice.chunk.cjs +914 -0
  56. package/dist/hooks/update_notice.chunk.cjs.sha256 +1 -0
  57. package/dist/install/install.mjs +6974 -6037
  58. package/dist/mcp/mcp-cloudflare-catalogue.json +1 -0
  59. package/dist/mcp/registry-manifest.json +3 -2
  60. package/dist/mcp/server.json +13 -4
  61. package/dist/mcp/server.mjs +71202 -63282
  62. package/dist/scripts/_lib/egress_rules.js +8 -2
  63. package/dist/scripts/condense.js +18 -15
  64. package/dist/server/routes/discovery.js +1 -1
  65. package/dist/server/routes/install.js +1 -1
  66. package/dist/server/routes/ping.js +1 -1
  67. package/dist/server/routes/schema.js +4 -4
  68. package/dist/server/routes/settings.js +2 -6
  69. package/dist/server/routes/wizard.js +6 -6
  70. package/dist/server/schemas/settings.js +42 -42
  71. package/dist/shared/settingsSurface.js +1 -1
  72. package/dist/shared/userMd/schema.js +1 -1
  73. package/dist/shared/zodJsonSchema.js +47 -0
  74. package/dist/ui/assets/index-B0bcIgi0.js +77 -0
  75. package/dist/ui/index.html +1 -1
  76. package/package.json +6 -3
  77. package/src/agent-src/templates/scripts/check_memory.ts +1 -1
  78. package/src/config/ci-local-parity.yml +11 -0
  79. package/src/config/continuity-surface.json +9 -2
  80. package/src/config/evaluator-budgets.json +9 -8
  81. package/src/config/gate-violation-baselines.json +3 -3
  82. package/src/config/gitignore-block.txt +6 -5
  83. package/src/config/hook-bundle-budget.json +46 -6
  84. package/src/config/pack-size-budget.json +12 -1
  85. package/src/config/packed-binary-manifest.json +18 -0
  86. package/src/config/sigstore/npm_keys.json +50 -0
  87. package/src/config/sigstore/trust-material.json +9 -0
  88. package/src/config/sigstore/trusted_root.json +126 -0
  89. package/src/config/skill-body-budget.json +7 -1
  90. package/src/scripts/_cli/cmd_settings_set.ts +3 -2
  91. package/src/scripts/_cli/cmd_update.ts +48 -20
  92. package/src/scripts/_cli/cmd_upgrade.ts +7 -1
  93. package/src/scripts/_cli/upgrade_unattended.ts +90 -76
  94. package/src/scripts/_dispatch.bash +4 -3
  95. package/src/scripts/_lib/confusables.ts +0 -19
  96. package/src/scripts/_lib/egress_normalize.ts +53 -23
  97. package/src/scripts/_lib/egress_rules.ts +8 -2
  98. package/src/scripts/_lib/egress_text.ts +5 -3
  99. package/src/scripts/_lib/egress_token.ts +7 -5
  100. package/src/scripts/_lib/gate_collector_experimental.ts +633 -0
  101. package/src/scripts/_lib/git_common_dir.ts +10 -0
  102. package/src/scripts/_lib/graph_feeder_record.ts +3 -2
  103. package/src/scripts/_lib/install_reach_checks.ts +32 -2
  104. package/src/scripts/_lib/lineage_backfill.ts +136 -0
  105. package/src/scripts/_lib/lineage_ledger.ts +211 -0
  106. package/src/scripts/_lib/lineage_map.ts +55 -0
  107. package/src/scripts/_lib/lineage_query.ts +140 -0
  108. package/src/scripts/_lib/lineage_seed.ts +116 -0
  109. package/src/scripts/_lib/lineage_watch.ts +249 -0
  110. package/src/scripts/_lib/link_crypto.ts +8 -4
  111. package/src/scripts/_lib/listing_manifests.ts +85 -0
  112. package/src/scripts/_lib/neighbour_census.ts +1 -0
  113. package/src/scripts/_lib/production_reach.ts +3 -3
  114. package/src/scripts/_lib/project_registry.ts +227 -0
  115. package/src/scripts/_lib/provenance_verify.ts +14 -242
  116. package/src/scripts/_lib/release_settings_surface.ts +2 -6
  117. package/src/scripts/_lib/sigstore_provenance.ts +177 -0
  118. package/src/scripts/_lib/source_id.ts +48 -0
  119. package/src/scripts/_lib/source_shape.ts +4 -0
  120. package/src/scripts/_lib/unattended_gates.ts +6 -1
  121. package/src/scripts/adoption_status.ts +231 -27
  122. package/src/scripts/advisories.ts +26 -10
  123. package/src/scripts/ai_council/council_egress.ts +5 -6
  124. package/src/scripts/bench_graph_feeder_latency.ts +10 -3
  125. package/src/scripts/build_mcp_registry_manifest.ts +23 -12
  126. package/src/scripts/check_dependency_floors.ts +14 -0
  127. package/src/scripts/check_egress_mutations.ts +1 -0
  128. package/src/scripts/check_release_manifest_content.ts +17 -2
  129. package/src/scripts/check_release_pr_shape.ts +5 -0
  130. package/src/scripts/code_graph/build.ts +145 -45
  131. package/src/scripts/code_graph/cli.ts +382 -35
  132. package/src/scripts/code_graph/conventions_default.ts +247 -0
  133. package/src/scripts/code_graph/detect.ts +5 -5
  134. package/src/scripts/code_graph/estate_cli.ts +135 -0
  135. package/src/scripts/code_graph/estate_index.ts +394 -0
  136. package/src/scripts/code_graph/estate_manifests.ts +223 -0
  137. package/src/scripts/code_graph/estate_map.ts +141 -0
  138. package/src/scripts/code_graph/extract.ts +8 -2
  139. package/src/scripts/code_graph/extract_more.ts +241 -2
  140. package/src/scripts/code_graph/graph_budget.ts +158 -0
  141. package/src/scripts/code_graph/graph_home.ts +80 -0
  142. package/src/scripts/code_graph/lineage_cli.ts +315 -0
  143. package/src/scripts/code_graph/loader.ts +10 -2
  144. package/src/scripts/code_graph/map.ts +195 -53
  145. package/src/scripts/code_graph/map_model.ts +113 -20
  146. package/src/scripts/code_graph/map_verify.ts +80 -5
  147. package/src/scripts/code_graph/map_viewer/viewer.css +18 -0
  148. package/src/scripts/code_graph/map_viewer/viewer.js +146 -15
  149. package/src/scripts/code_graph/passes.ts +173 -0
  150. package/src/scripts/code_graph/project_ref.ts +25 -0
  151. package/src/scripts/code_graph/projects_cli.ts +254 -0
  152. package/src/scripts/code_graph/providers/angular.ts +55 -0
  153. package/src/scripts/code_graph/providers/aspnetcore.ts +182 -0
  154. package/src/scripts/code_graph/providers/catalog.ts +299 -0
  155. package/src/scripts/code_graph/providers/django.ts +206 -0
  156. package/src/scripts/code_graph/providers/express.ts +25 -0
  157. package/src/scripts/code_graph/providers/fastapi.ts +49 -0
  158. package/src/scripts/code_graph/providers/flask.ts +99 -0
  159. package/src/scripts/code_graph/providers/go_http.ts +121 -0
  160. package/src/scripts/code_graph/providers/index.ts +103 -0
  161. package/src/scripts/code_graph/{laravel_overlay.ts → providers/laravel.ts} +113 -7
  162. package/src/scripts/code_graph/providers/nestjs.ts +34 -0
  163. package/src/scripts/code_graph/providers/nextjs.ts +91 -0
  164. package/src/scripts/code_graph/providers/nuxt.ts +55 -0
  165. package/src/scripts/code_graph/providers/rails.ts +204 -0
  166. package/src/scripts/code_graph/providers/react-router.ts +58 -0
  167. package/src/scripts/code_graph/providers/shared/detect.ts +78 -0
  168. package/src/scripts/code_graph/providers/shared/extractors.ts +249 -0
  169. package/src/scripts/code_graph/providers/shared/js.ts +252 -0
  170. package/src/scripts/code_graph/providers/shared/kit.ts +210 -0
  171. package/src/scripts/code_graph/providers/shared/php.ts +64 -0
  172. package/src/scripts/code_graph/providers/shared/python.ts +223 -0
  173. package/src/scripts/code_graph/providers/spring.ts +175 -0
  174. package/src/scripts/code_graph/providers/sqlalchemy.ts +62 -0
  175. package/src/scripts/code_graph/providers/sveltekit.ts +59 -0
  176. package/src/scripts/code_graph/providers/symfony.ts +142 -0
  177. package/src/scripts/code_graph/providers/typeorm.ts +58 -0
  178. package/src/scripts/code_graph/providers/types.ts +56 -0
  179. package/src/scripts/code_graph/providers/vue-router.ts +21 -0
  180. package/src/scripts/code_graph/providers/wordpress.ts +128 -0
  181. package/src/scripts/code_graph/query.ts +9 -9
  182. package/src/scripts/code_graph/refresh_cli.ts +81 -0
  183. package/src/scripts/code_graph/refresh_lock.ts +197 -0
  184. package/src/scripts/code_graph/repo_identity.ts +169 -0
  185. package/src/scripts/code_graph/resolution_tiers.ts +19 -7
  186. package/src/scripts/code_graph/scip_reader.ts +2 -2
  187. package/src/scripts/code_graph/sqlite_store.ts +31 -28
  188. package/src/scripts/code_graph/types.ts +79 -41
  189. package/src/scripts/code_graph/validate.ts +6 -8
  190. package/src/scripts/condense.ts +15 -15
  191. package/src/scripts/generate_settings_reference.ts +2 -6
  192. package/src/scripts/hook_chunks.mjs +11 -0
  193. package/src/scripts/hook_manifest.json +1 -1
  194. package/src/scripts/hook_manifest.yaml +43 -23
  195. package/src/scripts/hooks/code_graph_refresh_hook.ts +163 -0
  196. package/src/scripts/hooks/dispatch_hook.ts +6 -7
  197. package/src/scripts/hooks/host_semantics.ts +72 -0
  198. package/src/scripts/hooks/lazy_concern.ts +8 -0
  199. package/src/scripts/hooks/user_notice.ts +105 -0
  200. package/src/scripts/install-hooks.sh +54 -33
  201. package/src/scripts/install.ts +2 -6
  202. package/src/scripts/lint_harvest_provenance.ts +137 -11
  203. package/src/scripts/lint_hook_manifest.ts +2 -0
  204. package/src/scripts/lint_marketplace.ts +33 -0
  205. package/src/scripts/lint_mcp_registry_manifest.ts +36 -0
  206. package/src/scripts/mcp_server/consumer_tool_catalog.json +70 -15
  207. package/src/scripts/mcp_server/graph_tools.ts +165 -41
  208. package/src/scripts/network_sources.ts +24 -6
  209. package/src/scripts/release.ts +2 -5
  210. package/src/scripts/release_drill.ts +4 -1
  211. package/src/scripts/release_env.ts +17 -0
  212. package/src/scripts/release_mix_taxonomy.json +3 -0
  213. package/src/scripts/schemas/provenance-mechanism.schema.json +46 -0
  214. package/src/scripts/update_notice_hook.ts +75 -7
  215. package/src/server/schemas/settings.ts +42 -42
  216. package/src/shared/settingsSurface.ts +1 -1
  217. package/src/shared/userMd/schema.ts +1 -1
  218. package/src/shared/zodJsonSchema.ts +41 -0
  219. package/src/vendor/grammars/README.md +8 -6
  220. package/src/vendor/grammars/tree-sitter-c_sharp.wasm +0 -0
  221. package/src/vendor/grammars/tree-sitter-ruby.wasm +0 -0
  222. package/dist/cli-delegate/chunk-XIAPY44N.js +0 -4587
  223. package/dist/ui/assets/index-w70Ado09.js +0 -23
  224. /package/dist/cli-delegate/{chunk-FKYZOWVD.js → chunk-QBAFP67O.js} +0 -0
  225. /package/dist/cli-delegate/{chunk-BMGUGSY6.js → chunk-TQG6UMPC.js} +0 -0
@@ -0,0 +1,914 @@
1
+ #!/usr/bin/env node
2
+ const __acChunkMetaUrl = require('node:url').pathToFileURL(__filename).href; const __acChunkMeta = { url: __acChunkMetaUrl, dirname: __dirname, filename: __filename };
3
+ "use strict";
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __export = (target, all) => {
11
+ for (var name in all)
12
+ __defProp(target, name, { get: all[name], enumerable: true });
13
+ };
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
+ mod
29
+ ));
30
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
31
+
32
+ // src/scripts/update_notice_hook.ts
33
+ var update_notice_hook_exports = {};
34
+ __export(update_notice_hook_exports, {
35
+ CONCERN: () => CONCERN,
36
+ NOTICE_STATE_FILENAME: () => NOTICE_STATE_FILENAME,
37
+ NOTICE_STATE_SCHEMA: () => NOTICE_STATE_SCHEMA,
38
+ NOTICE_THROTTLE_FILENAME: () => NOTICE_THROTTLE_FILENAME,
39
+ confirmDelivered: () => confirmDelivered,
40
+ main: () => main,
41
+ noticeOncePerDay: () => noticeOncePerDay,
42
+ ranToday: () => ranToday,
43
+ readNoticeState: () => readNoticeState,
44
+ readUpdateMode: () => readUpdateMode,
45
+ runNotice: () => runNotice,
46
+ writeNoticeState: () => writeNoticeState
47
+ });
48
+ module.exports = __toCommonJS(update_notice_hook_exports);
49
+ var import_node_crypto2 = require("node:crypto");
50
+ var fs8 = __toESM(require("node:fs"), 1);
51
+ var path7 = __toESM(require("node:path"), 1);
52
+ var import_node_url2 = require("node:url");
53
+ var import_yaml = require("yaml");
54
+
55
+ // src/scripts/_cli/doctor_install_mode.ts
56
+ var fs2 = __toESM(require("node:fs"), 1);
57
+ var path2 = __toESM(require("node:path"), 1);
58
+
59
+ // src/scripts/_lib/user_global_paths.ts
60
+ var fs = __toESM(require("node:fs"), 1);
61
+ var os = __toESM(require("node:os"), 1);
62
+ var path = __toESM(require("node:path"), 1);
63
+ var EVENT4U_HOME_ENV = "EVENT4U_CONFIG_HOME";
64
+ var DEFAULT_EVENT4U_ROOT_RELATIVE = path.join(".event4u", "agent-config");
65
+ var LEGACY_XDG_ROOT_RELATIVE = path.join(".config", "agent-config");
66
+ function expanduser(p) {
67
+ if (p === "~") {
68
+ return os.homedir();
69
+ }
70
+ if (p.startsWith("~/") || process.platform === "win32" && p.startsWith("~\\")) {
71
+ return path.join(os.homedir(), p.slice(2));
72
+ }
73
+ return p;
74
+ }
75
+ function is_absolute_like_python(p) {
76
+ if (process.platform === "win32") {
77
+ return /^[a-zA-Z]:[\\/]/.test(p) || /^([\\/]{2})[^\\/]+[\\/][^\\/]+/.test(p);
78
+ }
79
+ return p.startsWith("/");
80
+ }
81
+ function event4u_root(env) {
82
+ const env_map = env ?? process.env;
83
+ const override = env_map[EVENT4U_HOME_ENV];
84
+ if (override) {
85
+ return expanduser(override);
86
+ }
87
+ return path.join(os.homedir(), DEFAULT_EVENT4U_ROOT_RELATIVE);
88
+ }
89
+ function legacy_xdg_root() {
90
+ return path.join(os.homedir(), LEGACY_XDG_ROOT_RELATIVE);
91
+ }
92
+ function resolve_with_fallback(relative_name, options = {}) {
93
+ if (is_absolute_like_python(relative_name)) {
94
+ throw new Error(
95
+ `resolve_with_fallback expects a relative path, got '${relative_name}'`
96
+ );
97
+ }
98
+ const new_path = path.join(event4u_root(options.env ?? null), relative_name);
99
+ if (fs.existsSync(new_path)) {
100
+ return new_path;
101
+ }
102
+ const legacy_path = path.join(legacy_xdg_root(), relative_name);
103
+ if (fs.existsSync(legacy_path)) {
104
+ return legacy_path;
105
+ }
106
+ return null;
107
+ }
108
+ function write_target(relative_name, options = {}) {
109
+ if (is_absolute_like_python(relative_name)) {
110
+ throw new Error(`write_target expects a relative path, got '${relative_name}'`);
111
+ }
112
+ return path.join(event4u_root(options.env ?? null), relative_name);
113
+ }
114
+
115
+ // src/scripts/_lib/version_order.ts
116
+ var NUM = "(0|[1-9]\\d*)";
117
+ var IDENT = "[0-9A-Za-z-]+";
118
+ var VERSION_RE = new RegExp(
119
+ `^v*${NUM}\\.${NUM}\\.${NUM}(?:-(${IDENT}(?:\\.${IDENT})*))?(?:\\+${IDENT}(?:\\.${IDENT})*)?$`
120
+ );
121
+ function parse_version(v) {
122
+ if (typeof v !== "string") return null;
123
+ const m = VERSION_RE.exec(v.trim());
124
+ if (!m) return null;
125
+ const pre = m[4] === void 0 ? [] : m[4].split(".").map((id) => /^\d+$/.test(id) ? Number(id) : id);
126
+ return { major: Number(m[1]), minor: Number(m[2]), patch: Number(m[3]), pre };
127
+ }
128
+ function cmp_num(a, b) {
129
+ return a === b ? 0 : a < b ? -1 : 1;
130
+ }
131
+ function compare_parsed(a, b) {
132
+ const core = cmp_num(a.major, b.major) || cmp_num(a.minor, b.minor) || cmp_num(a.patch, b.patch);
133
+ if (core !== 0) return core;
134
+ if (a.pre.length === 0 || b.pre.length === 0) return cmp_num(b.pre.length, a.pre.length);
135
+ for (let i = 0; i < Math.max(a.pre.length, b.pre.length); i += 1) {
136
+ const x = a.pre[i];
137
+ const y = b.pre[i];
138
+ if (x === void 0) return -1;
139
+ if (y === void 0) return 1;
140
+ if (typeof x === "number" && typeof y === "number") {
141
+ if (x !== y) return cmp_num(x, y);
142
+ } else if (typeof x === "number") {
143
+ return -1;
144
+ } else if (typeof y === "number") {
145
+ return 1;
146
+ } else if (x !== y) {
147
+ return x < y ? -1 : 1;
148
+ }
149
+ }
150
+ return 0;
151
+ }
152
+ function compare_versions(a, b) {
153
+ const pa = parse_version(a);
154
+ const pb = parse_version(b);
155
+ if (pa === null || pb === null) return null;
156
+ return compare_parsed(pa, pb);
157
+ }
158
+
159
+ // src/scripts/_lib/update_check.ts
160
+ var PACKAGE_NAME = "@event4u/agent-config";
161
+ var NPM_REGISTRY_URL = `https://registry.npmjs.org/${PACKAGE_NAME}/latest`;
162
+ var CHECK_WINDOW_MS = 24 * 60 * 60 * 1e3;
163
+ var STATE_FILENAME = "update-check.json";
164
+ var DEFAULT_STATE_PATH = write_target(STATE_FILENAME);
165
+ var GLOBAL_TREE = /[\\/](?:lib|npm)[\\/]node_modules[\\/]@event4u[\\/]agent-config[\\/]?$/;
166
+ function classify_install_origin(signals) {
167
+ const pin = signals.project_pin?.trim() ?? "";
168
+ if (pin !== "") {
169
+ return signals.latest && _is_newer(signals.latest, pin) ? "project-pin" : "unknown";
170
+ }
171
+ if (signals.package_root.split(/[\\/]+/).includes("_npx")) {
172
+ return "ephemeral";
173
+ }
174
+ if (signals.is_global_consumer || GLOBAL_TREE.test(signals.package_root)) {
175
+ return "global";
176
+ }
177
+ return "unknown";
178
+ }
179
+ function _int_or_zero(part) {
180
+ const trimmed = part.trim();
181
+ if (/^[+-]?\d+$/.test(trimmed)) {
182
+ return parseInt(trimmed, 10);
183
+ }
184
+ return 0;
185
+ }
186
+ function _is_newer(latest, installed) {
187
+ const parse = (v) => {
188
+ const core = v.replace(/^v+/, "").split("-")[0] ?? "";
189
+ const parts = core.split(".");
190
+ const out = [];
191
+ for (const p of parts.slice(0, 3)) {
192
+ out.push(_int_or_zero(p));
193
+ }
194
+ while (out.length < 3) {
195
+ out.push(0);
196
+ }
197
+ return [out[0], out[1], out[2]];
198
+ };
199
+ const a = parse(latest);
200
+ const b = parse(installed);
201
+ for (let i = 0; i < 3; i += 1) {
202
+ if (a[i] > b[i]) {
203
+ return true;
204
+ }
205
+ if (a[i] < b[i]) {
206
+ return false;
207
+ }
208
+ }
209
+ return false;
210
+ }
211
+
212
+ // src/scripts/_cli/doctor_install_mode.ts
213
+ function isSourceCheckoutPackage(packageRoot) {
214
+ return fs2.existsSync(path2.join(packageRoot, ".git"));
215
+ }
216
+ function originForPackageRoot(root) {
217
+ if (isSourceCheckoutPackage(root)) return "source-checkout";
218
+ return classify_install_origin({ package_root: root, project_pin: null, latest: null, is_global_consumer: false });
219
+ }
220
+
221
+ // src/scripts/_lib/agent_settings.ts
222
+ var import_node_module = require("node:module");
223
+ var path4 = __toESM(require("node:path"), 1);
224
+
225
+ // src/scripts/_lib/package_root.ts
226
+ var fs3 = __toESM(require("node:fs"), 1);
227
+ var path3 = __toESM(require("node:path"), 1);
228
+ var import_node_url = require("node:url");
229
+ var PACKAGE_NAME2 = "@event4u/agent-config";
230
+ var MAX_ASCENT = 16;
231
+ function resolvePackageRoot(fromUrlOrPath, legacyHops = 3) {
232
+ const start = fromUrlOrPath.startsWith("file:") ? (0, import_node_url.fileURLToPath)(fromUrlOrPath) : fromUrlOrPath;
233
+ const startDir = path3.dirname(start);
234
+ let dir = startDir;
235
+ for (let i = 0; i < MAX_ASCENT; i++) {
236
+ const manifest = path3.join(dir, "package.json");
237
+ if (fs3.existsSync(manifest)) {
238
+ try {
239
+ const parsed = JSON.parse(fs3.readFileSync(manifest, "utf8"));
240
+ if (parsed.name === PACKAGE_NAME2) {
241
+ return dir;
242
+ }
243
+ } catch {
244
+ }
245
+ }
246
+ const parent = path3.dirname(dir);
247
+ if (parent === dir) {
248
+ break;
249
+ }
250
+ dir = parent;
251
+ }
252
+ return path3.resolve(startDir, ...Array.from({ length: legacyHops }, () => ".."));
253
+ }
254
+
255
+ // src/scripts/_lib/agent_settings.ts
256
+ var _require = (0, import_node_module.createRequire)(__acChunkMetaUrl);
257
+ var Logger = class {
258
+ name = "scripts._lib.agent_settings";
259
+ records = [];
260
+ info(message, ...args) {
261
+ this.records.push({ level: "INFO", message: _format(message, args) });
262
+ }
263
+ warning(message, ...args) {
264
+ this.records.push({ level: "WARNING", message: _format(message, args) });
265
+ }
266
+ };
267
+ function _format(template, args) {
268
+ let i = 0;
269
+ return template.replace(/%s/g, () => {
270
+ if (i < args.length) {
271
+ const value = args[i];
272
+ i += 1;
273
+ return _pystr(value);
274
+ }
275
+ return "%s";
276
+ });
277
+ }
278
+ function _pystr(value) {
279
+ if (Array.isArray(value)) {
280
+ return `[${value.map((v) => _pyrepr(v)).join(", ")}]`;
281
+ }
282
+ return String(value);
283
+ }
284
+ function _pyrepr(value) {
285
+ if (typeof value === "string") {
286
+ return `'${value}'`;
287
+ }
288
+ return String(value);
289
+ }
290
+ var logger = new Logger();
291
+ var USER_GLOBAL_FILENAME = "agent-settings.yml";
292
+ function DEFAULT_USER_GLOBAL_FILE() {
293
+ return write_target(USER_GLOBAL_FILENAME);
294
+ }
295
+ var USER_GLOBAL_CANONICAL_RELATIVE = "settings/.agent-settings.yml";
296
+ function user_global_settings_paths() {
297
+ const paths = [];
298
+ const flat = resolve_with_fallback(USER_GLOBAL_FILENAME);
299
+ if (flat !== null) {
300
+ paths.push(flat);
301
+ }
302
+ const canonical = resolve_with_fallback(USER_GLOBAL_CANONICAL_RELATIVE);
303
+ if (canonical !== null) {
304
+ paths.push(canonical);
305
+ }
306
+ if (paths.length === 0) {
307
+ paths.push(DEFAULT_USER_GLOBAL_FILE());
308
+ }
309
+ return paths;
310
+ }
311
+ var TEMPLATE_RELATIVE = path4.join("src", "config", "agent-settings.template.yml");
312
+ var _PACKAGE_ROOT = resolvePackageRoot(__acChunkMetaUrl);
313
+
314
+ // src/scripts/_lib/session_register.ts
315
+ var import_node_fs2 = __toESM(require("node:fs"), 1);
316
+ var import_node_path2 = __toESM(require("node:path"), 1);
317
+
318
+ // src/scripts/_lib/fs_atomic.ts
319
+ var import_node_fs = __toESM(require("node:fs"), 1);
320
+ var import_node_path = __toESM(require("node:path"), 1);
321
+ var import_node_crypto = require("node:crypto");
322
+ function _normalize_encoding(encoding) {
323
+ const compact = encoding.toLowerCase().replace(/[-_\s]/g, "");
324
+ const candidates = [encoding, compact];
325
+ if (compact === "latin1" || compact === "iso88591") candidates.push("latin1");
326
+ if (compact === "utf8") candidates.push("utf8");
327
+ if (compact === "utf16le" || compact === "utf16") candidates.push("utf16le");
328
+ if (compact === "usascii") candidates.push("ascii");
329
+ for (const c of candidates) {
330
+ if (Buffer.isEncoding(c)) return c;
331
+ }
332
+ throw new Error(`unknown encoding: ${encoding}`);
333
+ }
334
+ function write_atomic(p, data, options = {}) {
335
+ const encoding = options.encoding ?? "utf-8";
336
+ const target = import_node_path.default.normalize(p);
337
+ const parent = import_node_path.default.dirname(target);
338
+ import_node_fs.default.mkdirSync(parent, { recursive: true });
339
+ let payload;
340
+ if (typeof data === "string") {
341
+ payload = Buffer.from(data, _normalize_encoding(encoding));
342
+ } else if (data instanceof Uint8Array) {
343
+ payload = Buffer.from(data);
344
+ } else {
345
+ throw new TypeError(
346
+ `write_atomic: data must be str or bytes, got ${typeof data}`
347
+ );
348
+ }
349
+ let fd = null;
350
+ let tmp_path = "";
351
+ for (let attempt = 0; attempt < 32; attempt += 1) {
352
+ tmp_path = import_node_path.default.join(
353
+ parent,
354
+ `.${import_node_path.default.basename(target)}.tmp.${(0, import_node_crypto.randomBytes)(6).toString("hex")}`
355
+ );
356
+ try {
357
+ fd = import_node_fs.default.openSync(tmp_path, "wx", 384);
358
+ break;
359
+ } catch (err) {
360
+ if (err.code === "EEXIST") continue;
361
+ throw err;
362
+ }
363
+ }
364
+ if (fd === null) {
365
+ throw new Error("write_atomic: could not create a unique temp file");
366
+ }
367
+ let closed = false;
368
+ try {
369
+ let offset = 0;
370
+ while (offset < payload.length) {
371
+ offset += import_node_fs.default.writeSync(fd, payload, offset, payload.length - offset);
372
+ }
373
+ try {
374
+ import_node_fs.default.fsyncSync(fd);
375
+ } catch {
376
+ }
377
+ import_node_fs.default.closeSync(fd);
378
+ closed = true;
379
+ import_node_fs.default.renameSync(tmp_path, target);
380
+ } catch (err) {
381
+ if (!closed) {
382
+ try {
383
+ import_node_fs.default.closeSync(fd);
384
+ } catch {
385
+ }
386
+ }
387
+ try {
388
+ import_node_fs.default.unlinkSync(tmp_path);
389
+ } catch {
390
+ }
391
+ throw err;
392
+ }
393
+ _fsync_dir(parent);
394
+ return target;
395
+ }
396
+ function _fsync_dir(directory) {
397
+ let dir_fd;
398
+ try {
399
+ dir_fd = import_node_fs.default.openSync(directory, import_node_fs.default.constants.O_RDONLY);
400
+ } catch {
401
+ return;
402
+ }
403
+ try {
404
+ try {
405
+ import_node_fs.default.fsyncSync(dir_fd);
406
+ } catch {
407
+ }
408
+ } finally {
409
+ import_node_fs.default.closeSync(dir_fd);
410
+ }
411
+ }
412
+
413
+ // src/scripts/_lib/session_register.ts
414
+ var TTL_MEASURED_SECONDS = Object.freeze({
415
+ claude: 14400
416
+ // 4 h — raw p99 13 705 s / raw user→user max 14 199 s, rounded up
417
+ });
418
+ var TTL_DEFAULT_SECONDS = 43200;
419
+ function ttl_seconds_for(platform) {
420
+ const key = String(platform ?? "").trim().toLowerCase();
421
+ return TTL_MEASURED_SECONDS[key] ?? TTL_DEFAULT_SECONDS;
422
+ }
423
+ function safe_stem(session_id) {
424
+ const collapsed = String(session_id ?? "").replace(/\.\./g, "_").replace(/[/\\]/g, "_").replace(/[^A-Za-z0-9._-]/g, "_").slice(0, 128);
425
+ return /[A-Za-z0-9]/.test(collapsed) ? collapsed : "unknown-session";
426
+ }
427
+ function global_register_dir(env) {
428
+ return import_node_path2.default.join(event4u_root(env), "runtime", "sessions");
429
+ }
430
+ function epoch_ms(stamp) {
431
+ if (typeof stamp !== "string" || stamp.length === 0) return null;
432
+ const ms = Date.parse(stamp);
433
+ return Number.isFinite(ms) ? ms : null;
434
+ }
435
+ function is_expired(rec, now = /* @__PURE__ */ new Date()) {
436
+ const seen = epoch_ms(rec.last_seen);
437
+ if (seen === null) return true;
438
+ const age_s = (now.getTime() - seen) / 1e3;
439
+ return age_s > ttl_seconds_for(rec.platform);
440
+ }
441
+ function is_record(v) {
442
+ if (typeof v !== "object" || v === null) return false;
443
+ const o = v;
444
+ return typeof o["session_id"] === "string" && typeof o["last_seen"] === "string";
445
+ }
446
+ var PRUNE_GRACE_MS = 24 * 60 * 60 * 1e3;
447
+ function read_live_records(dir, options = {}) {
448
+ const now = options.now ?? /* @__PURE__ */ new Date();
449
+ const prune = options.prune === true;
450
+ const grace = options.prune_grace_ms ?? PRUNE_GRACE_MS;
451
+ let names;
452
+ try {
453
+ names = import_node_fs2.default.readdirSync(dir).filter((n) => n.endsWith(".json"));
454
+ } catch {
455
+ return [];
456
+ }
457
+ const live = [];
458
+ for (const name of names) {
459
+ const full = import_node_path2.default.join(dir, name);
460
+ let rec = null;
461
+ try {
462
+ const parsed = JSON.parse(import_node_fs2.default.readFileSync(full, "utf-8"));
463
+ rec = is_record(parsed) ? parsed : null;
464
+ } catch {
465
+ rec = null;
466
+ }
467
+ if (rec === null || is_expired(rec, now)) {
468
+ if (prune && (rec === null || is_expired(rec, new Date(now.getTime() - grace)))) {
469
+ try {
470
+ import_node_fs2.default.unlinkSync(full);
471
+ } catch {
472
+ }
473
+ }
474
+ continue;
475
+ }
476
+ live.push(rec);
477
+ }
478
+ return live;
479
+ }
480
+ function foreign_live_records(dir, session_id, options = {}) {
481
+ const own = safe_stem(session_id);
482
+ return read_live_records(dir, options).filter((r) => safe_stem(r.session_id) !== own);
483
+ }
484
+ function any_live_session(dir, session_id, now = /* @__PURE__ */ new Date()) {
485
+ const records = session_id === void 0 || session_id === null ? read_live_records(dir, { now }) : foreign_live_records(dir, session_id, { now });
486
+ return records.length > 0;
487
+ }
488
+
489
+ // src/scripts/_lib/consumer_impact.ts
490
+ var CONSUMER_IMPACT_VALUES = ["none", "automatic", "notice", "action"];
491
+ var NO_IMPACT_TRAILERS = Object.freeze({
492
+ impact: "none",
493
+ recorded: false,
494
+ invalid: null,
495
+ security: false
496
+ });
497
+ var IMPACT_RANK = Object.freeze({
498
+ none: 0,
499
+ automatic: 1,
500
+ notice: 2,
501
+ action: 3
502
+ });
503
+
504
+ // src/scripts/_lib/update_notice.ts
505
+ var SECURITY_POLICY_REF = "SECURITY.md:21 \u2014 fixes land on the latest version only; older releases are not backported";
506
+ var HEAD_PRIORITY = [
507
+ "Security and correctness",
508
+ "Default changes + migration",
509
+ "Known limitations",
510
+ "Behaviour changes",
511
+ "Honest nulls"
512
+ ];
513
+ function sanitiseImpactMap(map) {
514
+ const clean = /* @__PURE__ */ new Map();
515
+ if (map === null || typeof map !== "object" || Array.isArray(map)) return clean;
516
+ for (const [version, entry] of Object.entries(map)) {
517
+ if (parse_version(version) === null) continue;
518
+ if (entry === null || typeof entry !== "object" || Array.isArray(entry)) continue;
519
+ const impact = entry["impact"];
520
+ if (!CONSUMER_IMPACT_VALUES.includes(impact)) continue;
521
+ clean.set(version, { impact, security: entry["security"] === true });
522
+ }
523
+ return clean;
524
+ }
525
+ function impactInRange(map, installed, candidate) {
526
+ const rank = (i) => CONSUMER_IMPACT_VALUES.indexOf(i);
527
+ let worst = null;
528
+ let security = false;
529
+ for (const [version, entry] of map) {
530
+ if (compare_versions(version, installed) !== 1 || compare_versions(version, candidate) === 1) continue;
531
+ if (worst === null || rank(entry.impact) > rank(worst)) worst = entry.impact;
532
+ security = security || entry.security;
533
+ }
534
+ return { worst, security };
535
+ }
536
+ var NOTHING = (reason) => ({ lines: [], stage: null, activate: null, suppressed: reason });
537
+ var RECONCILE_REASONS = /* @__PURE__ */ new Set(["no cached candidate", "nothing newer cached"]);
538
+ function noticeSuppression(input) {
539
+ if (input.env.ci) return "CI";
540
+ if (!input.env.interactive) return "non-interactive";
541
+ if (input.env.noUpdateCheck) return "AGENT_CONFIG_NO_UPDATE_CHECK=1";
542
+ if (input.origin === "source-checkout") return "source checkout";
543
+ if (input.origin === "ephemeral") return "ephemeral run";
544
+ if (input.mode === "off") return "update.mode off";
545
+ return null;
546
+ }
547
+ function oneCuratedLine(head) {
548
+ for (const label of HEAD_PRIORITY) {
549
+ const text = head.get(label);
550
+ if (text !== void 0 && text.trim() !== "" && text.trim() !== "_none_") {
551
+ return `${label}: ${text.trim()}`;
552
+ }
553
+ }
554
+ return null;
555
+ }
556
+ function shownVersion(candidate) {
557
+ const v = parse_version(candidate);
558
+ return `${v.major}.${v.minor}.${v.patch}${v.pre.length > 0 ? " (pre-release)" : ""}`;
559
+ }
560
+ function updateNotice(input) {
561
+ const suppressed = noticeSuppression(input);
562
+ if (suppressed !== null) return NOTHING(suppressed);
563
+ if (input.lastSeenInstalled !== null && compare_versions(input.installed, input.lastSeenInstalled) === 1) {
564
+ const line = oneCuratedLine(input.curatedHead);
565
+ const lines2 = [`agent-config is now ${input.installed} (was ${input.lastSeenInstalled}).`];
566
+ if (line !== null) lines2.push(` ${line}`);
567
+ return { lines: lines2, stage: null, activate: null, suppressed: null };
568
+ }
569
+ if (input.candidate === null || parse_version(input.candidate) === null) return NOTHING("no cached candidate");
570
+ if (compare_versions(input.candidate, input.installed) !== 1) return NOTHING("nothing newer cached");
571
+ const range = impactInRange(sanitiseImpactMap(input.impactMap), input.installed, input.candidate);
572
+ const lines = [`agent-config ${shownVersion(input.candidate)} is available (installed: ${input.installed}).`];
573
+ if (range.security) lines.push(` Security fix in range. ${SECURITY_POLICY_REF}.`);
574
+ if (range.worst === "notice") lines.push(" A release in range carries a notice \u2014 read it before upgrading.");
575
+ if (range.worst === "action") lines.push(" A release in range needs a hand; it is never installed unattended.");
576
+ const stageable = range.worst !== "action";
577
+ if (input.mode === "auto" && stageable) {
578
+ lines.push(
579
+ input.foreignSessionLive ? " Staged. Another session is open on this machine, so a swap would break its hooks." : " Staged. Run `agent-config upgrade --unattended` to install it."
580
+ );
581
+ } else {
582
+ lines.push(" Run `agent-config upgrade` to install it.");
583
+ }
584
+ return { lines, stage: stageable ? input.candidate : null, activate: null, suppressed: null };
585
+ }
586
+ function parseCuratedHead(changelog, version) {
587
+ const head = /* @__PURE__ */ new Map();
588
+ const lines = changelog.split("\n");
589
+ const sectionStart = lines.findIndex((l) => new RegExp(`^## \\[?${version.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\]?(\\s|$)`).test(l));
590
+ if (sectionStart < 0) return head;
591
+ let inHighlights = false;
592
+ for (let i = sectionStart + 1; i < lines.length; i += 1) {
593
+ const line = lines[i];
594
+ if (/^#{1,2} /.test(line)) break;
595
+ if (/^### /.test(line)) {
596
+ inHighlights = /^### Release highlights\s*$/.test(line);
597
+ continue;
598
+ }
599
+ if (!inHighlights) continue;
600
+ const m = /^- \*\*(.+?):\*\*\s*(.*)$/.exec(line);
601
+ if (m !== null) head.set(m[1], m[2].trim());
602
+ }
603
+ return head;
604
+ }
605
+
606
+ // src/scripts/hooks/hook_stdin.ts
607
+ var tty = __toESM(require("node:tty"), 1);
608
+
609
+ // src/scripts/_lib/stdin.ts
610
+ var fs6 = __toESM(require("node:fs"), 1);
611
+ var CHUNK = 64 * 1024;
612
+ var RETRY_SLEEP_MS = 5;
613
+ var MAX_RETRIES = 2e3;
614
+ function _sleepSync(ms) {
615
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
616
+ }
617
+ function readStdinText(fd = 0, opts = {}) {
618
+ const chunks = [];
619
+ const buf = Buffer.alloc(CHUNK);
620
+ let retries = 0;
621
+ let got_any = false;
622
+ const first_byte_deadline = opts.firstByteTimeoutMs === void 0 ? null : Date.now() + opts.firstByteTimeoutMs;
623
+ for (; ; ) {
624
+ let read;
625
+ try {
626
+ read = fs6.readSync(fd, buf, 0, CHUNK, null);
627
+ retries = 0;
628
+ } catch (exc) {
629
+ const code = exc.code;
630
+ if (code === "EAGAIN") {
631
+ if (!got_any && first_byte_deadline !== null && Date.now() >= first_byte_deadline) {
632
+ return "";
633
+ }
634
+ retries += 1;
635
+ if (retries > MAX_RETRIES) {
636
+ throw new Error(
637
+ `readStdinText: stdin stayed unreadable across ${String(MAX_RETRIES)} retries (~${String(MAX_RETRIES * RETRY_SLEEP_MS / 1e3)}s). Refusing to report an empty read as empty input.`
638
+ );
639
+ }
640
+ _sleepSync(RETRY_SLEEP_MS);
641
+ continue;
642
+ }
643
+ if (code === "EOF") break;
644
+ throw exc;
645
+ }
646
+ if (read === 0) break;
647
+ got_any = true;
648
+ chunks.push(Buffer.from(buf.subarray(0, read)));
649
+ }
650
+ return Buffer.concat(chunks).toString("utf-8");
651
+ }
652
+
653
+ // src/scripts/hooks/hook_stdin.ts
654
+ var OVERRIDE_KEY = /* @__PURE__ */ Symbol.for("agent-config.hookStdinOverride");
655
+ function host() {
656
+ return globalThis;
657
+ }
658
+ var HOOK_FIRST_BYTE_TIMEOUT_MS = 25;
659
+ function readFd0ToEnd() {
660
+ void process.stdin;
661
+ return readStdinText(0, { firstByteTimeoutMs: HOOK_FIRST_BYTE_TIMEOUT_MS });
662
+ }
663
+ function readHookStdin() {
664
+ const override = host()[OVERRIDE_KEY];
665
+ if (override !== null && override !== void 0) return override;
666
+ try {
667
+ if (tty.isatty(0)) return "";
668
+ return readFd0ToEnd();
669
+ } catch {
670
+ return "";
671
+ }
672
+ }
673
+
674
+ // src/scripts/hooks/state_io.ts
675
+ var REPLAY_ENV_VAR = "AGENT_CONFIG_REPLAY";
676
+ function is_replay_mode() {
677
+ return (process.env[REPLAY_ENV_VAR] ?? "").trim() === "1";
678
+ }
679
+
680
+ // src/scripts/hooks/user_notice.ts
681
+ var fs7 = __toESM(require("node:fs"), 1);
682
+ var USER_NOTICE_KEY = "user_notice";
683
+ var USER_NOTICE_ID_KEY = "notice_id";
684
+ var USER_NOTICE_HOSTS = /* @__PURE__ */ new Set(["claude"]);
685
+ function hostShowsUserNotice(platform) {
686
+ return typeof platform === "string" && USER_NOTICE_HOSTS.has(platform);
687
+ }
688
+ function receiptPath(concern) {
689
+ return write_target(`user-notice-${concern}.delivered`);
690
+ }
691
+ function readNoticeReceipt(concern) {
692
+ try {
693
+ const o = JSON.parse(fs7.readFileSync(receiptPath(concern), "utf-8"));
694
+ return typeof o["session_id"] === "string" && typeof o["notice_id"] === "string" && typeof o["at"] === "string" ? { session_id: o["session_id"], notice_id: o["notice_id"], at: o["at"] } : null;
695
+ } catch {
696
+ return null;
697
+ }
698
+ }
699
+
700
+ // src/scripts/update_notice_hook.ts
701
+ var CONCERN = "update-notice";
702
+ var NOTICE_STATE_FILENAME = "update-notice.json";
703
+ var NOTICE_THROTTLE_FILENAME = "update-notice.stamp";
704
+ var VALID_MODES = ["off", "notify", "ask", "auto"];
705
+ var NOTICE_STATE_SCHEMA = 1;
706
+ function readNoticeState(statePath) {
707
+ try {
708
+ if (statePath === null) return { staged: null, last_seen_installed: null };
709
+ const raw = JSON.parse(fs8.readFileSync(statePath, "utf-8"));
710
+ const o = raw !== null && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
711
+ if (o["schema"] !== void 0 && o["schema"] !== NOTICE_STATE_SCHEMA) return { staged: null, last_seen_installed: null };
712
+ const str = (v) => typeof v === "string" && parse_version(v.trim()) !== null ? v.trim() : null;
713
+ const p = o["pending"];
714
+ const installed = str(p?.["installed"]);
715
+ const pending = typeof p?.["session_id"] === "string" && typeof p["notice_id"] === "string" && installed !== null ? { session_id: p["session_id"], notice_id: p["notice_id"], installed } : void 0;
716
+ return { staged: str(o["staged"]), last_seen_installed: str(o["last_seen_installed"]), ...pending ? { pending } : {} };
717
+ } catch {
718
+ return { staged: null, last_seen_installed: null };
719
+ }
720
+ }
721
+ function confirmDelivered(state, receipt) {
722
+ const p = state.pending;
723
+ if (p === void 0 || receipt === null || !receipt.notice_id || receipt.notice_id !== p.notice_id || receipt.session_id !== p.session_id) return state;
724
+ return { staged: state.staged, last_seen_installed: p.installed };
725
+ }
726
+ function writeNoticeState(statePath, state) {
727
+ try {
728
+ write_atomic(statePath, `${JSON.stringify({ schema: NOTICE_STATE_SCHEMA, ...state }, null, 2)}
729
+ `);
730
+ } catch {
731
+ }
732
+ }
733
+ function readUpdateMode(paths = user_global_settings_paths()) {
734
+ let found;
735
+ for (const p of paths) {
736
+ try {
737
+ const doc = (0, import_yaml.parse)(fs8.readFileSync(p, "utf-8"), { version: "1.1" });
738
+ const block = doc?.["update"];
739
+ if (block === null || typeof block !== "object" || Array.isArray(block)) continue;
740
+ const mode = block["mode"];
741
+ if (typeof mode === "string" && VALID_MODES.includes(mode)) found = mode;
742
+ } catch {
743
+ }
744
+ }
745
+ return found;
746
+ }
747
+ function readJson(p) {
748
+ try {
749
+ const raw = JSON.parse(fs8.readFileSync(p, "utf-8"));
750
+ return raw !== null && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
751
+ } catch {
752
+ return {};
753
+ }
754
+ }
755
+ function readText(p) {
756
+ try {
757
+ return fs8.readFileSync(p, "utf-8");
758
+ } catch {
759
+ return "";
760
+ }
761
+ }
762
+ function envelopeField(raw, key) {
763
+ try {
764
+ const doc = JSON.parse(raw);
765
+ const value = doc?.[key];
766
+ return typeof value === "string" && value.trim() !== "" ? value.trim() : null;
767
+ } catch {
768
+ return null;
769
+ }
770
+ }
771
+ function runNotice(deps, apply = true) {
772
+ const pkg = readJson(path7.join(deps.packageRoot, "package.json"));
773
+ const installed = typeof pkg["version"] === "string" ? pkg["version"] : "";
774
+ if (installed === "") return { lines: [], stage: null, activate: null, suppressed: "installed version unreadable" };
775
+ const probe = deps.probeStatePath === null ? {} : readJson(deps.probeStatePath);
776
+ const seen = probe["last_seen_version"];
777
+ const state = confirmDelivered(readNoticeState(deps.noticeStatePath), deps.receipt?.() ?? null);
778
+ const outcome = updateNotice({
779
+ installed,
780
+ candidate: typeof seen === "string" && seen.trim() !== "" ? seen.trim() : null,
781
+ impactMap: probe["last_seen_impact"] ?? null,
782
+ mode: deps.mode,
783
+ origin: originForPackageRoot(deps.packageRoot),
784
+ env: {
785
+ ci: ["1", "true"].includes((deps.env["CI"] ?? "").trim().toLowerCase()) || deps.env["GITHUB_ACTIONS"] === "true",
786
+ interactive: deps.isTty,
787
+ noUpdateCheck: deps.env["AGENT_CONFIG_NO_UPDATE_CHECK"] === "1"
788
+ },
789
+ curatedHead: parseCuratedHead(readText(path7.join(deps.packageRoot, "CHANGELOG.md")), installed),
790
+ staged: state.staged,
791
+ lastSeenInstalled: state.last_seen_installed,
792
+ foreignSessionLive: any_live_session(deps.registerDir, deps.sessionId)
793
+ });
794
+ if (!apply) return outcome;
795
+ if (outcome.suppressed !== null) {
796
+ if (RECONCILE_REASONS.has(outcome.suppressed) && (state.staged !== null || state.last_seen_installed !== installed)) {
797
+ writeNoticeState(deps.noticeStatePath, { staged: null, last_seen_installed: installed });
798
+ }
799
+ return outcome;
800
+ }
801
+ if (deps.notice !== void 0) {
802
+ const noticeId = (0, import_node_crypto2.randomUUID)();
803
+ if (outcome.lines.length > 0) {
804
+ deps.notice.write(JSON.stringify({ [USER_NOTICE_KEY]: outcome.lines.join("\n"), [USER_NOTICE_ID_KEY]: noticeId }));
805
+ }
806
+ writeNoticeState(deps.noticeStatePath, {
807
+ staged: outcome.stage,
808
+ last_seen_installed: state.last_seen_installed,
809
+ ...outcome.lines.length > 0 && deps.sessionId ? { pending: { session_id: deps.sessionId, notice_id: noticeId, installed } } : {}
810
+ });
811
+ return outcome;
812
+ }
813
+ for (const line of outcome.lines) deps.err.write(`[update] ${line}
814
+ `);
815
+ writeNoticeState(deps.noticeStatePath, { staged: outcome.stage, last_seen_installed: installed });
816
+ return outcome;
817
+ }
818
+ function noticeOncePerDay(deps) {
819
+ const dry = runNotice(deps, false);
820
+ if (dry.suppressed !== null && !RECONCILE_REASONS.has(dry.suppressed)) return null;
821
+ if (deps.notice !== void 0) {
822
+ const receipt = deps.receipt?.() ?? null;
823
+ if (receipt !== null && localDay(new Date(receipt.at)) === localDay(/* @__PURE__ */ new Date())) {
824
+ const stored = readNoticeState(deps.noticeStatePath);
825
+ const confirmed = confirmDelivered(stored, receipt);
826
+ if (confirmed !== stored) writeNoticeState(deps.noticeStatePath, confirmed);
827
+ if (confirmed.pending === void 0) return null;
828
+ }
829
+ return runNotice(deps);
830
+ }
831
+ if (ranToday(deps.throttlePath)) return null;
832
+ const outcome = runNotice(deps);
833
+ stampToday(deps.throttlePath);
834
+ return outcome;
835
+ }
836
+ function localDay(d) {
837
+ return `${String(d.getFullYear())}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
838
+ }
839
+ function ranToday(throttlePath) {
840
+ try {
841
+ const st = fs8.lstatSync(throttlePath);
842
+ return st.isFile() && localDay(st.mtime) === localDay(/* @__PURE__ */ new Date());
843
+ } catch {
844
+ return false;
845
+ }
846
+ }
847
+ function stampToday(throttlePath) {
848
+ if (is_replay_mode()) return;
849
+ try {
850
+ write_atomic(throttlePath, `${(/* @__PURE__ */ new Date()).toISOString()}
851
+ `);
852
+ } catch {
853
+ }
854
+ }
855
+ function packageRootOf() {
856
+ const env = process.env["AGENT_CONFIG_PACKAGE_ROOT"];
857
+ if (env) return env;
858
+ return path7.resolve(path7.dirname((0, import_node_url2.fileURLToPath)(__acChunkMetaUrl)), "..", "..");
859
+ }
860
+ function main(argv) {
861
+ void argv;
862
+ const raw = readHookStdin();
863
+ if (is_replay_mode()) return 0;
864
+ try {
865
+ const packageRoot = packageRootOf();
866
+ const mode = readUpdateMode();
867
+ const viaHost = envelopeField(raw, "session_id") !== null && hostShowsUserNotice(envelopeField(raw, "platform"));
868
+ const deps = {
869
+ packageRoot,
870
+ sessionId: envelopeField(raw, "session_id"),
871
+ env: process.env,
872
+ isTty: viaHost || Boolean(process.stderr.isTTY) || Boolean(process.stdout.isTTY),
873
+ ...viaHost ? { notice: process.stdout, receipt: () => readNoticeReceipt(CONCERN) } : {},
874
+ mode,
875
+ probeStatePath: resolve_with_fallback(STATE_FILENAME),
876
+ noticeStatePath: write_target(NOTICE_STATE_FILENAME),
877
+ throttlePath: write_target(NOTICE_THROTTLE_FILENAME),
878
+ registerDir: global_register_dir(),
879
+ err: process.stderr
880
+ };
881
+ noticeOncePerDay(deps);
882
+ return 0;
883
+ } catch {
884
+ return 0;
885
+ }
886
+ }
887
+ function _isCliEntry() {
888
+ if (true) return false;
889
+ if (process.argv[1] === void 0) return false;
890
+ if (__acChunkMetaUrl === (0, import_node_url2.pathToFileURL)(path7.resolve(process.argv[1])).href) return true;
891
+ try {
892
+ return fs8.realpathSync((0, import_node_url2.fileURLToPath)(__acChunkMetaUrl)) === fs8.realpathSync(path7.resolve(process.argv[1]));
893
+ } catch {
894
+ return false;
895
+ }
896
+ }
897
+ if (_isCliEntry()) {
898
+ process.exit(main(process.argv.slice(2)));
899
+ }
900
+ // Annotate the CommonJS export names for ESM import in node:
901
+ 0 && (module.exports = {
902
+ CONCERN,
903
+ NOTICE_STATE_FILENAME,
904
+ NOTICE_STATE_SCHEMA,
905
+ NOTICE_THROTTLE_FILENAME,
906
+ confirmDelivered,
907
+ main,
908
+ noticeOncePerDay,
909
+ ranToday,
910
+ readNoticeState,
911
+ readUpdateMode,
912
+ runNotice,
913
+ writeNoticeState
914
+ });