@aiwg/cli 2026.10.12 → 2026.10.15

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 (104) hide show
  1. package/agentic/code/addons/aiwg-utils/rules/anti-laziness.core.md +13 -0
  2. package/agentic/code/addons/aiwg-utils/rules/anti-laziness.md +118 -0
  3. package/agentic/code/providers/pi/aiwg-bridge.ts +44 -1
  4. package/dist/src/artifacts/corpus-tools/cli.js +32 -0
  5. package/dist/src/artifacts/corpus-tools/discovery-log.js +1 -1
  6. package/dist/src/artifacts/corpus-tools/expand-cli.js +89 -0
  7. package/dist/src/artifacts/corpus-tools/expand-queue.js +38 -0
  8. package/dist/src/artifacts/corpus-tools/expand-state.js +40 -0
  9. package/dist/src/artifacts/corpus-tools/expand.js +125 -0
  10. package/dist/src/artifacts/corpus-tools/resolve-cli.js +91 -0
  11. package/dist/src/artifacts/corpus-tools/resolve-corpus.js +41 -0
  12. package/dist/src/artifacts/corpus-tools/resolve.js +105 -0
  13. package/dist/src/cli/handlers/doctor-args.js +40 -0
  14. package/dist/src/cli/handlers/doctor-help.js +4 -2
  15. package/dist/src/cli/handlers/use-bundle-counts.js +32 -6
  16. package/dist/src/cli/handlers/use-skill-assets.js +207 -0
  17. package/dist/src/cli/handlers/use.js +30 -193
  18. package/dist/src/cli/handlers/utilities.js +5 -31
  19. package/dist/src/config/authorization-cli.js +11 -3
  20. package/dist/src/config/worker-context.js +33 -4
  21. package/dist/src/decision/context-pruning-common.js +41 -0
  22. package/dist/src/decision/context-pruning-evaluation.js +366 -0
  23. package/dist/src/decision/context-pruning-pilot.js +431 -0
  24. package/dist/src/decision/context-pruning-types.js +19 -0
  25. package/dist/src/decision/context-pruning.js +5 -847
  26. package/dist/src/decision/ensemble/contract.js +4 -24
  27. package/dist/src/decision/heldout/collector.js +1 -1
  28. package/dist/src/decision/qualification/release.js +5 -62
  29. package/dist/src/extensions/manifest.js +8 -1
  30. package/dist/src/extensions/project-local-doctor.js +78 -2
  31. package/dist/src/extensions/validation.js +10 -11
  32. package/dist/src/features/catalog.js +1 -1
  33. package/dist/src/gates/evaluate.js +5 -15
  34. package/dist/src/gates/heldout.js +42 -0
  35. package/dist/src/gates/index.js +2 -1
  36. package/dist/src/gates/upstream-ceiling.js +111 -0
  37. package/dist/src/models/provider-models.js +5 -8
  38. package/dist/src/models/worker-installation-store.mjs +228 -0
  39. package/dist/src/models/worker-installation.mjs +7 -162
  40. package/dist/src/models/wrapper-definitions.js +14 -0
  41. package/dist/src/models/wrapper-deployment.js +48 -25
  42. package/dist/src/models/wrapper-enforcement.js +72 -0
  43. package/dist/src/policy/hitl-check.js +80 -0
  44. package/dist/src/providers/provider-definitions.js +10 -10
  45. package/dist/src/research/clients/arxiv.js +10 -4
  46. package/dist/src/research/clients/base.js +5 -4
  47. package/dist/src/research/clients/crossref.js +9 -1
  48. package/dist/src/research/clients/semantic-scholar.js +73 -44
  49. package/dist/src/research/identity.js +85 -0
  50. package/dist/src/research/index.js +1 -0
  51. package/dist/src/research/reference-match.js +89 -0
  52. package/dist/src/rules/activation.d.mts +2 -0
  53. package/dist/src/rules/activation.mjs +23 -0
  54. package/dist/src/rules/core-startup.d.mts +2 -0
  55. package/dist/src/rules/core-startup.mjs +31 -0
  56. package/dist/src/skills/adapters/local.js +32 -9
  57. package/dist/src/skills/agent-skills.js +2 -0
  58. package/dist/src/skills/cli-display.js +33 -0
  59. package/dist/src/skills/cli.js +2 -26
  60. package/dist/src/skills/collision-discovery.js +84 -0
  61. package/dist/src/skills/deployer.js +20 -75
  62. package/dist/src/skills/deployment-ownership.js +74 -0
  63. package/dist/src/skills/doctor.js +2 -2
  64. package/dist/src/skills/importer.js +4 -26
  65. package/dist/src/skills/registry.js +22 -7
  66. package/dist/src/smiths/context-pipeline/agents-md.js +34 -0
  67. package/dist/src/smiths/context-pipeline/aiwg-md.js +3 -0
  68. package/dist/src/smiths/context-pipeline/bridge-ownership.js +50 -0
  69. package/dist/src/smiths/context-pipeline/generator.js +40 -104
  70. package/dist/src/smiths/context-pipeline/managed-hook.js +10 -0
  71. package/dist/src/smiths/context-pipeline/parallelism-section.js +7 -3
  72. package/package.json +6 -2
  73. package/tools/agents/deploy-agents.mjs +2 -123
  74. package/tools/agents/providers/antigravity.mjs +4 -6
  75. package/tools/agents/providers/base.mjs +3 -3
  76. package/tools/agents/providers/claude.mjs +3 -5
  77. package/tools/agents/providers/codex.mjs +3 -5
  78. package/tools/agents/providers/context-write.mjs +12 -0
  79. package/tools/agents/providers/copilot.mjs +3 -5
  80. package/tools/agents/providers/cursor.mjs +3 -5
  81. package/tools/agents/providers/factory.mjs +3 -5
  82. package/tools/agents/providers/grok-build.mjs +17 -12
  83. package/tools/agents/providers/hermes-skill-lifecycle.mjs +144 -0
  84. package/tools/agents/providers/hermes-startup.mjs +209 -0
  85. package/tools/agents/providers/hermes.mjs +9 -359
  86. package/tools/agents/providers/model-wrapper.mjs +90 -0
  87. package/tools/agents/providers/muse.mjs +3 -3
  88. package/tools/agents/providers/omp.mjs +3 -1
  89. package/tools/agents/providers/openclaw.mjs +3 -5
  90. package/tools/agents/providers/opencode.mjs +3 -5
  91. package/tools/agents/providers/pi.mjs +1 -1
  92. package/tools/agents/providers/provider-paths-staging.mjs +9 -0
  93. package/tools/agents/providers/rule-delivery.mjs +26 -228
  94. package/tools/agents/providers/rule-presentation.mjs +13 -4
  95. package/tools/agents/providers/rule-projection.mjs +119 -0
  96. package/tools/agents/providers/rule-startup.mjs +70 -0
  97. package/tools/agents/providers/stale-artifact-prune.mjs +128 -0
  98. package/tools/agents/providers/warp.mjs +5 -7
  99. package/tools/agents/providers/windsurf.mjs +14 -62
  100. package/tools/plugin/package-plugins.mjs +2 -2
  101. package/tools/plugin/plugin-links.mjs +3 -0
  102. package/tools/skills/codex-skill-transform.mjs +232 -0
  103. package/tools/skills/deploy-skills-codex.mjs +8 -249
  104. package/tools/warp/warp-content.mjs +548 -0
