@aiwg/cli 2026.8.18 → 2026.8.20

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 (48) hide show
  1. package/THIRD_PARTY_NOTICES.md +12 -0
  2. package/dist/src/api/index.d.ts +2 -0
  3. package/dist/src/api/index.js +2 -0
  4. package/dist/src/artifacts/backend-runtime.js +26 -0
  5. package/dist/src/artifacts/backends/sqlite-backend.js +204 -28
  6. package/dist/src/artifacts/dep-graph.js +27 -5
  7. package/dist/src/artifacts/graph-backend.js +2 -2
  8. package/dist/src/artifacts/graph-query.js +21 -9
  9. package/dist/src/artifacts/index-builder.js +78 -12
  10. package/dist/src/artifacts/index-files.js +26 -5
  11. package/dist/src/artifacts/index-status.js +4 -1
  12. package/dist/src/artifacts/query-engine.js +67 -67
  13. package/dist/src/artifacts/stats.js +9 -2
  14. package/dist/src/artifacts/types.js +14 -2
  15. package/dist/src/cli/handlers/help.js +2 -0
  16. package/dist/src/cli/handlers/index.js +6 -2
  17. package/dist/src/cli/handlers/installation.js +1 -1
  18. package/dist/src/cli/handlers/mission.js +27 -0
  19. package/dist/src/cli/handlers/refresh.js +6 -4
  20. package/dist/src/cli/handlers/runtime-info.js +29 -0
  21. package/dist/src/cli/handlers/steward.js +12 -0
  22. package/dist/src/cli/handlers/uhp.js +88 -0
  23. package/dist/src/cli/handlers/use.js +19 -4
  24. package/dist/src/config/aiwg-config.js +10 -0
  25. package/dist/src/extensions/commands/definitions.js +38 -0
  26. package/dist/src/installation/manager-command.mjs +31 -0
  27. package/dist/src/installation/manager.mjs +21 -0
  28. package/dist/src/mission-protocol/codecs.js +265 -0
  29. package/dist/src/mission-protocol/index.js +3 -0
  30. package/dist/src/mission-protocol/types.js +2 -0
  31. package/dist/src/smiths/context-pipeline/claude-hook.js +8 -5
  32. package/dist/src/smiths/context-pipeline/line-endings.js +12 -0
  33. package/dist/src/smiths/context-pipeline/managed-hook.js +8 -5
  34. package/dist/src/smiths/context-pipeline/workspace-context.js +3 -1
  35. package/dist/src/storage/backend-contract.js +64 -0
  36. package/dist/src/storage/index.js +2 -0
  37. package/dist/src/storage/migration-protocol.js +378 -0
  38. package/dist/src/uhp/client.js +374 -0
  39. package/dist/src/uhp/config.js +130 -0
  40. package/dist/src/uhp/errors.js +63 -0
  41. package/dist/src/uhp/index.js +7 -0
  42. package/dist/src/uhp/mission.js +111 -0
  43. package/dist/src/uhp/sse.js +76 -0
  44. package/dist/src/uhp/types.js +2 -0
  45. package/dist/src/update/service.mjs +3 -1
  46. package/package.json +1 -1
  47. package/tools/agents/deploy-agents.mjs +28 -8
  48. package/tools/agents/providers/base.mjs +5 -3
