@aopslabs/aops 0.3.31 → 0.3.33

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 (147) hide show
  1. package/README.md +11 -3
  2. package/aops-assets-release/aops-assets.json.gz +0 -0
  3. package/aops-assets-release/disciplines/build-review-chat/SKILL.md +33 -0
  4. package/aops-assets-release/disciplines/coordinator-loop/SKILL.md +33 -0
  5. package/aops-assets-release/disciplines/design-first-consensus/SKILL.md +30 -0
  6. package/aops-assets-release/disciplines/solo-pm-loop/SKILL.md +31 -0
  7. package/aops-assets-release/docs/user-guides/agentspace-user-guide.md +384 -0
  8. package/aops-assets-release/docs/user-guides/aops-cli-user-guide.md +2067 -0
  9. package/aops-assets-release/docs/user-guides/chatv3-user-guide.md +500 -0
  10. package/aops-assets-release/docs/user-guides/docman-user-guide.md +1009 -0
  11. package/aops-assets-release/docs/user-guides/projectman-user-guide.md +763 -0
  12. package/aops-assets-release/docs/user-guides/tasker-user-guide.md +244 -0
  13. package/aops-assets-release/release.json +6 -0
  14. package/aops-assets-release/roles/coordinator/ROLE.md +28 -0
  15. package/aops-assets-release/roles/implementer/ROLE.md +27 -0
  16. package/aops-assets-release/roles/reviewer/ROLE.md +27 -0
  17. package/aops-assets-release/skills/aops/SKILL.md +112 -0
  18. package/aops-assets-release/skills/aops-bootstrapper-authoring/SKILL.md +245 -0
  19. package/aops-assets-release/skills/aops-cli-agentspace/SKILL.md +186 -0
  20. package/aops-assets-release/skills/aops-cli-board-lifecycle/SKILL.md +64 -0
  21. package/aops-assets-release/skills/aops-cli-chat/SKILL.md +204 -0
  22. package/aops-assets-release/skills/aops-cli-collab/SKILL.md +42 -0
  23. package/aops-assets-release/skills/aops-cli-core/SKILL.md +219 -0
  24. package/aops-assets-release/skills/aops-cli-discuss/SKILL.md +172 -0
  25. package/aops-assets-release/skills/aops-cli-docman/SKILL.md +192 -0
  26. package/aops-assets-release/skills/aops-cli-fileman/SKILL.md +169 -0
  27. package/aops-assets-release/skills/aops-cli-mission/SKILL.md +128 -0
  28. package/aops-assets-release/skills/aops-cli-operator-brief/SKILL.md +67 -0
  29. package/aops-assets-release/skills/aops-cli-projectman/SKILL.md +235 -0
  30. package/aops-assets-release/skills/aops-cli-sugar-authoring/SKILL.md +188 -0
  31. package/aops-assets-release/skills/aops-cli-tasker/SKILL.md +108 -0
  32. package/aops-assets-release/skills/aops-cli-tooling-agent/SKILL.md +112 -0
  33. package/aops-assets-release/skills/aops-cli-view/SKILL.md +210 -0
  34. package/aops-assets-release/skills/aops-collaborative-work/SKILL.md +304 -0
  35. package/aops-assets-release/skills/aops-interactive/SKILL.md +70 -0
  36. package/aops-assets-release/skills/aops-loop-interactive/SKILL.md +314 -0
  37. package/aops-assets-release/skills/aops-working-disciplines/SKILL.md +310 -0
  38. package/aops-assets-release/skills/feature-retirement-flow/SKILL.md +126 -0
  39. package/assets/skills/aops-install/SKILL.md +18 -17
  40. package/dist/commands/assets.js +93 -1264
  41. package/dist/commands/community-server.js +27 -8
  42. package/dist/commands/community-setup.js +1 -2
  43. package/dist/commands/discuss.js +1 -1
  44. package/dist/commands/doc.js +88 -27
  45. package/dist/commands/docs.js +68 -0
  46. package/dist/commands/global-update.js +28 -0
  47. package/dist/commands/init.js +3 -1
  48. package/dist/commands/loop.js +6379 -0
  49. package/dist/commands/memory.js +2 -1
  50. package/dist/commands/pm/index.js +11 -9
  51. package/dist/commands/pm/projectman.js +33 -2
  52. package/dist/commands/project.js +6 -6
  53. package/dist/commands/prompt.js +1 -1
  54. package/dist/commands/repo-sync.js +92 -27
  55. package/dist/commands/runner.js +257 -0
  56. package/dist/commands/skill.js +1 -1
  57. package/dist/commands/start.js +1 -1
  58. package/dist/commands/tasker.js +361 -0
  59. package/dist/commands/view.js +53 -9
  60. package/dist/lib/commercial-setup-readiness-adapter.js +0 -1
  61. package/dist/lib/community-migration-snapshot.js +7 -9
  62. package/dist/lib/community-native-database-recovery.js +5 -14
  63. package/dist/lib/community-native-lifecycle.js +13 -0
  64. package/dist/lib/setup-agent-assets-bridge.js +28 -148
  65. package/dist/lib/setup-agent-assets-release.js +16 -44
  66. package/dist/lib/setup-init-orchestrator.js +11 -15
  67. package/dist/lib/simple-agent-assets.js +447 -0
  68. package/dist/lib/user-guide-sections.js +488 -0
  69. package/dist/main.js +10 -2
  70. package/dist/seeds/agents-md.js +3 -3
  71. package/dist/utils/agents-md.js +1 -1
  72. package/dist/utils/guide-paths.js +7 -7
  73. package/dist/utils/hosted-workspace.js +2 -1
  74. package/dist/utils/repo-first-storage.js +26 -1
  75. package/dist/utils/session-state.js +2 -7
  76. package/launchers/aops-cockpit.sh +0 -0
  77. package/launchers/aops-server.sh +0 -0
  78. package/package.json +67 -35
  79. package/THIRD_PARTY_NOTICES +0 -16169
  80. package/agent-assets-release/agent-assets/core/bc42dd7792dbe66040e99a7ef3d80b3bc788c72b369b5a065cf936aef29f53fb/files/SKILL.md +0 -47
  81. package/agent-assets-release/agent-assets/core/bc42dd7792dbe66040e99a7ef3d80b3bc788c72b369b5a065cf936aef29f53fb/files/references/agentspace/SKILL.md +0 -72
  82. package/agent-assets-release/agent-assets/core/bc42dd7792dbe66040e99a7ef3d80b3bc788c72b369b5a065cf936aef29f53fb/files/references/aops-cli-core/SKILL.md +0 -110
  83. package/agent-assets-release/agent-assets/core/bc42dd7792dbe66040e99a7ef3d80b3bc788c72b369b5a065cf936aef29f53fb/files/references/chatv3/SKILL.md +0 -59
  84. package/agent-assets-release/agent-assets/core/bc42dd7792dbe66040e99a7ef3d80b3bc788c72b369b5a065cf936aef29f53fb/files/references/collaborative-work/SKILL.md +0 -81
  85. package/agent-assets-release/agent-assets/core/bc42dd7792dbe66040e99a7ef3d80b3bc788c72b369b5a065cf936aef29f53fb/files/references/discuss/SKILL.md +0 -66
  86. package/agent-assets-release/agent-assets/core/bc42dd7792dbe66040e99a7ef3d80b3bc788c72b369b5a065cf936aef29f53fb/files/references/docman/SKILL.md +0 -75
  87. package/agent-assets-release/agent-assets/core/bc42dd7792dbe66040e99a7ef3d80b3bc788c72b369b5a065cf936aef29f53fb/files/references/projectman/SKILL.md +0 -92
  88. package/agent-assets-release/agent-assets/core/bc42dd7792dbe66040e99a7ef3d80b3bc788c72b369b5a065cf936aef29f53fb/files/references/sys/SKILL.md +0 -36
  89. package/agent-assets-release/agent-assets/core/bc42dd7792dbe66040e99a7ef3d80b3bc788c72b369b5a065cf936aef29f53fb/files/references/view/SKILL.md +0 -58
  90. package/agent-assets-release/agent-assets/core/bc42dd7792dbe66040e99a7ef3d80b3bc788c72b369b5a065cf936aef29f53fb/files/references/working-disciplines/SKILL.md +0 -66
  91. package/agent-assets-release/agent-assets/core/bc42dd7792dbe66040e99a7ef3d80b3bc788c72b369b5a065cf936aef29f53fb/files/user-guides/agent-assets.md +0 -81
  92. package/agent-assets-release/agent-assets/core/bc42dd7792dbe66040e99a7ef3d80b3bc788c72b369b5a065cf936aef29f53fb/files/user-guides/agentspace.md +0 -183
  93. package/agent-assets-release/agent-assets/core/bc42dd7792dbe66040e99a7ef3d80b3bc788c72b369b5a065cf936aef29f53fb/files/user-guides/aops-cli.md +0 -1108
  94. package/agent-assets-release/agent-assets/core/bc42dd7792dbe66040e99a7ef3d80b3bc788c72b369b5a065cf936aef29f53fb/files/user-guides/aops-system.md +0 -102
  95. package/agent-assets-release/agent-assets/core/bc42dd7792dbe66040e99a7ef3d80b3bc788c72b369b5a065cf936aef29f53fb/files/user-guides/chatv3.md +0 -113
  96. package/agent-assets-release/agent-assets/core/bc42dd7792dbe66040e99a7ef3d80b3bc788c72b369b5a065cf936aef29f53fb/files/user-guides/docman.md +0 -223
  97. package/agent-assets-release/agent-assets/core/bc42dd7792dbe66040e99a7ef3d80b3bc788c72b369b5a065cf936aef29f53fb/files/user-guides/projectman.md +0 -233
  98. package/agent-assets-release/agent-assets/core/bc42dd7792dbe66040e99a7ef3d80b3bc788c72b369b5a065cf936aef29f53fb/files/user-guides/sys.md +0 -94
  99. package/agent-assets-release/agent-assets/core/bc42dd7792dbe66040e99a7ef3d80b3bc788c72b369b5a065cf936aef29f53fb/files/user-guides/working-disciplines.md +0 -482
  100. package/agent-assets-release/agent-assets/core/bc42dd7792dbe66040e99a7ef3d80b3bc788c72b369b5a065cf936aef29f53fb/manifest.json +0 -117
  101. package/agent-assets-release/agent-assets/gateway/aops/SKILL.md +0 -14
  102. package/agent-assets-release/agent-assets/inventory.json +0 -29
  103. package/agent-assets-release/agent-assets/projection.json +0 -8
  104. package/agent-assets-release/agent-assets-release.json +0 -171
  105. package/agent-assets-release/agent-assets-release.sigstore.json +0 -67
  106. package/assets/agent-assets/core/SKILL.md +0 -47
  107. package/assets/agent-assets/core/references/agentspace/SKILL.md +0 -72
  108. package/assets/agent-assets/core/references/aops-cli-core/SKILL.md +0 -110
  109. package/assets/agent-assets/core/references/chatv3/SKILL.md +0 -59
  110. package/assets/agent-assets/core/references/collaborative-work/SKILL.md +0 -81
  111. package/assets/agent-assets/core/references/discuss/SKILL.md +0 -66
  112. package/assets/agent-assets/core/references/docman/SKILL.md +0 -75
  113. package/assets/agent-assets/core/references/projectman/SKILL.md +0 -92
  114. package/assets/agent-assets/core/references/sys/SKILL.md +0 -36
  115. package/assets/agent-assets/core/references/view/SKILL.md +0 -58
  116. package/assets/agent-assets/core/references/working-disciplines/SKILL.md +0 -66
  117. package/assets/agent-assets/core/user-guides/agent-assets.md +0 -81
  118. package/assets/agent-assets/core/user-guides/agentspace.md +0 -183
  119. package/assets/agent-assets/core/user-guides/aops-cli.md +0 -1108
  120. package/assets/agent-assets/core/user-guides/aops-system.md +0 -102
  121. package/assets/agent-assets/core/user-guides/chatv3.md +0 -113
  122. package/assets/agent-assets/core/user-guides/docman.md +0 -223
  123. package/assets/agent-assets/core/user-guides/projectman.md +0 -233
  124. package/assets/agent-assets/core/user-guides/sys.md +0 -94
  125. package/assets/agent-assets/core/user-guides/working-disciplines.md +0 -482
  126. package/assets/agent-assets/gateway/aops/SKILL.md +0 -14
  127. package/dist/lib/agent-assets/gateway.js +0 -15
  128. package/dist/lib/agent-assets/guards.js +0 -23
  129. package/dist/lib/agent-assets/hosted-discovery.js +0 -148
  130. package/dist/lib/agent-assets/hosted-package-input.js +0 -154
  131. package/dist/lib/agent-assets/legacy-pointer-migration.js +0 -677
  132. package/dist/lib/agent-assets/native-fs.js +0 -589
  133. package/dist/lib/agent-assets/roots.js +0 -45
  134. package/dist/lib/agent-assets/runtime-binding-reader.js +0 -545
  135. package/dist/lib/agent-assets/runtime-targets.js +0 -50
  136. package/dist/lib/agent-assets/store-reader.js +0 -1212
  137. package/dist/lib/agent-assets/store-writer.js +0 -1484
  138. package/native/bin/darwin-arm64/aops-agent-assets-fs +0 -0
  139. package/native/bin/darwin-x64/aops-agent-assets-fs +0 -0
  140. package/native/bin/linux-arm64/aops-agent-assets-fs +0 -0
  141. package/native/bin/linux-x64/aops-agent-assets-fs +0 -0
  142. package/native/bin/win32-x64/aops-agent-assets-fs.exe +0 -0
  143. package/native/manifest.json +0 -49
  144. package/native/qualifications/win32-x64.json +0 -23
  145. package/native/tui/darwin-arm64/aops-tui +0 -0
  146. package/native/tui/linux-x64/aops-tui +0 -0
  147. package/native/tui/win32-x64/aops-tui.exe +0 -0