@@ -0,0 +1,228 @@
1
+ // Own trusted approval-store I/O, locking, pruning, and explicit approval management.
2
+ import { constants } from 'node:fs';
3
+ import { open, realpath, lstat, stat, mkdir, rename, writeFile, unlink } from 'node:fs/promises';
4
+ import path from 'node:path';
5
+ import { homedir } from 'node:os';
6
+ import { createHash } from 'node:crypto';
7
+ const installedModuleMaxBytes = 5 * 1024 * 1024;
8
+
9
+ // Resolve existing ancestors too: a not-yet-created output can traverse a symlink.
10
+ export async function canonicalFuturePath(filename) {
11
+ try { return await realpath(filename); }
12
+ catch (error) {
13
+ if (error.code !== 'ENOENT') throw error;
14
+ // A dangling link is not a new output: following it may leave the scope.
15
+ try { if ((await lstat(filename)).isSymbolicLink()) throw new Error('Dangling worker path'); }
16
+ catch (statError) { if (statError.code !== 'ENOENT') throw statError; }
17
+ const parent = path.dirname(filename);
18
+ if (parent === filename) throw error;
19
+ return path.join(await canonicalFuturePath(parent), path.basename(filename));
20
+ }
21
+ }
22
+
23
+ export function inside(root, target) {
24
+ const relative = path.relative(root, target);
25
+ return relative === '' || (!relative.startsWith(`..${path.sep}`) && relative !== '..' && !path.isAbsolute(relative));
26
+ }
27
+
28
+ export async function readInstalledFile(filename) {
29
+ const file = await open(filename, 'r');
30
+ try {
31
+ const stat = await file.stat();
32
+ if (!stat.isFile()) throw new Error('Installed module inputs must be regular files');
33
+ if (stat.size > installedModuleMaxBytes) throw new Error('Installed module input exceeds maxBytes (5 MiB)');
34
+ // Bound the actual read too: an fstat size check alone allows concurrent growth.
35
+ const bytes = Buffer.alloc(installedModuleMaxBytes + 1);
36
+ let length = 0;
37
+ while (length < bytes.length) {
38
+ const { bytesRead } = await file.read(bytes, length, bytes.length - length, null);
39
+ if (!bytesRead) break;
40
+ length += bytesRead;
41
+ }
42
+ if (length > installedModuleMaxBytes) throw new Error('Installed module input exceeds maxBytes (5 MiB)');
43
+ return bytes.subarray(0, length);
44
+ } finally {
45
+ await file.close();
46
+ }
47
+ }
48
+
49
+ export function installationStorePath() {
50
+ const root = process.env.AIWG_CONFIG || path.join(homedir(), '.config/aiwg');
51
+ if (!path.isAbsolute(root)) throw new Error('Installation store must be absolute');
52
+ return path.join(root, 'worker-installations.json');
53
+ }
54
+
55
+ // HOME is the operator's trust boundary; custom stores outside it are checked
56
+ // back to /. O_NOFOLLOW on the store itself does not protect its ancestors.
57
+ export async function assertTrustedStoreAncestors(directory) {
58
+ const home = path.resolve(homedir());
59
+ const boundary = inside(home, directory) ? home : path.parse(directory).root;
60
+ // The store directory itself is checked by the caller.
61
+ if (directory === boundary) return;
62
+ const ancestors = [];
63
+ for (let target = path.dirname(directory); ; target = path.dirname(target)) {
64
+ ancestors.push(target);
65
+ if (target === boundary) break;
66
+ }
67
+ for (const target of ancestors.reverse()) {
68
+ const stat = await lstat(target);
69
+ if (!stat.isDirectory() || stat.isSymbolicLink() || stat.mode & 0o022
70
+ || process.getuid && stat.uid !== 0 && stat.uid !== process.getuid()) {
71
+ throw new Error(`Untrusted installation store ancestor: ${target}`);
72
+ }
73
+ }
74
+ }
75
+
76
+ export async function assertTrustedStore(filename, writableRoots, repairDirectory = false, apply = false) {
77
+ const changes = [];
78
+ const canonical = await canonicalFuturePath(filename);
79
+ if (canonical !== filename) throw new Error('Symlinked installation store');
80
+ for (const root of writableRoots) {
81
+ if (inside(await realpath(root), canonical)) throw new Error('Worker-writable installation store');
82
+ }
83
+ for (const target of [path.dirname(filename), filename]) {
84
+ try {
85
+ const stat = await lstat(target);
86
+ if (process.getuid && stat.uid !== process.getuid()) throw new Error(`Installation store path is owned by another user: ${target}`);
87
+ if (stat.isSymbolicLink() || stat.isFile() && stat.nlink !== 1
88
+ || target === path.dirname(filename) && !stat.isDirectory()
89
+ || target === filename && !stat.isFile()) throw new Error(`Untrusted installation store permissions: ${target}`);
90
+ if (stat.mode & 0o022) {
91
+ if (!repairDirectory || target !== path.dirname(filename) || !process.getuid) {
92
+ throw new Error(`Untrusted installation store permissions: ${target}`);
93
+ }
94
+ await assertTrustedStoreAncestors(target);
95
+ changes.push({ path: target, action: 'chmod go-w' });
96
+ if (apply) {
97
+ const handle = await open(target, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_DIRECTORY);
98
+ try {
99
+ const current = await handle.stat();
100
+ if (current.uid !== process.getuid() || current.ino !== stat.ino || current.dev !== stat.dev) {
101
+ throw new Error(`Installation store directory changed: ${target}`);
102
+ }
103
+ await handle.chmod(current.mode & ~0o022);
104
+ } finally { await handle.close(); }
105
+ }
106
+ }
107
+ } catch (error) { if (error.code !== 'ENOENT') throw error; }
108
+ }
109
+ return changes;
110
+ }
111
+
112
+ /** Qualification's confirmed write may secure its own directory; ordinary readers never repair. */
113
+ export async function prepareWorkerInstallationStore({ workerWritableRoots, apply = false }) {
114
+ return assertTrustedStore(installationStorePath(), workerWritableRoots, true, apply);
115
+ }
116
+
117
+ export async function readInstallationStore(filename, expectedDigest) {
118
+ try {
119
+ const bytes = await readInstalledFile(filename);
120
+ const digest = `sha256:${createHash('sha256').update(bytes).digest('hex')}`;
121
+ if (expectedDigest !== undefined && digest !== expectedDigest) throw new Error('Installation store binding changed');
122
+ const stored = JSON.parse(bytes.toString('utf8'));
123
+ if (stored.version !== 1 || !Array.isArray(stored.registrations) || stored.registrations.length > 128) {
124
+ throw new Error('Unsupported installation record');
125
+ }
126
+ return { stored, digest };
127
+ } catch (error) {
128
+ if (error.code === 'ENOENT' && expectedDigest === undefined) return { stored: { version: 1, registrations: [] }, digest: null };
129
+ throw error;
130
+ }
131
+ }
132
+
133
+ // Serialize readers and writers; a stale lock fails closed and is never stolen.
134
+ export async function withWorkerInstallationStore(writableRoots, operation) {
135
+ const filename = installationStorePath();
136
+ await assertTrustedStore(filename, writableRoots);
137
+ await mkdir(path.dirname(filename), { recursive: true, mode: 0o700 });
138
+ const lockPath = `${filename}.lock`;
139
+ let lock;
140
+ for (let attempt = 0; attempt < 100; attempt++) {
141
+ try { lock = await open(lockPath, 'wx', 0o600); break; }
142
+ catch (error) {
143
+ if (error.code !== 'EEXIST' || attempt === 99) throw error;
144
+ await new Promise(resolve => setTimeout(resolve, 20));
145
+ }
146
+ }
147
+ try {
148
+ await assertTrustedStore(filename, writableRoots);
149
+ const { stored } = await readInstallationStore(filename);
150
+ return await operation({ filename, stored });
151
+ } finally {
152
+ await lock.close();
153
+ await unlink(lockPath);
154
+ }
155
+ }
156
+
157
+ export async function writeWorkerInstallationStore(filename, stored, writableRoots) {
158
+ await assertTrustedStore(filename, writableRoots);
159
+ const temporary = `${filename}.${process.pid}.${createHash('sha256').update(String(Math.random())).digest('hex')}.tmp`;
160
+ try {
161
+ await writeFile(temporary, `${JSON.stringify(stored, null, 2)}\n`, { mode: 0o600, flag: 'wx' });
162
+ await rename(temporary, filename);
163
+ } finally {
164
+ await unlink(temporary).catch(error => { if (error.code !== 'ENOENT') throw error; });
165
+ }
166
+ }
167
+
168
+ async function workspaceIdentity(workspace) {
169
+ if (typeof workspace !== 'string' || !path.isAbsolute(workspace)) return workspace;
170
+ try { return await realpath(workspace); }
171
+ catch (error) {
172
+ if (error.code !== 'ENOENT' && error.code !== 'ENOTDIR') throw error;
173
+ return path.resolve(workspace);
174
+ }
175
+ }
176
+
177
+ async function workspaceDeleted(workspace) {
178
+ if (typeof workspace !== 'string' || !path.isAbsolute(workspace)) return false;
179
+ try { return !(await stat(workspace)).isDirectory(); }
180
+ catch (error) {
181
+ // Permission and I/O failures do not establish that a workspace was deleted.
182
+ return error.code === 'ENOENT' || error.code === 'ENOTDIR';
183
+ }
184
+ }
185
+
186
+ export async function retainWorkerApprovals(registrations, record) {
187
+ const retained = [];
188
+ for (const entry of registrations) {
189
+ if (await workspaceDeleted(entry.installation?.cwd)) continue;
190
+ const workspace = await workspaceIdentity(entry.installation?.cwd).catch(() => entry.installation?.cwd);
191
+ if (entry.cli !== record.cli || workspace !== record.installation.cwd) retained.push(entry);
192
+ }
193
+ if (retained.length >= 128) throw new Error('Worker installation store is full (128 workspace approvals); run aiwg doctor --probe-workers --forget-approval <workspace-path> [--cli <name>] --yes before qualifying another workspace');
194
+ return [...retained, record];
195
+ }
196
+
197
+ /** Offline inventory of recorded authority; never load a driver or validate launch eligibility. */
198
+ export async function listWorkerApprovals({ cwd, cli }) {
199
+ return withWorkerInstallationStore([cwd], async ({ stored }) => {
200
+ const approvals = [];
201
+ for (const entry of stored.registrations) {
202
+ if (cli && entry.cli !== cli) continue;
203
+ approvals.push({ cli: entry.cli, workspace: entry.installation?.cwd ?? null,
204
+ workspaceExists: !(await workspaceDeleted(entry.installation?.cwd)) });
205
+ }
206
+ return approvals;
207
+ });
208
+ }
209
+
210
+ /** Explicit revocation by exact canonical workspace, including workspaces already deleted. */
211
+ export async function forgetWorkerApproval({ cwd, workspace, cli, yes }) {
212
+ if (yes !== true) throw new Error('Forgetting worker approvals requires --yes');
213
+ const target = await workspaceIdentity(path.resolve(cwd, workspace));
214
+ return withWorkerInstallationStore([cwd], async ({ filename, stored }) => {
215
+ const removed = [];
216
+ const retained = [];
217
+ for (const entry of stored.registrations) {
218
+ const identity = await workspaceIdentity(entry.installation?.cwd);
219
+ if (identity === target && (!cli || entry.cli === cli)) {
220
+ removed.push({ cli: entry.cli, workspace: entry.installation.cwd });
221
+ } else retained.push(entry);
222
+ }
223
+ if (!removed.length) throw new Error(`No worker approval found for ${target}${cli ? ` (CLI ${cli})` : ''}`);
224
+ stored.registrations = retained;
225
+ await writeWorkerInstallationStore(filename, stored, [cwd]);
226
+ return removed;
227
+ });
228
+ }
@@ -1,10 +1,10 @@
1
+ import { canonicalFuturePath, inside, readInstalledFile, installationStorePath, assertTrustedStore, readInstallationStore, withWorkerInstallationStore, writeWorkerInstallationStore, retainWorkerApprovals } from './worker-installation-store.mjs';
2
+ export { prepareWorkerInstallationStore } from './worker-installation-store.mjs';
1
3
  /** Shared installed-worker qualification owner, also used by the Ralph compatibility facade. */