@@ -0,0 +1,111 @@
1
+ import { UHP_VERSION } from './types.js';
2
+ import { decodeMission } from '../mission-protocol/index.js';
3
+ function collectArtifacts(response) {
4
+ const artifacts = new Map();
5
+ const visit = (value) => {
6
+ if (Array.isArray(value)) {
7
+ value.forEach(visit);
8
+ return;
9
+ }
10
+ if (!value || typeof value !== 'object')
11
+ return;
12
+ const object = value;
13
+ if (typeof object.file_id === 'string')
14
+ artifacts.set(object.file_id, {
15
+ fileId: object.file_id,
16
+ ...(typeof object.container_id === 'string' ? { containerId: object.container_id } : {}),
17
+ ...(typeof object.filename === 'string' ? { filename: object.filename } : {}),
18
+ ...(typeof object.media_type === 'string' ? { mediaType: object.media_type } : {}),
19
+ source: structuredClone(object),
20
+ });
21
+ for (const child of Object.values(object))
22
+ visit(child);
23
+ };
24
+ visit(response.output);
25
+ return [...artifacts.values()];
26
+ }
27
+ function collectInputFiles(request) {
28
+ const files = [];
29
+ const visit = (value) => {
30
+ if (Array.isArray(value)) {
31
+ value.forEach(visit);
32
+ return;
33
+ }
34
+ if (!value || typeof value !== 'object')
35
+ return;
36
+ const object = value;
37
+ if (object.type === 'input_file')
38
+ files.push({
39
+ ...(typeof object.file_id === 'string' ? { fileId: object.file_id } : {}),
40
+ ...(typeof object.filename === 'string' ? { filename: object.filename } : {}),
41
+ ...(typeof object.file_data === 'string' && object.file_data.startsWith('data:') ? { mediaType: object.file_data.slice(5).split(/[;,]/, 1)[0] } : {}),
42
+ source: structuredClone(object),
43
+ });
44
+ for (const child of Object.values(object))
45
+ visit(child);
46
+ };
47
+ visit(request.input);
48
+ return files;
49
+ }
50
+ export function projectUhpResponseToMission(profile, response, request = { input: '' }, event) {
51
+ const known = ['in_progress', 'completed', 'failed', 'incomplete', 'cancelled'].includes(response.status);
52
+ const state = response.status === 'in_progress' ? 'running' : known ? response.status : 'unknown';
53
+ const metadata = response.metadata ?? {};
54
+ const artifacts = collectArtifacts(response);
55
+ const knownKeys = new Set(['id', 'object', 'created_at', 'status', 'model', 'previous_response_id', 'output', 'error', 'incomplete_details', 'metadata', 'store', 'usage']);
56
+ return {
57
+ transport: 'uhp',
58
+ protocolVersion: UHP_VERSION,
59
+ endpointProfile: profile,
60
+ state,
61
+ nativeState: response.status,
62
+ observationState: known ? 'authoritative' : 'unknown',
63
+ responseId: response.id,
64
+ previousResponseId: response.previous_response_id ?? request.previous_response_id,
65
+ sessionId: metadata.session_id,
66
+ harness: {
67
+ requested: request.metadata?.harness_id,
68
+ actual: metadata.harness_id,
69
+ substitutionReason: typeof metadata.harness_substitution_reason === 'string' ? metadata.harness_substitution_reason : undefined,
70
+ },
71
+ model: {
72
+ requested: request.model,
73
+ actual: response.model,
74
+ substitutionReason: metadata.model_substitution_reason ?? (typeof metadata.model_fallback_reason === 'string' ? metadata.model_fallback_reason : undefined),
75
+ },
76
+ containerId: metadata.container_id,
77
+ eventSequence: event?.sequence_number,
78
+ terminalEvent: event && /^response\.(?:completed|failed|incomplete|cancelled)$/.test(event.type) ? event.type : undefined,
79
+ artifactIds: artifacts.map(artifact => artifact.fileId),
80
+ inputFiles: collectInputFiles(request),
81
+ artifacts,
82
+ partialOutput: response.status !== 'completed' && Boolean(response.output?.length),
83
+ extensions: Object.fromEntries(Object.entries(response).filter(([key]) => !knownKeys.has(key))),
84
+ ...(known ? {} : { diagnostic: `Unknown UHP response state '${String(response.status)}'` }),
85
+ };
86
+ }
87
+ export function unknownUhpMissionEvidence(profile, diagnostic, responseId, lastSequence) {
88
+ return {
89
+ transport: 'uhp', protocolVersion: UHP_VERSION, endpointProfile: profile,
90
+ state: 'unknown', nativeState: 'unknown', observationState: 'unknown', responseId,
91
+ harness: {}, model: {}, eventSequence: lastSequence, artifactIds: [], inputFiles: [], artifacts: [], partialOutput: false,
92
+ extensions: {}, diagnostic,
93
+ };
94
+ }
95
+ /** Canonical Mission adapter consumed by UHP; the legacy evidence projection remains a compatibility view. */
96
+ export function projectUhpResponseToCanonicalMission(profile, response, request = { input: '' }, event) {
97
+ const evidence = projectUhpResponseToMission(profile, response, request, event);
98
+ return decodeMission({
99
+ ...evidence,
100
+ objective: typeof request.input === 'string' && request.input.length ? request.input : 'UHP task',
101
+ status: evidence.nativeState,
102
+ artifacts: evidence.artifacts.map(artifact => ({
103
+ id: artifact.fileId,
104
+ kind: 'uhp-file',
105
+ ...(artifact.mediaType ? { mediaType: artifact.mediaType } : {}),
106
+ ...(artifact.source.sha256 ? { sha256: artifact.source.sha256 } : {}),
107
+ extensions: { 'uhp.file': artifact.source },
108
+ })),
109
+ }, 'uhp-2026-08-11');
110
+ }
111
+ //# sourceMappingURL=mission.js.map
@@ -0,0 +1,76 @@
1
+ import { UhpError, redactUhpText } from './errors.js';
2
+ const TERMINAL_EVENTS = new Set(['response.completed', 'response.failed', 'response.incomplete', 'response.cancelled']);
3
+ export async function* parseUhpEventStream(body, options) {
4
+ const reader = body.getReader();
5
+ const decoder = new TextDecoder();
6
+ let buffer = '';
7
+ let expectedSequence = 0;
8
+ let terminalCount = 0;
9
+ let first = true;
10
+ const read = async () => {
11
+ let timer;
12
+ try {
13
+ return await Promise.race([
14
+ reader.read(),
15
+ new Promise((_, reject) => {
16
+ timer = setTimeout(() => reject(new UhpError('stream_inactivity_timeout', 'UHP stream became inactive; remote task state is unknown', { retryable: true, remoteState: 'unknown' })), options.inactivityTimeoutMs);
17
+ }),
18
+ ]);
19
+ }
20
+ finally {
21
+ if (timer)
22
+ clearTimeout(timer);
23
+ }
24
+ };
25
+ const decodeBlock = (block) => {
26
+ const data = block.split(/\r?\n/).filter(line => line.startsWith('data:')).map(line => line.slice(5).trimStart()).join('\n');
27
+ if (!data)
28
+ return undefined;
29
+ let event;
30
+ try {
31
+ event = JSON.parse(data);
32
+ }
33
+ catch {
34
+ throw new UhpError('malformed_sse', redactUhpText('Malformed JSON in UHP event stream', options.secrets), { remoteState: 'unknown' });
35
+ }
36
+ if (!Number.isSafeInteger(event.sequence_number) || event.sequence_number !== expectedSequence) {
37
+ throw new UhpError('event_sequence_gap', `Expected UHP event sequence ${expectedSequence}, received ${String(event.sequence_number)}`, { remoteState: 'unknown' });
38
+ }
39
+ if (first && event.type !== 'response.created')
40
+ throw new UhpError('invalid_first_event', `First UHP event must be response.created, received ${event.type}`, { remoteState: 'unknown' });
41
+ first = false;
42
+ expectedSequence += 1;
43
+ if (TERMINAL_EVENTS.has(event.type))
44
+ terminalCount += 1;
45
+ if (terminalCount > 1)
46
+ throw new UhpError('duplicate_terminal_event', 'UHP stream emitted more than one terminal event', { remoteState: 'unknown' });
47
+ return event;
48
+ };
49
+ try {
50
+ while (true) {
51
+ options.signal?.throwIfAborted();
52
+ const { done, value } = await read();
53
+ buffer += decoder.decode(value, { stream: !done });
54
+ const blocks = buffer.split(/\r?\n\r?\n/);
55
+ buffer = blocks.pop() ?? '';
56
+ for (const block of blocks) {
57
+ const event = decodeBlock(block);
58
+ if (event)
59
+ yield event;
60
+ }
61
+ if (done)
62
+ break;
63
+ }
64
+ if (buffer.trim()) {
65
+ const event = decodeBlock(buffer);
66
+ if (event)
67
+ yield event;
68
+ }
69
+ if (terminalCount !== 1)
70
+ throw new UhpError('missing_terminal_event', 'UHP stream ended without exactly one terminal event; remote task state is unknown', { retryable: true, remoteState: 'unknown' });
71
+ }
72
+ finally {
73
+ reader.releaseLock();
74
+ }
75
+ }
76
+ //# sourceMappingURL=sse.js.map
@@ -0,0 +1,2 @@
1
+ export const UHP_VERSION = '2026-08-11';
2
+ //# sourceMappingURL=types.js.map
@@ -16,6 +16,7 @@ import {
16
16
  loadInstallationIdentity,
17
17
  saveInstallationIdentity,
18
18
  } from '../installation/manager.mjs';
