@aiwg/cli 2026.10.15 → 2026.10.18

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 (286) hide show
  1. package/agentic/code/providers/pi/aiwg-bridge.ts +45 -7
  2. package/dist/src/artifacts/citation-parser.js +7 -6
  3. package/dist/src/artifacts/corpus-tools/citation-densify.js +4 -2
  4. package/dist/src/artifacts/corpus-tools/cli.js +8 -3
  5. package/dist/src/artifacts/corpus-tools/discovery-log.js +26 -24
  6. package/dist/src/artifacts/corpus-tools/expand-cli.js +3 -2
  7. package/dist/src/artifacts/corpus-tools/expand-dates.js +107 -0
  8. package/dist/src/artifacts/corpus-tools/expand-queue.js +4 -1
  9. package/dist/src/artifacts/corpus-tools/expand-review.js +104 -0
  10. package/dist/src/artifacts/corpus-tools/expand-state.js +17 -1
  11. package/dist/src/artifacts/corpus-tools/expand.js +16 -17
  12. package/dist/src/artifacts/corpus-tools/induction-audit.js +7 -6
  13. package/dist/src/artifacts/corpus-tools/integrity-scan.js +3 -3
  14. package/dist/src/artifacts/corpus-tools/radar-shared.js +7 -9
  15. package/dist/src/artifacts/corpus-tools/ref-files.js +11 -0
  16. package/dist/src/artifacts/corpus-tools/resolve-cli.js +11 -3
  17. package/dist/src/artifacts/corpus-tools/resolve.js +42 -11
  18. package/dist/src/artifacts/corpus-tools/retrieval-lab.js +2 -1
  19. package/dist/src/artifacts/corpus-tools/sidecar-lint.js +4 -4
  20. package/dist/src/artifacts/corpus-tools/sidecar-repair.js +2 -1
  21. package/dist/src/artifacts/corpus-views/ref-parser.js +3 -17
  22. package/dist/src/artifacts/graph-query.js +5 -3
  23. package/dist/src/artifacts/hybrid-query.js +11 -2
  24. package/dist/src/artifacts/index-refresh.js +2 -0
  25. package/dist/src/artifacts/query-engine-corpus.js +217 -0
  26. package/dist/src/artifacts/query-engine-discover-output.js +229 -0
  27. package/dist/src/artifacts/query-engine-discover.js +285 -0
  28. package/dist/src/artifacts/query-engine-entries.js +188 -0
  29. package/dist/src/artifacts/query-engine-index.js +249 -0
  30. package/dist/src/artifacts/query-engine-matching.js +143 -0
  31. package/dist/src/artifacts/query-engine-options.js +2 -0
  32. package/dist/src/artifacts/query-engine-rules.js +202 -0
  33. package/dist/src/artifacts/query-engine-scoring.js +436 -0
  34. package/dist/src/artifacts/query-engine-show-card.js +194 -0
  35. package/dist/src/artifacts/query-engine-show-load.js +211 -0
  36. package/dist/src/artifacts/query-engine-show.js +300 -0
  37. package/dist/src/artifacts/query-engine.js +7 -2576
  38. package/dist/src/cli/handlers/daemon.js +17 -1
  39. package/dist/src/cli/handlers/doctor-args.js +10 -5
  40. package/dist/src/cli/handlers/doctor-help.js +4 -1
  41. package/dist/src/cli/handlers/index.js +2 -2
  42. package/dist/src/cli/handlers/mc-agents.js +111 -0
  43. package/dist/src/cli/handlers/mc-args.js +54 -0
  44. package/dist/src/cli/handlers/mc-control.js +227 -0
  45. package/dist/src/cli/handlers/mc-dispatch.js +203 -0
  46. package/dist/src/cli/handlers/mc-help.js +171 -0
  47. package/dist/src/cli/handlers/mc-run.js +343 -0
  48. package/dist/src/cli/handlers/mc-session.js +138 -0
  49. package/dist/src/cli/handlers/mc-status.js +258 -0
  50. package/dist/src/cli/handlers/mc-summary.js +43 -0
  51. package/dist/src/cli/handlers/mc-types.js +3 -0
  52. package/dist/src/cli/handlers/mc-worker.js +205 -0
  53. package/dist/src/cli/handlers/mc.js +12 -1665
  54. package/dist/src/cli/handlers/models-refusal.js +13 -0
  55. package/dist/src/cli/handlers/models-resource-sample.js +10 -0
  56. package/dist/src/cli/handlers/models.js +5 -3
  57. package/dist/src/cli/handlers/regenerate.js +8 -16
  58. package/dist/src/cli/handlers/remove-bundled.js +133 -0
  59. package/dist/src/cli/handlers/remove-options.js +31 -0
  60. package/dist/src/cli/handlers/remove-user.js +174 -0
  61. package/dist/src/cli/handlers/remove.js +201 -0
  62. package/dist/src/cli/handlers/sessions.js +7 -7
  63. package/dist/src/cli/handlers/subcommands-bundles.js +257 -0
  64. package/dist/src/cli/handlers/subcommands-discovery.js +165 -0
  65. package/dist/src/cli/handlers/subcommands-list-format.js +129 -0
  66. package/dist/src/cli/handlers/subcommands-list.js +250 -0
  67. package/dist/src/cli/handlers/subcommands-plugins.js +213 -0
  68. package/dist/src/cli/handlers/subcommands-quickref.js +58 -0
  69. package/dist/src/cli/handlers/subcommands-rlm.js +113 -0
  70. package/dist/src/cli/handlers/subcommands-services.js +66 -0
  71. package/dist/src/cli/handlers/subcommands-storage.js +259 -0
  72. package/dist/src/cli/handlers/subcommands.js +18 -1976
  73. package/dist/src/cli/handlers/update.js +157 -0
  74. package/dist/src/cli/handlers/use.js +14 -4
  75. package/dist/src/cli/handlers/utilities.js +3 -560
  76. package/dist/src/cli/handlers/utility-doctor.js +412 -0
  77. package/dist/src/cli/scope-resolver.js +1 -142
  78. package/dist/src/cli/services/deployment-verification.js +0 -1
  79. package/dist/src/cli/user-scope-mirror.js +173 -0
  80. package/dist/src/config/aiwg-config.js +2 -1
  81. package/dist/src/config/authorization-cli.js +7 -3
  82. package/dist/src/config/dispatch-host-thresholds.js +2 -0
  83. package/dist/src/config/dispatch-thresholds-runtime.d.mts +3 -2
  84. package/dist/src/config/dispatch-thresholds-runtime.mjs +21 -7
  85. package/dist/src/config/framework-aliases.js +12 -0
  86. package/dist/src/config/host-resource-report.d.mts +24 -0
  87. package/dist/src/config/host-resource-report.mjs +110 -0
  88. package/dist/src/config/host-resource-runtime.d.mts +37 -0
  89. package/dist/src/config/host-resource-runtime.mjs +296 -0
  90. package/dist/src/config/installed-selection.js +22 -0
  91. package/dist/src/config/worker-invocation-marker.d.mts +1 -0
  92. package/dist/src/config/worker-invocation-marker.mjs +2 -0
  93. package/dist/src/decision/ensemble-study/artifacts.js +7 -0
  94. package/dist/src/decision/ensemble-study/gate-policy.js +58 -0
  95. package/dist/src/decision/ensemble-study/gates.js +78 -0
  96. package/dist/src/decision/ensemble-study/protocol.js +18 -21
  97. package/dist/src/decision/ensemble-study/score.js +3 -2
  98. package/dist/src/decision/ensemble-study/statistics.js +7 -26
  99. package/dist/src/decision/heldout/access.js +74 -0
  100. package/dist/src/decision/heldout/calibration.js +1 -0
  101. package/dist/src/decision/heldout/collector.js +8 -1
  102. package/dist/src/decision/sensitivity/comparative-gates.js +135 -0
  103. package/dist/src/decision/sensitivity/comparative.js +18 -41
  104. package/dist/src/effects/verifiers/file.js +22 -5
  105. package/dist/src/extensions/claude-attribution.js +82 -0
  106. package/dist/src/extensions/claude-hooks-installer.js +133 -69
  107. package/dist/src/extensions/commands/daemon.js +109 -0
  108. package/dist/src/extensions/commands/definitions.js +5 -89
  109. package/dist/src/gates/evaluate.js +2 -358
  110. package/dist/src/gates/heldout.js +17 -7
  111. package/dist/src/gates/observations.js +363 -0
  112. package/dist/src/gates/pack-composition.js +270 -0
  113. package/dist/src/gates/pack-tightening.js +197 -0
  114. package/dist/src/gates/pack-validation.js +262 -0
  115. package/dist/src/gates/registry-error.js +5 -0
  116. package/dist/src/gates/registry.js +13 -685
  117. package/dist/src/lint/check-patterns.js +163 -0
  118. package/dist/src/lint/checks.js +268 -0
  119. package/dist/src/lint/reference-resolution.js +54 -0
  120. package/dist/src/lint/runner.js +3 -465
  121. package/dist/src/mcp/helpers.mjs +11 -1
  122. package/dist/src/mcp/json-document.mjs +29 -0
  123. package/dist/src/mcp/muse-native-config.mjs +1 -28
  124. package/dist/src/memory/project-registry.js +44 -4
  125. package/dist/src/mission-protocol/worker-review-gate.js +7 -0
  126. package/dist/src/models/worker-plan.js +36 -5
  127. package/dist/src/models/wrapper-deployment.js +25 -12
  128. package/dist/src/models/wrapper-enforcement.js +47 -7
  129. package/dist/src/network-analysis/research.js +2 -1
  130. package/dist/src/plugin/command-ownership.js +34 -0
  131. package/dist/src/plugin/skill-command-frontmatter.js +197 -0
  132. package/dist/src/plugin/skill-command-translator.js +6 -232
  133. package/dist/src/policy/hitl-check.js +14 -4
  134. package/dist/src/policy/hitl-consume.js +54 -0
  135. package/dist/src/policy/hitl-receipt.js +2 -0
  136. package/dist/src/policy/hitl.js +11 -3
  137. package/dist/src/providers/context-output-ownership.js +26 -0
  138. package/dist/src/providers/deployment-ownership.d.mts +19 -0
  139. package/dist/src/providers/deployment-ownership.mjs +226 -0
  140. package/dist/src/providers/deployment-removal.js +200 -0
  141. package/dist/src/providers/provider-context-contracts.js +162 -0
  142. package/dist/src/providers/provider-definition-schema.js +136 -0
  143. package/dist/src/providers/provider-definitions.js +8 -1298
  144. package/dist/src/providers/provider-seeds-1.js +360 -0
  145. package/dist/src/providers/provider-seeds-2.js +387 -0
  146. package/dist/src/providers/provider-seeds-3.js +262 -0
  147. package/dist/src/providers/removal-transaction.js +86 -0
  148. package/dist/src/providers/settings-document.d.mts +3 -0
  149. package/dist/src/providers/settings-document.mjs +47 -0
  150. package/dist/src/providers/settings-removal.js +190 -0
  151. package/dist/src/providers/skill-ownership.d.mts +19 -2
  152. package/dist/src/providers/skill-ownership.mjs +12 -4
  153. package/dist/src/providers/transformation-receipt-integration.js +15 -271
  154. package/dist/src/providers/transformation-receipt-outputs.js +99 -0
  155. package/dist/src/providers/transformation-receipt-source.js +194 -0
  156. package/dist/src/research/clients/arxiv.js +4 -30
  157. package/dist/src/research/clients/base.js +48 -22
  158. package/dist/src/research/identity.js +42 -4
  159. package/dist/src/research/query-cli.js +3 -87
  160. package/dist/src/research/query-options.js +87 -0
  161. package/dist/src/research/reference-match.js +105 -24
  162. package/dist/src/research/services/acquisition.js +9 -7
  163. package/dist/src/research/services/citation.js +5 -2
  164. package/dist/src/research/types.js +2 -0
  165. package/dist/src/rules/activation.mjs +15 -6
  166. package/dist/src/rules/core-startup.mjs +2 -2
  167. package/dist/src/serve/mission-conductor.js +52 -4
  168. package/dist/src/serve/mission-summary.js +56 -0
  169. package/dist/src/sessions/adapters/grok-build-native.js +23 -0
  170. package/dist/src/sessions/adapters/grok-build.js +14 -7
  171. package/dist/src/sessions/workspace-discovery.js +5 -5
  172. package/dist/src/smiths/context-pipeline/aiwg-md.js +39 -46
  173. package/dist/src/smiths/context-pipeline/claude-hook.js +1 -1
  174. package/dist/src/smiths/context-pipeline/code-regions.js +28 -0
  175. package/dist/src/smiths/context-pipeline/context-file-safety.js +3 -0
  176. package/dist/src/smiths/context-pipeline/finalization.js +81 -51
  177. package/dist/src/smiths/context-pipeline/generator.js +10 -11
  178. package/dist/src/smiths/context-pipeline/managed-hook.js +1 -1
  179. package/dist/src/smiths/context-pipeline/muse-bridge.js +2 -2
  180. package/dist/src/smiths/context-pipeline/provider-policy.js +6 -12
  181. package/dist/src/smiths/context-pipeline/workspace-audit.js +299 -0
  182. package/dist/src/smiths/context-pipeline/workspace-bootstrap.js +148 -0
  183. package/dist/src/smiths/context-pipeline/workspace-context-shared.js +111 -0
  184. package/dist/src/smiths/context-pipeline/workspace-context.js +8 -1373
  185. package/dist/src/smiths/context-pipeline/workspace-doctor.js +192 -0
  186. package/dist/src/smiths/context-pipeline/workspace-document.js +201 -0
  187. package/dist/src/smiths/context-pipeline/workspace-extraction.js +205 -0
  188. package/dist/src/smiths/context-pipeline/workspace-migration.js +250 -0
  189. package/dist/src/smiths/hook-bridge/index.js +9 -0
  190. package/package.json +13 -1
  191. package/schemas/decision/D17StudyProtocol.v1.schema.json +39 -67
  192. package/schemas/decision/D29Study.v10.schema.json +65 -0
  193. package/tools/agents/deploy-agents.mjs +24 -675
  194. package/tools/agents/deploy-command-mirrors.mjs +229 -0
  195. package/tools/agents/deploy-options.mjs +258 -0
  196. package/tools/agents/deploy-support.mjs +165 -0
  197. package/tools/agents/providers/base-addon-discovery.mjs +139 -0
  198. package/tools/agents/providers/base-behaviors.mjs +168 -0
  199. package/tools/agents/providers/base-context.mjs +205 -0
  200. package/tools/agents/providers/base-contract.mjs +116 -0
  201. package/tools/agents/providers/base-files.mjs +252 -0
  202. package/tools/agents/providers/base-flat-artifacts.mjs +233 -0
  203. package/tools/agents/providers/base-framework-discovery.mjs +309 -0
  204. package/tools/agents/providers/base-frontmatter.mjs +196 -0
  205. package/tools/agents/providers/base-inventory.mjs +269 -0
  206. package/tools/agents/providers/base-kernel-skills.mjs +354 -0
  207. package/tools/agents/providers/base-migrations.mjs +258 -0
  208. package/tools/agents/providers/base-models-platforms.mjs +273 -0
  209. package/tools/agents/providers/base-rule-index.mjs +450 -0
  210. package/tools/agents/providers/base-runtime.mjs +60 -0
  211. package/tools/agents/providers/base-skill-copy.mjs +273 -0
  212. package/tools/agents/providers/base.mjs +16 -3364
  213. package/tools/agents/providers/claude-post-deploy.mjs +20 -1
  214. package/tools/agents/providers/context-write.mjs +4 -0
  215. package/tools/agents/providers/hermes-startup.mjs +0 -5
  216. package/tools/agents/providers/muse.mjs +7 -2
  217. package/tools/agents/providers/pi.mjs +3 -1
  218. package/tools/agents/providers/rule-delivery-surface.mjs +359 -0
  219. package/tools/agents/providers/rule-delivery.mjs +20 -1144
  220. package/tools/agents/providers/rule-deployment-commit.mjs +148 -0
  221. package/tools/agents/providers/rule-deployment-prepare.mjs +461 -0
  222. package/tools/agents/providers/rule-deployment-state.mjs +300 -0
  223. package/tools/agents/providers/rule-projection.mjs +3 -0
  224. package/tools/daemon/README.md +511 -0
  225. package/tools/daemon/adapters/base-adapter.mjs +84 -0
  226. package/tools/daemon/adapters/webhook-adapter.mjs +107 -0
  227. package/tools/daemon/agent-supervisor.mjs +299 -0
  228. package/tools/daemon/automation-engine.mjs +310 -0
  229. package/tools/daemon/autonomous-engine.mjs +346 -0
  230. package/tools/daemon/behavior-loader.mjs +316 -0
  231. package/tools/daemon/behavior.mjs +174 -0
  232. package/tools/daemon/concierge/intent-router.mjs +401 -0
  233. package/tools/daemon/concierge/orchestrator.mjs +272 -0
  234. package/tools/daemon/concierge/response-translator.mjs +462 -0
  235. package/tools/daemon/config.mjs +377 -0
  236. package/tools/daemon/cron-scheduler.mjs +178 -0
  237. package/tools/daemon/daemon-main.mjs +1169 -0
  238. package/tools/daemon/event-router.mjs +84 -0
  239. package/tools/daemon/file-watcher.mjs +383 -0
  240. package/tools/daemon/index.mjs +1181 -0
  241. package/tools/daemon/init-profile.mjs +124 -0
  242. package/tools/daemon/ipc-client.mjs +197 -0
  243. package/tools/daemon/ipc-ops-handlers.mjs +236 -0
  244. package/tools/daemon/ipc-server.mjs +275 -0
  245. package/tools/daemon/maintenance-owner.mjs +79 -0
  246. package/tools/daemon/memory-manager.mjs +386 -0
  247. package/tools/daemon/message-router.mjs +194 -0
  248. package/tools/daemon/provider-watcher.mjs +585 -0
  249. package/tools/daemon/pty-adapter.mjs +420 -0
  250. package/tools/daemon/repl-chat.mjs +359 -0
  251. package/tools/daemon/resource-bounds.mjs +88 -0
  252. package/tools/daemon/sandbox-transport.mjs +295 -0
  253. package/tools/daemon/scheduled-task-runner.mjs +535 -0
  254. package/tools/daemon/task-store.mjs +450 -0
  255. package/tools/daemon/tmux-manager.mjs +324 -0
  256. package/tools/daemon/update-policy.mjs +517 -0
  257. package/tools/daemon/web-server.mjs +399 -0
  258. package/tools/daemon/web-ui/index.html +585 -0
  259. package/tools/daemon/web-ui/styles.css +156 -0
  260. package/tools/docker/Dockerfile.daemon +35 -0
  261. package/tools/docker/container-manager.mjs +291 -0
  262. package/tools/messaging/adapter-registry.mjs +230 -0
  263. package/tools/messaging/adapters/base.mjs +326 -0
  264. package/tools/messaging/adapters/discord.mjs +462 -0
  265. package/tools/messaging/adapters/slack.mjs +402 -0
  266. package/tools/messaging/adapters/telegram.mjs +552 -0
  267. package/tools/messaging/chat-handler.mjs +297 -0
  268. package/tools/messaging/command-router.mjs +269 -0
  269. package/tools/messaging/event-bus.mjs +199 -0
  270. package/tools/messaging/index.mjs +456 -0
  271. package/tools/messaging/message-formatter.mjs +320 -0
  272. package/tools/messaging/room-manager.mjs +277 -0
  273. package/tools/messaging/types.mjs +94 -0
  274. package/tools/providers/pi-bridge-policy.mjs +4 -0
  275. package/tools/ralph-external/daemon-supervisor.mjs +394 -0
  276. package/tools/ralph-external/lib/behavior-registry.mjs +270 -0
  277. package/tools/ralph-external/lib/worker-invocation-processes.mjs +7 -4
  278. package/tools/ralph-external/lib/worker-isolation-args.mjs +217 -0
  279. package/tools/ralph-external/lib/worker-isolation-status.mjs +19 -0
  280. package/tools/ralph-external/lib/worker-isolation.mjs +11 -237
  281. package/tools/ralph-external/lib/worker-overflow.mjs +10 -2
  282. package/tools/ralph-external/lib/worker-termination.mjs +15 -8
  283. package/tools/ralph-external/lib/worker-unit-cleanup.mjs +72 -0
  284. package/tools/ralph-external/session-launcher.mjs +7 -7
  285. package/tools/scripts/resource-preflight.mjs +3 -242
  286. package/vscode-extension/schemas/aiwg.config.v1.json +2 -4