2
4
  import { spawn } from 'node:child_process';
3
5
  import { buildInstalledWorkerTransport } from './worker-artifact-binding.mjs';
4
- import { constants } from 'node:fs';
5
- import { open, realpath, lstat, mkdir, rename, writeFile, unlink } from 'node:fs/promises';
6
+ import { open, realpath, lstat } from 'node:fs/promises';
6
7
  import path from 'node:path';
7
- import { homedir } from 'node:os';
8
8
  import { pathToFileURL } from 'node:url';
9
9
  import { createHash } from 'node:crypto';
10
10
  import { parse } from 'acorn';
@@ -225,7 +225,6 @@ const providerRegistry = new Map();
225
225
  const installedModules = new Map();
226
226
  let installedLoad = Promise.resolve();
227
227
  // Same default byte ceiling as workerAdapter.catalogAdapter.maxBytes.
228
- const installedModuleMaxBytes = 5 * 1024 * 1024;
229
228
 
230
229
  async function binaryIdentity(filename, workerWritableRoots) {
231
230
  if (typeof filename !== 'string' || !path.isAbsolute(filename) || filename.includes('\0')) throw new Error('Absolute installed binary required');
@@ -254,20 +253,6 @@ async function binaryIdentity(filename, workerWritableRoots) {
254
253
  } finally { await handle.close(); }
255
254
  }