19
+ import { resolveManagerCommand } from '../installation/manager-command.mjs';
19
20
 
20
21
  const VALID_MODES = new Set(['npm', 'web', 'source']);
21
22
 
@@ -148,8 +149,9 @@ export async function updateInstallation(options = {}) {
148
149
  throw new Error('Canonical npm installation has no package-manager executable. Run `aiwg installation adopt --manager <absolute-path-to-npm>`.');
149
150
  }
150
151
  if (!dryRun) {
152
+ const invocation = resolveManagerCommand(managerExecutable, command, options);
151
153
  const execute = options.execute ?? ((file, args) => execFileSync(file, args, { stdio: 'inherit' }));
152
- execute(managerExecutable, command);
154
+ execute(invocation.file, invocation.args);
153
155
  if (detected.identity && detected.identityPersistent && options.persistIdentity !== false) {
154
156
  saveInstallationIdentity({ ...detected.identity, channel }, options);
155
157
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiwg/cli",
3
- "version": "2026.8.18",
3
+ "version": "2026.8.20",
4
4
  "description": "Lightweight AIWG CLI for signed, versioned web-backed resources.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -340,7 +340,7 @@ function mirrorSkillsAsCommands(provider, target, srcRoot, opts) {
340
340
  * @param {string|null} explicitSource the raw `--source` value (null when unset)
341
341
  */
342
342
  function pruneStaleAiwgArtifacts(provider, target, srcRoot, opts, explicitSource) {
343
- if (opts.skillsOnly) return; // skills run their own prune in the provider
343
+ if (opts.skillsOnly && !opts.kernelOnly) return; // skills run their own prune in the provider
344
344
 
345
345
  const aiwgRoot = resolveAiwgRoot(srcRoot);
346
346
  if (!aiwgRoot) return; // no AIWG tree → bundle/standalone deploy; never prune
@@ -355,6 +355,20 @@ function pruneStaleAiwgArtifacts(provider, target, srcRoot, opts, explicitSource
355
355
  if (!underCode) return; // project-local bundle / external source → skip
356
356
  }
357
357
 
358
+ if (opts.kernelOnly) {
359
+ for (const type of ['agents', 'commands', 'rules']) {
360
+ const relPath = provider.paths?.[type];
361
+ if (!relPath || relPath.endsWith('.md')) continue;
362
+ const destDir = path.isAbsolute(relPath) ? relPath : path.join(target, relPath);
363
+ pruneStaleAiwgFiles(destDir, new Set(), {
364
+ dryRun: opts.dryRun,
365
+ verbose: opts.verbose,
366
+ artifactExtensions: ['.md', '.mdc', '.toml'],
367
+ });
368
+ }
369
+ return;
370
+ }
371
+
358
372
  const typesThisRun = [];
359
373
  if (!opts.commandsOnly && !opts.rulesOnly) typesThisRun.push('agents');
360
374
  if (opts.deployCommands || opts.commandsOnly) typesThisRun.push('commands');
@@ -406,6 +420,7 @@ function parseArgs() {
406
420
  commandsOnly: false,
407
421
  skillsOnly: false,
408
422
  rulesOnly: false,
423
+ kernelOnly: false,
409
424
  filter: null, // Glob pattern for agent names
410
425
  filterRole: null, // Filter by role: reasoning|coding|efficiency
411
426
  save: false, // Save model config to project models.json
@@ -438,6 +453,7 @@ function parseArgs() {
438
453
  else if (a === '--commands-only') cfg.commandsOnly = true;
439
454
  else if (a === '--skills-only') cfg.skillsOnly = true;
440
455
  else if (a === '--rules-only') cfg.rulesOnly = true;
456
+ else if (a === '--kernel-only') cfg.kernelOnly = true;
441
457
  else if (a === '--deploy-behaviors') cfg.deployBehaviors = true;
442
458
  else if (a === '--filter' && args[i + 1]) cfg.filter = args[++i];
443
459
  else if (a === '--filter-role' && args[i + 1]) cfg.filterRole = args[++i];
@@ -474,6 +490,7 @@ Options:
474
490
  --commands-only Deploy only commands (skip agents)
475
491
  --skills-only Deploy only skills (skip agents)
476
492
  --rules-only Deploy only rules (skip agents)
493
+ --kernel-only Deploy kernel skills only and prune managed bulk artifacts
477
494
  --dry-run Show what would be deployed without writing
478
495
  --force Overwrite existing files
479
496
  --provider <name> Target provider (see below)
@@ -490,7 +507,9 @@ Options:
490
507
  --create-agents-md Create/update AGENTS.md template
491
508
  --skip-commands-migration Skip deleting the commands directory before skills deployment
492
509
  --copy-all Copy ALL skills per-project (legacy mirror at <provider>/.aiwg/skills/).
493
- Default is kernel-only + index-driven discovery for the rest (#1217).
510
+ For aiwg use all, this also restores the legacy full agent,
511
+ command, and expanded-rule copy. Default bulk deployment is
512
+ kernel-only + index-driven discovery for the rest (#1217).
494
513
  Use this for sandboxed runtimes / air-gapped corpora where
495
514
  $AIWG_ROOT isn't readable from the agent's working dir.
496
515
  Alias: --copy-standard-skills — rc.29 era).
@@ -879,13 +898,14 @@ export async function main() {
879
898
  modelsConfig,
880
899
  asAgentsMd: cfg.asAgentsMd,
881
900
  createAgentsMd: cfg.createAgentsMd,
882
- deployCommands: cfg.deployCommands,
883
- deploySkills: cfg.deploySkills,
884
- deployRules: cfg.deployRules,
885
- deployBehaviors: cfg.deployBehaviors,
901
+ deployCommands: cfg.kernelOnly ? false : cfg.deployCommands,
902
+ deploySkills: cfg.kernelOnly ? true : cfg.deploySkills,
903
+ deployRules: cfg.kernelOnly ? false : cfg.deployRules,
904
+ deployBehaviors: cfg.kernelOnly ? false : cfg.deployBehaviors,
886
905
  commandsOnly: cfg.commandsOnly,
887
- skillsOnly: cfg.skillsOnly,
906
+ skillsOnly: cfg.skillsOnly || cfg.kernelOnly,
888
907
  rulesOnly: cfg.rulesOnly,
908
+ kernelOnly: cfg.kernelOnly,
889
909
  filter: cfg.filter,
890
910
  filterRole: cfg.filterRole,
891
911
  save: cfg.save,
@@ -893,7 +913,7 @@ export async function main() {
893
913
  verbose: cfg.verbose,
894
914
  quiet: cfg.quiet,
895
915
  asPlugin: cfg.asPlugin,
896
- deployBehaviors: cfg.deployBehaviors,
916
+ deployBehaviors: cfg.kernelOnly ? false : cfg.deployBehaviors,
897
917
  skipCommandsMigration: cfg.skipCommandsMigration,
898
918
  // #1217 / #1219: --copy-all flag forces legacy per-project mirror
899
919
  // for the standard tier. Default is no-copy + index-driven discovery.
@@ -1183,7 +1183,7 @@ export function computeAllKernelNames(srcRoot) {
1183
1183
  * located — see `computeAllKernelNames`), pruning is skipped entirely so a
1184
1184
  * project-local-bundle deploy without AIWG_ROOT never empties the kernel
1185
1185
  * skills directory (#123).
1186
- * @param {object} opts `{ dryRun, verbose }`
1186
+ * @param {object} opts `{ dryRun, verbose, artifactExtensions }`
1187
1187
  * @returns {number} count of pruned entries
1188
1188
  */
1189
1189
  export function pruneStaleAiwgSkills(kernelDestDir, desiredKernelNames, opts = {}) {
@@ -1348,7 +1348,8 @@ export function resolveAiwgRoot(srcRoot) {
1348
1348
  * `pruneStaleAiwgSkills`.
1349
1349
  *
1350
1350
  * Removes a file from `destDir` only when ALL hold:
1351
- * 1. It is a deployed artifact file (`.md` / `.mdc`), not `RULES-INDEX.md`
1351
+ * 1. It has an allowed deployed-artifact extension (`.md` / `.mdc` by
1352
+ * default; callers may include `.toml`), is not `RULES-INDEX.md`,
1352
1353
  * and not the sidecar manifest.
1353
1354
  * 2. Its stem is NOT in `desiredStems` (the source no longer ships it).
1354
1355
  * 3. It carries an AIWG ownership signal — either a `.aiwg-manifest.json`
@@ -1369,6 +1370,7 @@ export function resolveAiwgRoot(srcRoot) {
1369
1370
  */
1370
1371
  export function pruneStaleAiwgFiles(destDir, desiredStems, opts = {}) {
1371
1372
  const { dryRun = false, verbose = false } = opts;
1373
+ const artifactExtensions = opts.artifactExtensions || ['.md', '.mdc'];
1372
1374
  const removed = [];
1373
1375
  if (!destDir || !fs.existsSync(destDir)) return removed;
1374
1376
 
@@ -1391,7 +1393,7 @@ export function pruneStaleAiwgFiles(destDir, desiredStems, opts = {}) {
1391
1393
  if (name === 'RULES-INDEX.md') continue;
1392
1394
  if (name === 'RULES-ONDEMAND.md') continue; // generated on-demand index (#1673)
1393
1395
  const lower = name.toLowerCase();
1394
- if (!lower.endsWith('.md') && !lower.endsWith('.mdc')) continue;
1396
+ if (!artifactExtensions.some(extension => lower.endsWith(extension))) continue;
1395
1397
 
1396
1398
  if (desired.has(artifactStem(name))) continue;
1397
1399