@@ -1,589 +0,0 @@
1
- import { createHash } from 'node:crypto';
2
- import { spawn } from 'node:child_process';
3
- import { lstat, readFile, realpath } from 'node:fs/promises';
4
- import os from 'node:os';
5
- import path from 'node:path';
6
- import { fileURLToPath } from 'node:url';
7
- import { createInterface } from 'node:readline';
8
- import { AgentAssetsError } from './envelope.js';
9
- const PROTOCOL = 'AOPS_AGENT_ASSETS_FS_V1';
10
- const NATIVE_SURFACE = 'agent-assets-native-fs-v1';
11
- const SHA256 = /^[a-f0-9]{64}$/;
12
- const SUPPORTED = new Set([
13
- 'linux:x64',
14
- 'linux:arm64',
15
- 'darwin:x64',
16
- 'darwin:arm64',
17
- 'win32:x64',
18
- ]);
19
- const WINDOWS_CRASH_INJECTION_POINTS = Object.freeze([
20
- 'authority-history',
21
- 'authority-current',
22
- 'activation-receipt',
23
- 'active-pointer',
24
- 'runtime-binding-receipt',
25
- 'runtime-binding-current',
26
- 'maintenance-receipt',
27
- 'pin',
28
- 'rollback',
29
- 'prune',
30
- ]);
31
- export function windowsQualificationSupportsRuntime(input) {
32
- return input.qualificationArchitecture === input.runtimeArchitecture
33
- && input.qualificationCapabilityClass === input.runtimeCapabilityClass;
34
- }
35
- export async function openAgentAssetsNativePublicationSession(options) {
36
- const loaded = await loadNativeHelper(options);
37
- const transport = new NativeTransport(loaded.helperPath);
38
- try {
39
- await transport.ready;
40
- const bootstrapAnchor = await resolveBootstrapAnchor(options);
41
- const bootstrap = await transport.command([
42
- PROTOCOL,
43
- 'bootstrap',
44
- hexUtf8(bootstrapAnchor),
45
- hexUtf8(path.resolve(options.agentAssetsRoot)),
46
- ]);
47
- if (bootstrap.length !== 1 || bootstrap[0] !== 'bootstrap') {
48
- throw protocolError('Native helper returned an invalid bootstrap response.');
49
- }
50
- const response = await transport.command([
51
- PROTOCOL,
52
- 'open',
53
- hexUtf8(options.agentAssetsRoot),
54
- hexUtf8(loaded.helper.capabilityClass),
55
- loaded.capabilityEvidenceSha256,
56
- hexUtf8(loaded.runtimeOsBuild),
57
- hexUtf8(loaded.helper.architecture),
58
- options.requiredDurability ?? 'process-crash',
59
- ]);
60
- if (response[0] !== 'open' || response.length !== 9) {
61
- throw protocolError('Native helper returned an invalid open response.');
62
- }
63
- const capability = Object.freeze({
64
- platform: response[1],
65
- architecture: response[2],
66
- filesystem: decodeHexUtf8(response[3]),
67
- volumeIdentity: decodeHexUtf8(response[4]),
68
- capabilityClass: decodeHexUtf8(response[5]),
69
- capabilityEvidenceSha256: response[6],
70
- machineIdentitySha256: response[7],
71
- rootIdentitySha256: response[8],
72
- helperSha256: loaded.helper.sha256,
73
- nativeManifestSha256: loaded.manifestSha256,
74
- });
75
- assertCapability(capability, loaded);
76
- return new NativePublicationSession(transport, capability);
77
- }
78
- catch (error) {
79
- transport.terminate();
80
- throw normalizeNativeFailure(error);
81
- }
82
- }
83
- class NativePublicationSession {
84
- capability;
85
- transport;
86
- closed = false;
87
- constructor(transport, capability) {
88
- this.transport = transport;
89
- this.capability = capability;
90
- }
91
- async createDirectory(relativePath) {
92
- await this.run(['mkdir', hexUtf8(relativePath)]);
93
- }
94
- async publishFileNoReplace(relativePath, content) {
95
- await this.run(['publish-no-replace', hexUtf8(relativePath), Buffer.from(content).toString('hex')]);
96
- }
97
- async publishFileReplace(relativePath, expectedPriorSha256, content) {
98
- if (!SHA256.test(expectedPriorSha256)) {
99
- throw protocolError('Expected prior digest must be lowercase SHA-256.');
100
- }
101
- await this.run([
102
- 'publish-replace',
103
- hexUtf8(relativePath),
104
- expectedPriorSha256,
105
- Buffer.from(content).toString('hex'),
106
- ]);
107
- }
108
- async promoteDirectoryNoReplace(sourceRelativePath, destinationRelativePath) {
109
- await this.run([
110
- 'promote-directory',
111
- hexUtf8(sourceRelativePath),
112
- hexUtf8(destinationRelativePath),
113
- ]);
114
- }
115
- async registerRuntimeRoot(runtimeRoot) {
116
- if (this.closed)
117
- throw protocolError('Native publication session is closed.');
118
- const response = await this.transport.command([
119
- PROTOCOL,
120
- 'register-runtime-root',
121
- hexUtf8(path.resolve(runtimeRoot)),
122
- ]);
123
- if (response.length !== 3
124
- || response[0] !== 'register-runtime-root'
125
- || !/^runtime-[1-9]\d*$/.test(response[1])
126
- || !SHA256.test(response[2])) {
127
- throw protocolError('Native helper returned an invalid runtime-root registration.');
128
- }
129
- return new NativeRuntimeRoot(response[1], response[2], (fields) => this.run(fields));
130
- }
131
- async removeManagedTree(relativePath) {
132
- if (this.closed)
133
- throw protocolError('Native publication session is closed.');
134
- const response = await this.transport.command([
135
- PROTOCOL,
136
- 'remove-managed-tree',
137
- hexUtf8(relativePath),
138
- ]);
139
- if (response.length !== 2
140
- || response[0] !== 'remove-managed-tree'
141
- || (response[1] !== 'removed' && response[1] !== 'not-found')) {
142
- throw protocolError('Native helper returned an invalid managed-removal response.');
143
- }
144
- return response[1];
145
- }
146
- async close() {
147
- if (this.closed)
148
- return;
149
- this.closed = true;
150
- try {
151
- await this.transport.command([PROTOCOL, 'close']);
152
- }
153
- finally {
154
- this.transport.terminate();
155
- }
156
- }
157
- async run(fields) {
158
- if (this.closed)
159
- throw protocolError('Native publication session is closed.');
160
- const response = await this.transport.command([PROTOCOL, ...fields]);
161
- if (response[0] !== fields[0] || response.length !== 1) {
162
- throw protocolError('Native helper returned an invalid mutation response.');
163
- }
164
- }
165
- }
166
- async function resolveBootstrapAnchor(options) {
167
- const root = path.resolve(options.agentAssetsRoot);
168
- if (options.bootstrapAnchor)
169
- return path.resolve(options.bootstrapAnchor);
170
- const home = path.resolve(os.homedir());
171
- const relativeToHome = path.relative(home, root);
172
- if (relativeToHome && !relativeToHome.startsWith('..') && !path.isAbsolute(relativeToHome)) {
173
- return home;
174
- }
175
- const rootStats = await lstat(root).catch(() => null);
176
- if (rootStats?.isDirectory() && !rootStats.isSymbolicLink())
177
- return root;
178
- throw new AgentAssetsError('atomic_primitive_unavailable', 'A missing agent-assets root outside the user home requires an explicit trusted bootstrap anchor.', { nextActions: ['Pass bootstrapAnchor as an existing canonical local directory containing agentAssetsRoot.'] });
179
- }
180
- class NativeRuntimeRoot {
181
- id;
182
- rootIdentitySha256;
183
- run;
184
- constructor(id, rootIdentitySha256, run) {
185
- this.id = id;
186
- this.rootIdentitySha256 = rootIdentitySha256;
187
- this.run = run;
188
- }
189
- async createDirectory(relativePath) {
190
- await this.run(['runtime-mkdir', this.id, hexUtf8(relativePath)]);
191
- }
192
- async publishFileNoReplace(relativePath, content) {
193
- await this.run([
194
- 'runtime-publish-no-replace',
195
- this.id,
196
- hexUtf8(relativePath),
197
- Buffer.from(content).toString('hex'),
198
- ]);
199
- }
200
- async publishFileReplace(relativePath, expectedPriorSha256, content) {
201
- if (!SHA256.test(expectedPriorSha256)) {
202
- throw protocolError('Expected runtime prior digest must be lowercase SHA-256.');
203
- }
204
- await this.run([
205
- 'runtime-publish-replace',
206
- this.id,
207
- hexUtf8(relativePath),
208
- expectedPriorSha256,
209
- Buffer.from(content).toString('hex'),
210
- ]);
211
- }
212
- }
213
- class NativeTransport {
214
- ready;
215
- child;
216
- readline;
217
- pending = [];
218
- readyResolve;
219
- readyReject;
220
- didReadReady = false;
221
- closed = false;
222
- constructor(helperPath) {
223
- this.child = spawn(helperPath, ['session'], {
224
- stdio: ['pipe', 'pipe', 'pipe'],
225
- windowsHide: true,
226
- });
227
- this.ready = new Promise((resolve, reject) => {
228
- this.readyResolve = resolve;
229
- this.readyReject = reject;
230
- });
231
- this.readline = createInterface({ input: this.child.stdout, crlfDelay: Infinity });
232
- this.readline.on('line', (line) => this.onLine(line));
233
- this.child.once('error', (error) => this.failAll(error));
234
- this.child.once('exit', (code, signal) => {
235
- this.failAll(new Error(`native helper exited before close (${code ?? signal ?? 'unknown'})`));
236
- });
237
- }
238
- command(fields) {
239
- if (this.closed)
240
- return Promise.reject(protocolError('Native helper transport is closed.'));
241
- return new Promise((resolve, reject) => {
242
- this.pending.push({ resolve, reject });
243
- this.child.stdin.write(`${fields.join('\t')}\n`, 'utf8', (error) => {
244
- if (error)
245
- this.failAll(error);
246
- });
247
- });
248
- }
249
- terminate() {
250
- if (this.closed)
251
- return;
252
- this.closed = true;
253
- this.readline.close();
254
- this.child.stdin.destroy();
255
- this.child.kill();
256
- }
257
- onLine(line) {
258
- const fields = line.split('\t');
259
- if (!this.didReadReady) {
260
- this.didReadReady = true;
261
- if (fields.length === 5
262
- && fields[0] === 'READY'
263
- && fields[1] === PROTOCOL
264
- && fields[2] === '1') {
265
- this.readyResolve();
266
- }
267
- else {
268
- this.readyReject(protocolError('Native helper handshake is incompatible.'));
269
- }
270
- return;
271
- }
272
- const pending = this.pending.shift();
273
- if (!pending) {
274
- this.failAll(protocolError('Native helper emitted an unsolicited response.'));
275
- return;
276
- }
277
- if (fields[0] === 'OK') {
278
- pending.resolve(fields.slice(1));
279
- return;
280
- }
281
- if (fields[0] === 'ERR' && fields.length === 3) {
282
- pending.reject(nativeError(fields[1], decodeHexUtf8(fields[2])));
283
- return;
284
- }
285
- pending.reject(protocolError('Native helper response is malformed.'));
286
- }
287
- failAll(error) {
288
- if (!this.didReadReady)
289
- this.readyReject(error);
290
- for (const pending of this.pending.splice(0))
291
- pending.reject(error);
292
- this.terminate();
293
- }
294
- }
295
- async function loadNativeHelper(options) {
296
- const platform = normalizePlatform(options.platform ?? process.platform);
297
- const architecture = normalizeArchitecture(options.architecture ?? process.arch);
298
- if (!SUPPORTED.has(`${platform}:${architecture}`)) {
299
- throw new AgentAssetsError('atomic_primitive_unavailable', `No v1 native publication helper is supported for ${platform}/${architecture}.`, { nextActions: ['Use a supported Community CLI platform build; do not enable a JavaScript filesystem fallback.'] });
300
- }
301
- const nativeRoot = path.resolve(options.nativeRoot ?? defaultNativeRoot());
302
- await assertPlainPath(nativeRoot, true);
303
- const manifestPath = path.join(nativeRoot, 'manifest.json');
304
- const manifestBytes = await readPlainFile(manifestPath);
305
- const manifestSha256 = sha256(manifestBytes);
306
- const expectedManifestSha256 = options.expectedNativeManifestSha256
307
- ?? injectedNativeManifestSha256();
308
- if (!expectedManifestSha256 || !SHA256.test(expectedManifestSha256)) {
309
- throw new AgentAssetsError('atomic_primitive_unavailable', 'The installed CLI has no signed native-helper manifest identity.', { nextActions: ['Reinstall AOPS CLI from a signed Community release.'] });
310
- }
311
- if (manifestSha256 !== expectedManifestSha256) {
312
- throw new AgentAssetsError('hash_mismatch', 'The native-helper manifest digest does not match the CLI identity.', {
313
- nextActions: ['Reinstall AOPS CLI from the same signed Community release; do not repair helper files manually.'],
314
- });
315
- }
316
- const manifest = parseNativeManifest(manifestBytes);
317
- const helper = manifest.helpers.find((item) => (item.platform === platform && item.architecture === architecture));
318
- if (!helper) {
319
- throw new AgentAssetsError('atomic_primitive_unavailable', `The signed CLI archive does not contain a helper for ${platform}/${architecture}.`, { nextActions: ['Install a Community CLI archive that includes this exact platform helper.'] });
320
- }
321
- const helperPath = safeManifestPath(nativeRoot, helper.relativePath);
322
- const helperBytes = await readPlainFile(helperPath);
323
- if (sha256(helperBytes) !== helper.sha256) {
324
- throw new AgentAssetsError('hash_mismatch', 'The packaged native helper digest is invalid.', {
325
- nextActions: ['Reinstall the signed Community CLI package.'],
326
- });
327
- }
328
- if (platform !== 'win32') {
329
- if (helper.qualification !== null) {
330
- throw protocolError('POSIX helper records must not carry a Windows qualification.');
331
- }
332
- return Object.freeze({
333
- helper,
334
- helperPath,
335
- manifestSha256,
336
- capabilityEvidenceSha256: helper.sha256,
337
- runtimeOsBuild: '',
338
- });
339
- }
340
- if (!helper.qualification) {
341
- throw new AgentAssetsError('durability_unavailable', 'The Windows helper has no packaged signed crash-recovery qualification.', { nextActions: ['Install a Community release with signed Windows crash-recovery evidence.'] });
342
- }
343
- const qualificationPath = safeManifestPath(nativeRoot, helper.qualification.relativePath);
344
- const qualificationBytes = await readPlainFile(qualificationPath);
345
- if (sha256(qualificationBytes) !== helper.qualification.sha256) {
346
- throw new AgentAssetsError('hash_mismatch', 'The Windows qualification digest is invalid.', {
347
- nextActions: ['Reinstall the signed Community CLI package.'],
348
- });
349
- }
350
- const qualification = parseWindowsQualification(qualificationBytes);
351
- if (!windowsQualificationSupportsRuntime({
352
- qualificationArchitecture: qualification.architecture,
353
- qualificationCapabilityClass: qualification.capabilityClass,
354
- runtimeArchitecture: architecture,
355
- runtimeCapabilityClass: helper.capabilityClass,
356
- })) {
357
- throw new AgentAssetsError('durability_unavailable', 'The packaged Windows qualification does not match this architecture and capability class.', { nextActions: ['Install a Community release with a compatible signed Windows helper.'] });
358
- }
359
- return Object.freeze({
360
- helper,
361
- helperPath,
362
- manifestSha256,
363
- capabilityEvidenceSha256: qualification.evidenceSha256,
364
- runtimeOsBuild: os.release(),
365
- });
366
- }
367
- function parseNativeManifest(bytes) {
368
- const value = parseJson(bytes, 'Native helper manifest is not valid JSON.');
369
- exactKeys(value, ['schemaVersion', 'surface', 'helpers']);
370
- if (value.schemaVersion !== 1 || value.surface !== NATIVE_SURFACE || !Array.isArray(value.helpers)) {
371
- throw protocolError('Native helper manifest schema is incompatible.');
372
- }
373
- const identities = new Set();
374
- const paths = new Set();
375
- const helpers = value.helpers.map((raw) => {
376
- exactKeys(raw, [
377
- 'platform',
378
- 'architecture',
379
- 'relativePath',
380
- 'sha256',
381
- 'capabilityClass',
382
- 'qualification',
383
- ]);
384
- const platform = normalizePlatform(raw.platform);
385
- const architecture = normalizeArchitecture(raw.architecture);
386
- const identity = `${platform}:${architecture}`;
387
- if (identities.has(identity))
388
- throw protocolError('Native helper manifest has a duplicate platform identity.');
389
- identities.add(identity);
390
- assertManifestRelativePath(raw.relativePath);
391
- if (paths.has(raw.relativePath))
392
- throw protocolError('Native helper manifest has a duplicate path.');
393
- paths.add(raw.relativePath);
394
- if (!SHA256.test(raw.sha256))
395
- throw protocolError('Native helper digest is invalid.');
396
- const expectedClass = platform === 'win32'
397
- ? 'windows-ntfs-crash-recoverable-v1'
398
- : platform === 'darwin'
399
- ? 'macos-exclusive-durable-v1'
400
- : 'linux-posix-durable-v1';
401
- if (raw.capabilityClass !== expectedClass)
402
- throw protocolError('Native helper capability class is invalid.');
403
- let qualification = null;
404
- if (raw.qualification !== null) {
405
- exactKeys(raw.qualification, ['relativePath', 'sha256']);
406
- assertManifestRelativePath(raw.qualification.relativePath);
407
- if (!SHA256.test(raw.qualification.sha256) || paths.has(raw.qualification.relativePath)) {
408
- throw protocolError('Native qualification record is invalid or duplicated.');
409
- }
410
- paths.add(raw.qualification.relativePath);
411
- qualification = Object.freeze({
412
- relativePath: raw.qualification.relativePath,
413
- sha256: raw.qualification.sha256,
414
- });
415
- }
416
- return Object.freeze({
417
- platform,
418
- architecture,
419
- relativePath: raw.relativePath,
420
- sha256: raw.sha256,
421
- capabilityClass: expectedClass,
422
- qualification,
423
- });
424
- });
425
- if (helpers.length === 0)
426
- throw protocolError('Native helper manifest is empty.');
427
- return Object.freeze({ schemaVersion: 1, surface: NATIVE_SURFACE, helpers: Object.freeze(helpers) });
428
- }
429
- function parseWindowsQualification(bytes) {
430
- const value = parseJson(bytes, 'Windows qualification is not valid JSON.');
431
- exactKeys(value, [
432
- 'schemaVersion',
433
- 'status',
434
- 'platform',
435
- 'architecture',
436
- 'osBuild',
437
- 'filesystem',
438
- 'primitiveProfile',
439
- 'capabilityClass',
440
- 'evidenceSha256',
441
- 'crashInjectionPoints',
442
- ]);
443
- if (value.schemaVersion !== 1
444
- || value.status !== 'qualified'
445
- || value.platform !== 'win32'
446
- || !['x64', 'arm64'].includes(value.architecture)
447
- || !/^\d+\.\d+\.\d+$/.test(value.osBuild)
448
- || value.filesystem !== 'NTFS'
449
- || value.primitiveProfile !== 'windows-createfile-flush-movefileex-v1'
450
- || value.capabilityClass !== 'windows-ntfs-crash-recoverable-v1'
451
- || !SHA256.test(value.evidenceSha256)
452
- || JSON.stringify(value.crashInjectionPoints) !== JSON.stringify(WINDOWS_CRASH_INJECTION_POINTS)) {
453
- throw new AgentAssetsError('durability_unavailable', 'Windows qualification is incomplete or incompatible.', {
454
- nextActions: ['Install a Community release with complete crash-injection evidence.'],
455
- });
456
- }
457
- return Object.freeze(value);
458
- }
459
- function assertCapability(capability, loaded) {
460
- if (capability.platform !== loaded.helper.platform
461
- || capability.architecture !== loaded.helper.architecture
462
- || capability.capabilityClass !== loaded.helper.capabilityClass
463
- || capability.capabilityEvidenceSha256 !== loaded.capabilityEvidenceSha256
464
- || (loaded.helper.platform === 'win32' && capability.filesystem !== 'NTFS')
465
- || !SHA256.test(capability.machineIdentitySha256)
466
- || !SHA256.test(capability.rootIdentitySha256)
467
- || capability.machineIdentitySha256 === capability.rootIdentitySha256
468
- || capability.machineIdentitySha256 === capability.capabilityEvidenceSha256
469
- || capability.rootIdentitySha256 === capability.capabilityEvidenceSha256) {
470
- throw new AgentAssetsError('atomic_primitive_unavailable', 'Native live-probe identity does not match the signed helper manifest.', { nextActions: ['Reinstall the signed Community CLI archive and rerun readiness.'] });
471
- }
472
- }
473
- async function assertPlainPath(candidate, directory) {
474
- const resolved = path.resolve(candidate);
475
- const physical = await realpath(resolved).catch(() => null);
476
- const stats = await lstat(resolved).catch(() => null);
477
- if (!physical
478
- || physical !== resolved
479
- || !stats
480
- || stats.isSymbolicLink()
481
- || (directory ? !stats.isDirectory() : !stats.isFile())) {
482
- throw new AgentAssetsError('link_unsafe_path', 'Native helper package path is linked or not a plain entry.', {
483
- nextActions: ['Reinstall the CLI into a real non-linked package directory.'],
484
- });
485
- }
486
- }
487
- async function readPlainFile(candidate) {
488
- await assertPlainPath(candidate, false);
489
- return readFile(candidate);
490
- }
491
- function safeManifestPath(root, relativePath) {
492
- assertManifestRelativePath(relativePath);
493
- const candidate = path.resolve(root, ...relativePath.split('/'));
494
- const relative = path.relative(root, candidate);
495
- if (!relative || relative.startsWith('..') || path.isAbsolute(relative)) {
496
- throw protocolError('Native manifest path escaped its package root.');
497
- }
498
- return candidate;
499
- }
500
- function assertManifestRelativePath(value) {
501
- if (typeof value !== 'string'
502
- || value.length === 0
503
- || value.includes('\\')
504
- || path.posix.isAbsolute(value)
505
- || value.split('/').some((segment) => !segment || segment === '.' || segment === '..')) {
506
- throw protocolError('Native manifest contains an unsafe relative path.');
507
- }
508
- }
509
- function exactKeys(value, keys) {
510
- if (!value || typeof value !== 'object' || Array.isArray(value))
511
- throw protocolError('Record shape is invalid.');
512
- const actual = Object.keys(value);
513
- if (actual.length !== keys.length || actual.some((key) => !keys.includes(key))) {
514
- throw protocolError('Record contains missing or unknown fields.');
515
- }
516
- }
517
- function parseJson(bytes, message) {
518
- try {
519
- return JSON.parse(Buffer.from(bytes).toString('utf8'));
520
- }
521
- catch {
522
- throw protocolError(message);
523
- }
524
- }
525
- function normalizePlatform(value) {
526
- if (value === 'linux' || value === 'darwin' || value === 'win32')
527
- return value;
528
- throw new AgentAssetsError('atomic_primitive_unavailable', `Unsupported native platform: ${String(value)}`, {
529
- nextActions: ['Use a supported Community CLI platform build.'],
530
- });
531
- }
532
- function normalizeArchitecture(value) {
533
- if (value === 'x64' || value === 'arm64')
534
- return value;
535
- throw new AgentAssetsError('atomic_primitive_unavailable', `Unsupported native architecture: ${String(value)}`, {
536
- nextActions: ['Use a supported Community CLI architecture build.'],
537
- });
538
- }
539
- function defaultNativeRoot() {
540
- const moduleDirectory = path.dirname(fileURLToPath(import.meta.url));
541
- const bundled = path.resolve(moduleDirectory, '..', 'native');
542
- const compiledOrSource = path.resolve(moduleDirectory, '..', '..', '..', 'native');
543
- return moduleDirectory.endsWith(`${path.sep}dist`) ? bundled : compiledOrSource;
544
- }
545
- function injectedNativeManifestSha256() {
546
- return typeof "88e8c662234fb095f9b2defc7dd7184b15709dce28298748bd3f9736eb7de5ae" === 'undefined'
547
- ? undefined
548
- : "88e8c662234fb095f9b2defc7dd7184b15709dce28298748bd3f9736eb7de5ae";
549
- }
550
- function sha256(bytes) {
551
- return createHash('sha256').update(bytes).digest('hex');
552
- }
553
- function hexUtf8(value) {
554
- return Buffer.from(value, 'utf8').toString('hex');
555
- }
556
- function decodeHexUtf8(value) {
557
- if (value.length % 2 !== 0 || !/^[a-f0-9]*$/.test(value))
558
- throw protocolError('Native response hex is invalid.');
559
- return Buffer.from(value, 'hex').toString('utf8');
560
- }
561
- function protocolError(message) {
562
- return new AgentAssetsError('atomic_primitive_unavailable', message, {
563
- nextActions: ['Reinstall the signed Community CLI package; do not enable a JavaScript fallback.'],
564
- });
565
- }
566
- function nativeError(code, message) {
567
- const allowed = [
568
- 'invalid_package_path',
569
- 'link_unsafe_path',
570
- 'concurrent_writer',
571
- 'publication_conflict',
572
- 'atomic_replace_blocked',
573
- 'atomic_primitive_unavailable',
574
- 'durability_unavailable',
575
- 'different_machine_store',
576
- 'schema_incompatible',
577
- ];
578
- const normalized = allowed.includes(code)
579
- ? code
580
- : 'atomic_primitive_unavailable';
581
- return new AgentAssetsError(normalized, message, {
582
- nextActions: ['Run `aops assets status --verify full --json` and inspect native capability diagnostics.'],
583
- });
584
- }
585
- function normalizeNativeFailure(error) {
586
- return error instanceof AgentAssetsError
587
- ? error
588
- : protocolError(error instanceof Error ? error.message : String(error));
589
- }
@@ -1,45 +0,0 @@
1
- import os from 'node:os';
2
- import path from 'node:path';
3
- import { getAgentAssetsConfig } from '../../utils/config.js';
4
- function selectRoot(name, candidates) {
5
- const selected = candidates.find((candidate) => candidate.value !== undefined && candidate.value.trim().length > 0);
6
- if (!selected?.value)
7
- throw new Error(`agent_assets_${name}_missing`);
8
- const candidate = selected.value.trim();
9
- if (!path.isAbsolute(candidate))
10
- throw new Error(`agent_assets_${name}_must_be_absolute`);
11
- return Object.freeze({
12
- absolutePath: path.normalize(candidate),
13
- source: selected.source,
14
- });
15
- }
16
- export function resolveAgentAssetsRoots(options = {}) {
17
- const env = options.env ?? process.env;
18
- const homeDir = options.homeDir ?? os.homedir();
19
- if (!path.isAbsolute(homeDir))
20
- throw new Error('agent_assets_home_must_be_absolute');
21
- const config = options.config ?? getAgentAssetsConfig();
22
- const dataRoot = selectRoot('dataRoot', [
23
- { value: options.dataRoot, source: 'option' },
24
- { value: env.AOPS_AGENT_ASSETS_DATA_ROOT, source: 'environment' },
25
- { value: config.dataRoot, source: 'user-config' },
26
- { value: path.join(homeDir, '.aops'), source: 'default' },
27
- ]);
28
- const codex = selectRoot('codexHome', [
29
- { value: options.codexHome, source: 'option' },
30
- { value: env.CODEX_HOME, source: 'environment' },
31
- { value: config.runtimeHomes?.codex, source: 'user-config' },
32
- { value: path.join(homeDir, '.codex'), source: 'default' },
33
- ]);
34
- const claude = selectRoot('claudeHome', [
35
- { value: options.claudeHome, source: 'option' },
36
- { value: env.CLAUDE_HOME, source: 'environment' },
37
- { value: config.runtimeHomes?.claude, source: 'user-config' },
38
- { value: path.join(homeDir, '.claude'), source: 'default' },
39
- ]);
40
- return Object.freeze({
41
- dataRoot,
42
- assetRoot: path.join(dataRoot.absolutePath, 'agent-assets'),
43
- runtimeHomes: Object.freeze({ codex, claude }),
44
- });
45
- }