256
255
 
257
- // Resolve existing ancestors too: a not-yet-created output can traverse a symlink.
258
- async function canonicalFuturePath(filename) {
259
- try { return await realpath(filename); }
260
- catch (error) {
261
- if (error.code !== 'ENOENT') throw error;
262
- // A dangling link is not a new output: following it may leave the scope.
263
- try { if ((await lstat(filename)).isSymbolicLink()) throw new Error('Dangling worker path'); }
264
- catch (statError) { if (statError.code !== 'ENOENT') throw statError; }
265
- const parent = path.dirname(filename);
266
- if (parent === filename) throw error;
267
- return path.join(await canonicalFuturePath(parent), path.basename(filename));
268
- }
269
- }
270
-
271
256
  export async function inspectWorkerInstallation(instance, request) {
272
257
  const { inspectWorkerInvocationProfile, requiredWorkerControls, isOperatorQualifiedWorkerAdapter } = await import('./provider-policy.js');
273
258
  const { qualificationDigest } = await import('./qualification-digest.mjs');
@@ -504,11 +489,6 @@ function runBoundedVersionProbe(executable, argv, environment, cwd, timeoutMs, m
504
489
  });
505
490
  }
506
491
 
507
- function inside(root, target) {
508
- const relative = path.relative(root, target);
509
- return relative === '' || (!relative.startsWith(`..${path.sep}`) && relative !== '..' && !path.isAbsolute(relative));
510
- }
511
-
512
492
  // Inspect syntax without executing module bodies (including top-level effects).