@@ -0,0 +1,86 @@
1
+ // Back up a removal's complete write set before applying it; roll back failures.
2
+ import fs from 'node:fs';
3
+ import os from 'node:os';
4
+ import path from 'node:path';
5
+ function verifyPreimage(write) {
6
+ let ancestor = write.path;
7
+ while (ancestor !== path.dirname(ancestor)) {
8
+ if (fs.existsSync(ancestor) && fs.lstatSync(ancestor).isSymbolicLink())
9
+ throw new Error(`Symlink changed during removal planning: ${write.path}`);
10
+ ancestor = path.dirname(ancestor);
11
+ }
12
+ const current = fs.existsSync(write.path) ? fs.readFileSync(write.path) : null;
13
+ if (write.before === null ? current !== null : !current?.equals(write.before))
14
+ throw new Error(`Changed during removal planning: ${write.path}`);
15
+ }
16
+ export async function applyRemovalTransaction(writes, commit) {
17
+ if (!writes.length)
18
+ return;
19
+ const backup = fs.mkdtempSync(path.join(os.tmpdir(), 'aiwg-remove-'));
20
+ fs.chmodSync(backup, 0o700);
21
+ const entries = writes.map((write, index) => ({ path: write.path, backup: write.before ? `${index}` : null,
22
+ mode: undefined, operation: write.after ? 'write' : 'delete' }));
23
+ const journal = path.join(backup, 'removal.json');
24
+ // No output is mutated until every preimage and the durable intent are saved.
25
+ try {
26
+ for (const [index, write] of writes.entries()) {
27
+ verifyPreimage(write);
28
+ if (write.before)
29
+ entries[index].mode = fs.statSync(write.path).mode;
30
+ if (write.before)
31
+ fs.writeFileSync(path.join(backup, `${index}`), write.before, { mode: 0o600 });
32
+ }
33
+ fs.writeFileSync(journal, JSON.stringify({ status: 'prepared', entries }, null, 2), { mode: 0o600 });
34
+ }
35
+ catch (error) {
36
+ fs.rmSync(backup, { recursive: true, force: true });
37
+ throw error;
38
+ }
39
+ const applied = [];
40
+ try {
41
+ for (const [index, write] of writes.entries()) {
42
+ if (write.commit)
43
+ continue;
44
+ verifyPreimage(write);
45
+ applied.push(index); // Also restore a write that throws after truncation.
46
+ if (write.after === null)
47
+ fs.unlinkSync(write.path);
48
+ else
49
+ fs.writeFileSync(write.path, write.after);
50
+ }
51
+ for (const [index, write] of writes.entries()) {
52
+ if (!write.commit)
53
+ continue;
54
+ verifyPreimage(write);
55
+ applied.push(index);
56
+ }
57
+ await commit?.();
58
+ }
59
+ catch (error) {
60
+ const failures = [];
61
+ for (const index of applied.reverse()) {
62
+ const write = writes[index];
63
+ try {
64
+ if (write.before === null) {
65
+ if (fs.existsSync(write.path))
66
+ fs.unlinkSync(write.path);
67
+ }
68
+ else {
69
+ fs.writeFileSync(write.path, write.before);
70
+ fs.chmodSync(write.path, entries[index].mode);
71
+ }
72
+ }
73
+ catch {
74
+ failures.push(write.path);
75
+ }
76
+ }
77
+ try {
78
+ fs.writeFileSync(journal, JSON.stringify({ status: failures.length ? 'rollback-incomplete' : 'rolled-back', entries, failures }, null, 2));
79
+ }
80
+ catch { /* The prepared intent and preimages remain available. */ }
81
+ throw new Error(`Removal failed: ${error instanceof Error ? error.message : String(error)}. ${failures.length
82
+ ? `Rollback incomplete for ${failures.join(', ')}.` : 'All changes rolled back.'} Recovery preimages and record: ${journal}`);
83
+ }
84
+ fs.rmSync(backup, { recursive: true, force: true });
85
+ }
86
+ //# sourceMappingURL=removal-transaction.js.map
@@ -0,0 +1,3 @@
1
+ export function stableSettings(value: unknown): string | undefined;
2
+ export function parseSettings(file: string, bytes: Buffer): Record<string, unknown>;
3
+ export function renderSettings(file: string, bytes: Buffer, value: Record<string, unknown>): Buffer;
@@ -0,0 +1,47 @@
1
+ // Parse provider settings and render safe semantic edits in their native format.
2
+ import { parseTOML, getStaticTOMLValue } from 'toml-eslint-parser';
3
+ import { parseDocument } from 'yaml';
4
+ import { parseJson } from '../mcp/json-document.mjs';
5
+
6
+ export const stableSettings = value => JSON.stringify(value, (_key, child) => child && typeof child === 'object' && !Array.isArray(child)
7
+ ? Object.fromEntries(Object.entries(child).sort(([a], [b]) => a.localeCompare(b))) : child);
8
+ export function parseSettings(file, bytes) {
9
+ const text = bytes.toString();
10
+ if (file.endsWith('.toml')) return getStaticTOMLValue(parseTOML(text));
11
+ if (/\.ya?ml$/.test(file)) {
12
+ const doc = parseDocument(text);
13
+ if (doc.errors.length) throw new Error('Invalid YAML settings');
14
+ return doc.toJS() ?? {};
15
+ }
16
+ return parseJson(text);
17
+ }
18
+ const tomlValue = value => {
19
+ if (value instanceof Date) return value.toISOString();
20
+ if (Array.isArray(value)) return `[${value.map(tomlValue).join(', ')}]`;
21
+ if (value && typeof value === 'object') return `{ ${Object.entries(value).map(([key, child]) => `${JSON.stringify(key)} = ${tomlValue(child)}`).join(', ')} }`;
22
+ if (value === null || value === undefined) throw new Error('Unrepresentable TOML value');
23
+ return JSON.stringify(value);
24
+ };
25
+ export function renderSettings(file, bytes, value) {
26
+ if (file.endsWith('.toml')) {
27
+ // Root inline tables are valid TOML and preserve arbitrary dotted keys.
28
+ const text = Object.entries(value).map(([key, child]) => `${JSON.stringify(key)} = ${tomlValue(child)}`).join('\n') + '\n';
29
+ if (stableSettings(parseSettings(file, Buffer.from(text))) !== stableSettings(value)) throw new Error('TOML settings round trip failed');
30
+ return Buffer.from(text);
31
+ }
32
+ if (/\.ya?ml$/.test(file)) {
33
+ const doc = parseDocument(bytes.toString());
34
+ const update = (before, after, keys = []) => {
35
+ for (const key of Object.keys(before || {})) if (!Object.hasOwn(after, key)) doc.deleteIn([...keys, key]);
36
+ for (const [key, child] of Object.entries(after)) {
37
+ const prior = before?.[key];
38
+ if (stableSettings(prior) === stableSettings(child)) continue;
39
+ if (prior && child && typeof prior === 'object' && typeof child === 'object' && !Array.isArray(prior) && !Array.isArray(child)) update(prior, child, [...keys, key]);
40
+ else doc.setIn([...keys, key], child);
41
+ }
42
+ };
43
+ update(doc.toJS(), value);
44
+ return Buffer.from(doc.toString());
45
+ }
46
+ return Buffer.from(`${JSON.stringify(value, null, 2)}\n`);
47
+ }
@@ -0,0 +1,190 @@
1
+ // Restore verified settings contributions while retaining unresolved ownership for retries.
2
+ import fs from 'node:fs';
3
+ import { createHash } from 'node:crypto';
4
+ import { parseSettings, renderSettings, stableSettings } from './settings-document.mjs';
5
+ const digest = (value) => `sha256:${createHash('sha256').update(stableSettings(value) ?? '').digest('hex')}`;
6
+ const object = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
7
+ const own = (value, key) => object(value) && Object.hasOwn(value, key);
8
+ function lookup(root, keys) {
9
+ let value = root;
10
+ for (const key of keys) {
11
+ if (!own(value, key))
12
+ return { present: false, value: undefined };
13
+ value = value[key];
14
+ }
15
+ return { present: true, value };
16
+ }
17
+ function assign(root, keys, present, value, baseline) {
18
+ let parent = root;
19
+ const parents = [];
20
+ for (const key of keys.slice(0, -1)) {
21
+ if (!own(parent, key) || !object(parent[key]))
22
+ throw new Error('Settings parent was edited');
23
+ parents.push([parent, key]);
24
+ parent = parent[key];
25
+ }
26
+ const key = keys.at(-1);
27
+ if (present)
28
+ Object.defineProperty(parent, key, { value, enumerable: true, configurable: true, writable: true });
29
+ else
30
+ delete parent[key];
31
+ for (let index = parents.length - 1; index >= 0; index--) {
32
+ const [container, name] = parents[index];
33
+ if (Object.keys(container[name]).length)
34
+ break;
35
+ const prior = lookup(baseline, keys.slice(0, index + 1));
36
+ if (prior.present) {
37
+ if (!object(prior.value))
38
+ container[name] = prior.value;
39
+ break;
40
+ }
41
+ delete container[name];
42
+ }
43
+ }
44
+ const contributions = (entry) => entry.contributions || [{ hash: entry.hash, value: entry.value, owners: entry.owners }];
45
+ export function restoreSettings(file, record, owner) {
46
+ const decisions = [];
47
+ const report = (pointer, action, reason) => decisions.push({
48
+ path: file, pointer, action, reason, kind: 'settings', owned: true,
49
+ });
50
+ let before, document;
51
+ try {
52
+ before = fs.readFileSync(file);
53
+ document = parseSettings(file, before);
54
+ if (!object(document))
55
+ throw new Error('Invalid settings document');
56
+ }
57
+ catch {
58
+ report('', 'preserve', 'missing, unreadable or invalid settings; unverifiable');
59
+ return { decisions, retained: true };
60
+ }
61
+ // Older receipts verify leaves, but cannot prove ownership of empty parents.
62
+ let baseline = parseSettings(file, before), original;
63
+ const preimage = record.settingsPreimage;
64
+ try {
65
+ if (preimage?.present === false) {
66
+ baseline = {};
67
+ original = null;
68
+ }
69
+ else if (preimage?.present && typeof preimage.bytes === 'string') {
70
+ const bytes = Buffer.from(preimage.bytes, 'base64');
71
+ if (`sha256:${createHash('sha256').update(bytes).digest('hex')}` === preimage.hash) {
72
+ const parsed = parseSettings(file, bytes);
73
+ if (object(parsed)) {
74
+ baseline = parsed;
75
+ original = bytes;
76
+ }
77
+ }
78
+ }
79
+ }
80
+ catch { /* Leaf preimages can still recover values without a byte preimage. */ }
81
+ if (!Object.keys(record.settings || {}).length && record.owners?.includes(owner)) {
82
+ const others = record.owners.filter(candidate => candidate !== owner);
83
+ const currentHash = `sha256:${createHash('sha256').update(before).digest('hex')}`;
84
+ if (currentHash !== record.hash || original === undefined || stableSettings(document) !== stableSettings(baseline)) {
85
+ report('', 'preserve', 'operator-edited or unverifiable settings bytes preserved');
86
+ return { decisions, retained: true };
87
+ }
88
+ record.owners = others;
89
+ report('', 'release', others.length ? 'shared settings formatting retained' : 'restore verified pre-deploy settings bytes');
90
+ return { decisions, retained: false, ...(!others.length && (original === null || !before.equals(original))
91
+ ? { write: { path: file, before, after: original } } : {}) };
92
+ }
93
+ let retained = false, changed = false;
94
+ for (const [pointer, entry] of Object.entries(record.settings || {})) {
95
+ if (!entry.owners?.includes(owner))
96
+ continue;
97
+ const keys = pointer.slice(1).split('/').map(key => key.replaceAll('~1', '/').replaceAll('~0', '~'));
98
+ const preserve = (reason) => { retained = true; report(pointer, 'preserve', reason); };
99
+ if (!pointer.startsWith('/') || keys.some(key => ['__proto__', 'constructor', 'prototype'].includes(key))
100
+ || entry.previous?.unverifiable || typeof entry.previous?.present !== 'boolean'
101
+ || entry.hash !== digest(entry.value)) {
102
+ preserve('unverifiable settings contribution or pre-deploy value');
103
+ continue;
104
+ }
105
+ const current = lookup(document, keys);
106
+ const items = contributions(entry);
107
+ if (items.some(item => !Array.isArray(item.owners) || item.hash !== digest(item.value))) {
108
+ preserve('unverifiable settings contribution digest');
109
+ continue;
110
+ }
111
+ const other = items.flatMap(item => {
112
+ const owners = item.owners.filter(candidate => candidate !== owner);
113
+ return owners.length ? [{ ...item, owners }] : [];
114
+ });
115
+ if (Array.isArray(entry.value)) {
116
+ if (!current.present || !Array.isArray(current.value)) {
117
+ preserve('operator-edited settings value preserved');
118
+ continue;
119
+ }
120
+ const value = [...current.value], expected = [...entry.value];
121
+ const unresolved = [];
122
+ for (const item of items.filter(item => item.owners.includes(owner) && item.owners.length === 1)) {
123
+ const index = value.findIndex(candidate => digest(candidate) === item.hash);
124
+ if (index < 0) {
125
+ unresolved.push(item);
126
+ continue;
127
+ }
128
+ value.splice(index, 1);
129
+ const expectedIndex = expected.findIndex(candidate => digest(candidate) === item.hash);
130
+ if (expectedIndex >= 0)
131
+ expected.splice(expectedIndex, 1);
132
+ }
133
+ const next = [...other, ...unresolved];
134
+ const restorePrevious = !next.length && digest(current.value) === entry.hash;
135
+ const restoredValue = restorePrevious && entry.previous.present ? entry.previous.value : value;
136
+ const present = restorePrevious ? entry.previous.present : value.length > 0 || entry.previous.present;
137
+ // Preserve an operator's replacement or deletion of a contributed hook.
138
+ if (unresolved.length)
139
+ preserve('operator-edited hook or array entry preserved; contribution retained for retry');
140
+ else
141
+ report(pointer, 'release', digest(current.value) !== entry.hash ? 'remove recorded entries; operator-edited array entries preserved'
142
+ : other.length ? 'shared settings entries retained; release this owner only' : 'restore pre-deploy hook or array entries');
143
+ if (stableSettings(restoredValue) !== stableSettings(current.value) || !present) {
144
+ assign(document, keys, present, restoredValue, baseline);
145
+ changed = true;
146
+ }
147
+ if (next.length) {
148
+ entry.contributions = next;
149
+ entry.owners = [...new Set(next.flatMap(item => item.owners))].sort();
150
+ entry.value = expected;
151
+ entry.hash = digest(expected);
152
+ }
153
+ else
154
+ delete record.settings[pointer];
155
+ }
156
+ else {
157
+ if (!current.present || digest(current.value) !== entry.hash) {
158
+ preserve('operator-edited settings value preserved');
159
+ continue;
160
+ }
161
+ const last = other.at(-1);
162
+ const present = !!last || entry.previous.present;
163
+ const value = last ? last.value : entry.previous.value;
164
+ assign(document, keys, present, value, baseline);
165
+ changed ||= !present || stableSettings(value) !== stableSettings(current.value);
166
+ report(pointer, 'release', last ? 'restore remaining framework settings value' : 'restore pre-deploy settings value');
167
+ if (last) {
168
+ entry.contributions = other;
169
+ entry.owners = [...new Set(other.flatMap(item => item.owners))].sort();
170
+ entry.value = value;
171
+ entry.hash = digest(value);
172
+ }
173
+ else
174
+ delete record.settings[pointer];
175
+ }
176
+ }
177
+ if (!decisions.length)
178
+ report('', 'release', 'no settings contributions remain for this framework');
179
+ record.owners = [...new Set(Object.values(record.settings || {}).flatMap(entry => entry.owners))].sort();
180
+ if (record.frameworkSlug === owner)
181
+ delete record.frameworkSlug;
182
+ let after = before;
183
+ if (changed) {
184
+ after = original !== undefined && `sha256:${createHash('sha256').update(before).digest('hex')}` === record.hash && stableSettings(document) === stableSettings(baseline) ? original
185
+ : renderSettings(file, before, document);
186
+ record.hash = after ? `sha256:${createHash('sha256').update(after).digest('hex')}` : record.hash;
187
+ }
188
+ return { decisions, retained, ...(after === null || !before.equals(after) ? { write: { path: file, before, after } } : {}) };
189
+ }
190
+ //# sourceMappingURL=settings-removal.js.map
@@ -1,6 +1,22 @@
1
+ export interface ArtifactOwnershipRecord {
2
+ hash: string;
3
+ owners?: string[];
4
+ frameworkSlug?: string;
5
+ source?: string;
6
+ sourcePath?: string;
7
+ version?: string;
8
+ kind?: string;
9
+ settings?: Record<string, SettingsOwnershipRecord>;
10
+ settingsPreimage?: { present: boolean; bytes?: string; hash?: string };
11
+ }
12
+ export interface SettingsContribution { hash: string; value: unknown; owners: string[] }
13
+ export interface SettingsOwnershipRecord extends SettingsContribution {
14
+ previous: { present?: boolean; value?: unknown; unverifiable?: boolean };
15
+ contributions?: SettingsContribution[];
16
+ }
1
17
  export interface SkillReceipt {
2
18
  skillSource?: string;
3
- managed?: Record<string, { hash: string; frameworkSlug?: string; source?: string; version?: string }>;
19
+ managed?: Record<string, ArtifactOwnershipRecord>;
4
20
  }
5
21
  export interface SkillRemovalPlanEntry {
6
22
  path: string;
@@ -13,6 +29,7 @@ export interface SkillRemovalOptions {
13
29
  }
14
30
  export function extractFrameworkSlug(source: string): string | null;
15
31
  export function sameSkillOwner(receipt: SkillReceipt | null, skillSource: string, frameworkSlug?: string | null): boolean;
16
- export function canDeploySkill(receipt: SkillReceipt | null, skillSource: string, opts?: { force?: boolean }): boolean;
32
+ export function canDeploySkill(receipt: SkillReceipt | null, skillSource: string, opts?: { force?: boolean; logicalInputPath?: (file: string) => string }): boolean;
17
33
  export function pruneRecordedSkillFiles(skillDir: string, managed: SkillReceipt['managed'], desired: Set<string>, opts?: SkillRemovalOptions): void;
18
34
  export function releaseSkillOwnership(skillDir: string, owner: { frameworkSlug?: string; skillSource?: string; sourceRoot?: string }, opts?: SkillRemovalOptions): boolean | null;
35
+ export function mergeArtifactOwnership<T extends ArtifactOwnershipRecord>(previous: ArtifactOwnershipRecord | undefined, current: T, owner: string): T & { owners: string[] };
@@ -27,11 +27,13 @@ export function sameSkillOwner(receipt, skillSource, frameworkSlug = extractFram
27
27
  }
28
28
 
29
29
  /** Frameworks outrank addons; peers retain ownership unless explicitly forced. */
30
- export function canDeploySkill(receipt, skillSource, { force = false } = {}) {
30
+ export function canDeploySkill(receipt, skillSource, { force = false, logicalInputPath } = {}) {
31
31
  const owner = receipt?.managed?.['SKILL.md']?.frameworkSlug || receipt?.skillSource;
32
- if (!owner || sameSkillOwner(receipt, skillSource)) return true;
33
- const incoming = extractFrameworkSlug(`${skillSource}/SKILL.md`) || skillSource;
34
- const isFramework = /(?:^|\/)agentic\/code\/frameworks\//.test(skillSource.replace(/\\/g, '/'));
32
+ const logicalSource = logicalInputPath?.(skillSource) || skillSource;
33
+ const incomingSlug = extractFrameworkSlug(`${logicalSource}/SKILL.md`);
34
+ if (!owner || sameSkillOwner(receipt, skillSource, incomingSlug)) return true;
35
+ const incoming = incomingSlug || skillSource;
36
+ const isFramework = /(?:^|\/)agentic\/code\/frameworks\//.test(logicalSource.replace(/\\/g, '/'));
35
37
  const wasAddon = /(?:^|\/)agentic\/code\/addons\//.test((receipt.skillSource || '').replace(/\\/g, '/'));
36
38
  const replace = force || (isFramework && wasAddon);
37
39
  console.warn(`Skill deploy collision: '${path.basename(skillSource)}' is owned by ${owner}; ${incoming} ${replace ? 'taking ownership' : 'skipped'}`);
@@ -104,3 +106,9 @@ export function releaseSkillOwnership(skillDir, owner, opts = {}) {
104
106
  if (opts.dryRun) return false;
105
107
  try { fs.rmdirSync(skillDir); return true; } catch { return false; }
106
108
  }
109
+
110
+ /** Deploy adds owners; only explicit removal may release a recorded owner. */
111
+ export function mergeArtifactOwnership(previous, current, owner) {
112
+ const owners = previous?.owners || [];
113
+ return { ...(previous?.hash === current.hash ? previous : {}), ...current, owners: [...new Set([...owners, ...(current.owners || []), owner])].sort() };
114
+ }