513
493
  // Only statically declared interfaceVersion and callable register exports qualify.
514
494
  function checkInstalledExports(source) {
@@ -559,27 +539,6 @@ function checkInstalledExports(source) {
559
539
  inspect(ast);
560
540
  }
561
541
 
562
- async function readInstalledFile(filename) {
563
- const file = await open(filename, 'r');
564
- try {
565
- const stat = await file.stat();
566
- if (!stat.isFile()) throw new Error('Installed module inputs must be regular files');
567
- if (stat.size > installedModuleMaxBytes) throw new Error('Installed module input exceeds maxBytes (5 MiB)');
568
- // Bound the actual read too: an fstat size check alone allows concurrent growth.
569
- const bytes = Buffer.alloc(installedModuleMaxBytes + 1);
570
- let length = 0;
571
- while (length < bytes.length) {
572
- const { bytesRead } = await file.read(bytes, length, bytes.length - length, null);
573
- if (!bytesRead) break;
574
- length += bytesRead;
575
- }
576
- if (length > installedModuleMaxBytes) throw new Error('Installed module input exceeds maxBytes (5 MiB)');
577
- return bytes.subarray(0, length);
578
- } finally {
579
- await file.close();
580
- }
581
- }
582
-
583
542
  async function inspectInstalledModule(entry, workerWritableRoots, platform) {
584
543
  if (!entry || !/^installed:[a-z][a-z0-9-]{0,62}$/.test(entry.reference)
585
544
  || typeof entry.packageName !== 'string' || !entry.packageName
@@ -757,74 +716,6 @@ export function hasProvider(name) {
757
716
 
758
717
  // This host-owned record extends the installation owner. It is not project
759
718
  // configuration and never accepts module locations from models.json/aiwg.config.
760
- function installationStorePath() {
761
- const root = process.env.AIWG_CONFIG || path.join(homedir(), '.config/aiwg');
762
- if (!path.isAbsolute(root)) throw new Error('Installation store must be absolute');
763
- return path.join(root, 'worker-installations.json');
764
- }
765
-
766
- // HOME is the operator's trust boundary; custom stores outside it are checked
767
- // back to /. O_NOFOLLOW on the store itself does not protect its ancestors.
768
- async function assertTrustedStoreAncestors(directory) {
769
- const home = path.resolve(homedir());
770
- const boundary = inside(home, directory) ? home : path.parse(directory).root;
771
- // The store directory itself is checked by the caller.
772
- if (directory === boundary) return;
773
- const ancestors = [];
774
- for (let target = path.dirname(directory); ; target = path.dirname(target)) {
775
- ancestors.push(target);
776
- if (target === boundary) break;
777
- }
778
- for (const target of ancestors.reverse()) {
779
- const stat = await lstat(target);
780
- if (!stat.isDirectory() || stat.isSymbolicLink() || stat.mode & 0o022
781
- || process.getuid && stat.uid !== 0 && stat.uid !== process.getuid()) {
782
- throw new Error(`Untrusted installation store ancestor: ${target}`);
783
- }
784
- }
785
- }
786
-
787
- async function assertTrustedStore(filename, writableRoots, repairDirectory = false, apply = false) {
788
- const changes = [];
789
- const canonical = await canonicalFuturePath(filename);
790
- if (canonical !== filename) throw new Error('Symlinked installation store');
791
- for (const root of writableRoots) {
792
- if (inside(await realpath(root), canonical)) throw new Error('Worker-writable installation store');
793
- }
794
- for (const target of [path.dirname(filename), filename]) {
795
- try {
796
- const stat = await lstat(target);
797
- if (process.getuid && stat.uid !== process.getuid()) throw new Error(`Installation store path is owned by another user: ${target}`);
798
- if (stat.isSymbolicLink() || stat.isFile() && stat.nlink !== 1
799
- || target === path.dirname(filename) && !stat.isDirectory()
800
- || target === filename && !stat.isFile()) throw new Error(`Untrusted installation store permissions: ${target}`);
801
- if (stat.mode & 0o022) {
802
- if (!repairDirectory || target !== path.dirname(filename) || !process.getuid) {
803
- throw new Error(`Untrusted installation store permissions: ${target}`);
804
- }
805
- await assertTrustedStoreAncestors(target);
806
- changes.push({ path: target, action: 'chmod go-w' });
807
- if (apply) {
808
- const handle = await open(target, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_DIRECTORY);
809
- try {
810
- const current = await handle.stat();
811
- if (current.uid !== process.getuid() || current.ino !== stat.ino || current.dev !== stat.dev) {
812
- throw new Error(`Installation store directory changed: ${target}`);
813
- }
814
- await handle.chmod(current.mode & ~0o022);
815
- } finally { await handle.close(); }
816
- }
817
- }
818
- } catch (error) { if (error.code !== 'ENOENT') throw error; }
819
- }
820
- return changes;
821
- }
822
-
823
- /** Qualification's confirmed write may secure its own directory; ordinary readers never repair. */
824
- export async function prepareWorkerInstallationStore({ workerWritableRoots, apply = false }) {
825
- return assertTrustedStore(installationStorePath(), workerWritableRoots, true, apply);
826
- }
827
-
828
719
  // Use the existing delivery ledger's host-selected keyring, never public keys
829
720
  // supplied by a registration. PAE separates this authority from effect records.
830
721
  const qualificationPayloadType = 'application/vnd.aiwg.worker-installation-qualification+json';
@@ -859,22 +750,6 @@ async function qualificationSignatureFailure(record, trust) {
859
750
  return result === 'ok' ? null : result === 'signature-invalid' ? result : `signature-${result}`;
860
751
  }
861
752
 
862
- async function readInstallationStore(filename, expectedDigest) {
863
- try {
864
- const bytes = await readInstalledFile(filename);
865
- const digest = `sha256:${createHash('sha256').update(bytes).digest('hex')}`;
866
- if (expectedDigest !== undefined && digest !== expectedDigest) throw new Error('Installation store binding changed');
867
- const stored = JSON.parse(bytes.toString('utf8'));
868
- if (stored.version !== 1 || !Array.isArray(stored.registrations) || stored.registrations.length > 128) {
869
- throw new Error('Unsupported installation record');
870
- }
871
- return { stored, digest };
872
- } catch (error) {
873
- if (error.code === 'ENOENT' && expectedDigest === undefined) return { stored: { version: 1, registrations: [] }, digest: null };
874
- throw error;
875
- }
876
- }
877
-
878
753
  /** Offline projection of recorded approvals only. Never imports drivers, reads auth, or probes CLIs.
879
754
  * This is historical evidence, not current launch authority; loadRecordedWorkerInstallations
880
755
  * performs binary/version/scope checks when dispatch actually requests a binding.
@@ -935,21 +810,7 @@ export async function recordWorkerInstallation(instance, options) {
935
810
  await assertTrustedStore(filename, installation.workerWritableRoots);
936
811
  // Canonical workspace identity is an exact approval key, never a prefix.
937
812
  installation.cwd = await realpath(installation.cwd);
938
- await mkdir(path.dirname(filename), { recursive: true, mode: 0o700 });
939
- // Serialize read/modify/rename across qualifying CLI processes. A stale lock
940
- // fails closed; qualification never steals another process's lock.
941
- const lockPath = `${filename}.lock`;
942
- let lock;
943
- for (let attempt = 0; attempt < 100; attempt++) {
944
- try { lock = await open(lockPath, 'wx', 0o600); break; }
945
- catch (error) {
946
- if (error.code !== 'EEXIST' || attempt === 99) throw error;
947
- await new Promise(resolve => setTimeout(resolve, 20));
948
- }
949
- }
950
- try {
951
- await assertTrustedStore(filename, installation.workerWritableRoots);
952
- const { stored } = await readInstallationStore(filename);
813
+ return withWorkerInstallationStore(installation.workerWritableRoots, async ({ stored }) => {
953
814
  const environmentNames = Object.keys(installation.environment ?? {});
954
815
  delete installation.environment;
955
816
  delete installation.adapter;
@@ -966,26 +827,10 @@ export async function recordWorkerInstallation(instance, options) {
966
827
  if (checkSignature(keyring, signingKey.keyid, sig, qualificationPayloadType, payload, signedAt) !== 'ok') throw new Error('invalid signature');
967
828
  record.signature = { keyid: signingKey.keyid, sig, signedAt, projectDir: signingProjectDir, scope: keyring.scope };
968
829
  } catch { return { status: 'DISABLED', reason: keyRecoveryMessage }; }
969
- const retained = [];
970
- for (const entry of stored.registrations) {
971
- const workspace = typeof entry.installation?.cwd === 'string'
972
- ? await realpath(entry.installation.cwd).catch(() => entry.installation.cwd) : null;
973
- if (entry.cli !== cli || workspace !== installation.cwd) retained.push(entry);
974
- }
975
- // Bound host authority without silently evicting another workspace approval.
976
- if (retained.length >= 128) throw new Error('Worker installation store is full (128 workspace approvals); remove an obsolete approval before qualifying another workspace');
977
- stored.registrations = retained;
978
- stored.registrations.push(record);
979
- await mkdir(path.dirname(filename), { recursive: true, mode: 0o700 });
980
- await assertTrustedStore(filename, installation.workerWritableRoots);
981
- const temporary = `${filename}.${process.pid}.${createHash('sha256').update(String(Math.random())).digest('hex')}.tmp`;
982
- await writeFile(temporary, `${JSON.stringify(stored, null, 2)}\n`, { mode: 0o600, flag: 'wx' });
983
- await rename(temporary, filename);
830
+ stored.registrations = await retainWorkerApprovals(stored.registrations, record);
831
+ await writeWorkerInstallationStore(filename, stored, installation.workerWritableRoots);
984
832
  return result;
985
- } finally {
986
- await lock.close();
987
- await unlink(lockPath);
988
- }
833
+ });
989
834
  }
990
835
 
991
836
  /** Read recorded host authority, validate installation bytes and the current CLI
@@ -0,0 +1,14 @@
1
+ // Canonical wrapper identities reuse the three catalog roles and their existing tiers.
2
+ export const MODEL_WRAPPERS = {
3
+ reasoning: 'aiwg-model-reasoning-worker',
4
+ coding: 'aiwg-model-coding-worker',
5
+ efficiency: 'aiwg-model-efficiency-worker',
6
+ };
7
+ export const MODEL_WRAPPER_DEFINITIONS = [
8
+ { name: MODEL_WRAPPERS.reasoning, role: 'reasoning', tier: 'premium', effort: 'high', readOnly: false },
9
+ { name: MODEL_WRAPPERS.coding, role: 'coding', tier: 'standard', effort: 'medium', readOnly: false },
10
+ { name: MODEL_WRAPPERS.efficiency, role: 'efficiency', tier: 'economy', effort: 'low', readOnly: false },
11
+ { name: 'aiwg-model-explorer', role: 'efficiency', tier: 'economy', effort: 'low', readOnly: true },
12
+ { name: 'aiwg-model-verifier', role: 'coding', tier: 'standard', effort: 'medium', readOnly: true },
13
+ ];
14
+ //# sourceMappingURL=wrapper-definitions.js.map
@@ -1,17 +1,8 @@
1
1
  import { promises as fs } from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { load as loadYaml } from 'js-yaml';
4
- import { MODEL_WRAPPERS } from './provider-models.js';
5
- const TIERS = {
6
- reasoning: 'premium',
7
- coding: 'standard',
8
- efficiency: 'economy',
9
- };
10
- const EFFORTS = {
11
- reasoning: 'high',
12
- coding: 'medium',
13
- efficiency: 'low',
14
- };
4
+ import { MODEL_WRAPPER_DEFINITIONS } from './wrapper-definitions.js';
5
+ import { isFlagshipModel } from './tiers.js';
15
6
  const CLAUDE_ALIASES = {
16
7
  reasoning: 'opus',
17
8
  coding: 'sonnet',
@@ -66,7 +57,7 @@ function artifactFields(file, content) {
66
57
  if (/\.json$/i.test(file)) {
67
58
  try {
68
59
  const parsed = JSON.parse(content);
69
- return parsed && typeof parsed === 'object' ? parsed : null;
60
+ return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : null;
70
61
  }
71
62
  catch {
72
63
  return null;
@@ -94,38 +85,69 @@ function addMismatch(mismatches, wrapper, file, field, reason, expected, actual)
94
85
  reason,
95
86
  });
96
87
  }
97
- async function validateArtifact(file, role, expectation) {
98
- const wrapper = MODEL_WRAPPERS[role];
88
+ async function validateArtifact(file, definition, expectation) {
89
+ const { name: wrapper, role, tier, effort, readOnly } = definition;
99
90
  const mismatches = [];
100
91
  const content = await fs.readFile(file, 'utf8');
101
92
  if (!content.trim()) {
102
93
  addMismatch(mismatches, wrapper, file, 'content', 'wrapper artifact is empty');
103
94
  return mismatches;
104
95
  }
105
- const fields = artifactFields(file, content);
96
+ const fields = artifactFields(file, content)
97
+ ?? (expectation.provider === 'windsurf' && content.includes(`### ${wrapper}`) ? { name: wrapper } : null);
106
98
  if (!fields) {
107
99
  addMismatch(mismatches, wrapper, file, 'format', 'wrapper artifact is malformed or has no parseable metadata');
108
100
  return mismatches;
109
101
  }
110
- const actualName = fieldValue(fields, 'name');
102
+ const actualName = fieldValue(fields, 'name') ?? (expectation.provider === 'opencode' ? wrapper : undefined);
111
103
  if (actualName !== wrapper)
112
104
  addMismatch(mismatches, wrapper, file, 'name', 'wrapper identity does not match its deployed filename', wrapper, actualName);
113
105
  const actualRole = fieldValue(fields, 'model-role', 'modelRole', 'aiwg-model-role');
114
106
  if (actualRole && actualRole !== role)
115
107
  addMismatch(mismatches, wrapper, file, 'model-role', 'wrapper role is stale or mismatched', role, actualRole);
116
108
  const actualTier = fieldValue(fields, 'model-tier', 'modelTier', 'aiwg-model-tier');
117
- if (actualTier && actualTier !== TIERS[role])
118
- addMismatch(mismatches, wrapper, file, 'model-tier', 'wrapper tier is stale or mismatched', TIERS[role], actualTier);
109
+ const standardFallback = tier === 'economy' && actualTier === 'standard'
110
+ && (readOnly || expectation.provider === 'cursor');
111
+ if (actualTier && actualTier !== tier && !standardFallback)
112
+ addMismatch(mismatches, wrapper, file, 'model-tier', 'wrapper tier is stale or mismatched', tier, actualTier);
119
113
  const actualModel = fieldValue(fields, 'model', 'model_hint', 'modelHint');
120
114
  const expectedModel = expectation.models?.[role];
115
+ if (actualModel && isFlagshipModel(actualModel))
116
+ addMismatch(mismatches, wrapper, file, 'model', 'wrapper model is flagship; wrappers cannot elect flagship', undefined, actualModel);
117
+ if (readOnly) {
118
+ if (expectation.provider === 'codex' && fields.sandbox_mode !== 'read-only')
119
+ addMismatch(mismatches, wrapper, file, 'sandbox_mode', 'read-only wrapper must use the native read-only sandbox', 'read-only', fieldValue(fields, 'sandbox_mode'));
120
+ const tools = Array.isArray(fields.tools) ? fields.tools : typeof fields.tools === 'string' ? fields.tools.split(/[,\s]+/) : [];
121
+ if (['claude', 'copilot', 'factory', 'omp', 'antigravity', 'openclaw'].includes(expectation.provider ?? '') && tools.length === 0)
122
+ addMismatch(mismatches, wrapper, file, 'tools', 'read-only wrapper is missing its explicit tool allowlist');
123
+ if (tools.some(tool => /^(?:write|edit|create|apply[_-]?patch|multiedit|task|agent|write_to_file|replace_file_content)$/i.test(String(tool))))
124
+ addMismatch(mismatches, wrapper, file, 'tools', 'read-only wrapper exposes mutation or delegation tools');
125
+ const allowlists = {
126
+ claude: ['Read', 'Grep', 'Glob', 'Bash'], copilot: ['search/codebase', 'terminal'],
127
+ factory: ['Execute', 'Glob', 'Grep', 'Read'], omp: ['read', 'grep', 'glob', 'bash'],
128
+ antigravity: ['view_file', 'grep_search', 'run_command'], openclaw: ['Read', 'Grep', 'Glob', 'Bash'],
129
+ };
130
+ const allowed = allowlists[expectation.provider ?? ''];
131
+ if (allowed && (tools.length !== allowed.length || allowed.some(tool => !tools.includes(tool))))
132
+ addMismatch(mismatches, wrapper, file, 'tools', 'read-only wrapper tools differ from the provider allowlist');
133
+ if (expectation.provider === 'opencode') {
134
+ const permissions = fields.permission;
135
+ if (permissions?.edit !== 'deny' || permissions?.task !== 'deny' || permissions?.['*'] !== 'deny')
136
+ addMismatch(mismatches, wrapper, file, 'permission', 'read-only wrapper must deny edits, delegation and unlisted tools');
137
+ }
138
+ if (expectation.provider === 'cursor' && fields.readonly !== true)
139
+ addMismatch(mismatches, wrapper, file, 'readonly', 'Cursor wrapper must enable its native read-only control');
140
+ if (!content.includes('WorkerClaims') || !content.includes('criterion') || !content.includes('Stop rules'))
141
+ addMismatch(mismatches, wrapper, file, 'return-contract', 'read-only wrapper is missing its condensed worker return contract');
142
+ }
121
143
  if (expectation.provider === 'codex') {
122
144
  if (!actualModel)
123
145
  addMismatch(mismatches, wrapper, file, 'model', 'Codex wrapper has no exact model pin', expectedModel);
124
146
  else if (expectedModel && actualModel !== expectedModel)
125
147
  addMismatch(mismatches, wrapper, file, 'model', 'Codex wrapper model does not match the effective catalog', expectedModel, actualModel);
126
148
  const actualEffort = fieldValue(fields, 'model_reasoning_effort');
127
- if (actualEffort !== EFFORTS[role])
128
- addMismatch(mismatches, wrapper, file, 'model_reasoning_effort', 'Codex wrapper effort does not match its role', EFFORTS[role], actualEffort);
149
+ if (actualEffort !== effort)
150
+ addMismatch(mismatches, wrapper, file, 'model_reasoning_effort', 'Codex wrapper effort does not match its role', effort, actualEffort);
129
151
  if (!fieldValue(fields, 'developer_instructions'))
130
152
  addMismatch(mismatches, wrapper, file, 'developer_instructions', 'Codex wrapper has no bootstrap instructions', 'non-empty');
131
153
  }
@@ -136,26 +158,27 @@ async function validateArtifact(file, role, expectation) {
136
158
  if (!actualRole)
137
159
  addMismatch(mismatches, wrapper, file, 'model-role', 'Claude wrapper is missing its canonical role', role);
138
160
  if (!actualTier)
139
- addMismatch(mismatches, wrapper, file, 'model-tier', 'Claude wrapper is missing its canonical tier', TIERS[role]);
161
+ addMismatch(mismatches, wrapper, file, 'model-tier', 'Claude wrapper is missing its canonical tier', tier);
140
162
  }
141
163
  return mismatches;
142
164
  }
143
165
  export async function verifyModelWrapperDeployment(agentsPath, expectation = {}) {
144
- const expected = Object.entries(MODEL_WRAPPERS);
166
+ const expected = MODEL_WRAPPER_DEFINITIONS;
145
167
  if (!agentsPath)
146
168
  return {
147
169
  supported: false,
148
170
  valid: false,
149
171
  agentsPath: null,
150
172
  found: [],
151
- missing: expected.map(([, wrapper]) => wrapper),
173
+ missing: expected.map(({ name }) => name),
152
174
  mismatches: [],
153
175
  };
154
176
  const files = await collectFiles(agentsPath);
155
177
  const found = [];
156
178
  const missing = [];
157
179
  const mismatches = [];
158
- for (const [role, wrapper] of expected) {
180
+ for (const definition of expected) {
181
+ const wrapper = definition.name;
159
182
  const matches = files.filter(file => path.basename(file).replace(/(?:\.agent)?\.(?:md|toml|json|yaml|yml)$/i, '') === wrapper);
160
183
  if (matches.length === 0) {
161
184
  missing.push(wrapper);
@@ -164,7 +187,7 @@ export async function verifyModelWrapperDeployment(agentsPath, expectation = {})
164
187
  found.push(wrapper);
165
188
  if (matches.length > 1)
166
189
  addMismatch(mismatches, wrapper, matches[0], 'path', `multiple deployed wrapper artifacts found: ${matches.join(', ')}`);
167
- mismatches.push(...await validateArtifact(matches[0], role, expectation));
190
+ mismatches.push(...await validateArtifact(matches[0], definition, expectation));
168
191
  }
169
192
  return {
170
193
  supported: true,