@aiwg/cli 2026.10.11 → 2026.10.14

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 (174) hide show
  1. package/agentic/code/providers/model-catalog.v1.json +62 -12
  2. package/agentic/code/providers/pi/aiwg-bridge.ts +44 -1
  3. package/dist/src/artifacts/binding-target-identity.js +51 -0
  4. package/dist/src/artifacts/checksum-manifest.js +12 -0
  5. package/dist/src/artifacts/index-builder.js +11 -13
  6. package/dist/src/artifacts/query-engine.js +5 -11
  7. package/dist/src/cli/handlers/doctor-help.js +32 -0
  8. package/dist/src/cli/handlers/gates.js +19 -18
  9. package/dist/src/cli/handlers/models-help.js +7 -1
  10. package/dist/src/cli/handlers/models.js +3 -3
  11. package/dist/src/cli/handlers/script-runner.js +8 -5
  12. package/dist/src/cli/handlers/sessions-intake.js +104 -0
  13. package/dist/src/cli/handlers/sessions-tail.js +172 -0
  14. package/dist/src/cli/handlers/sessions.js +90 -17
  15. package/dist/src/cli/handlers/skill-lint.js +10 -3
  16. package/dist/src/cli/handlers/steward-format.js +100 -0
  17. package/dist/src/cli/handlers/steward-models.js +167 -0
  18. package/dist/src/cli/handlers/steward.js +14 -248
  19. package/dist/src/cli/handlers/use-bundle-counts.js +87 -0
  20. package/dist/src/cli/handlers/use-skill-assets.js +207 -0
  21. package/dist/src/cli/handlers/use.js +35 -216
  22. package/dist/src/cli/handlers/utilities.js +1 -24
  23. package/dist/src/config/aiwg-config.js +7 -0
  24. package/dist/src/config/authorization-cli.js +97 -0
  25. package/dist/src/config/cli-help.js +1 -0
  26. package/dist/src/config/cli.js +10 -1
  27. package/dist/src/decision/context-pruning-common.js +41 -0
  28. package/dist/src/decision/context-pruning-evaluation.js +366 -0
  29. package/dist/src/decision/context-pruning-pilot.js +431 -0
  30. package/dist/src/decision/context-pruning-types.js +19 -0
  31. package/dist/src/decision/context-pruning.js +5 -846
  32. package/dist/src/decision/ensemble/contract.js +17 -26
  33. package/dist/src/decision/ensemble-study/artifacts.js +5 -0
  34. package/dist/src/decision/ensemble-study/score.js +4 -3
  35. package/dist/src/decision/feature-export.js +3 -9
  36. package/dist/src/decision/heldout/collector.js +2 -2
  37. package/dist/src/decision/issue-triage/runtime.js +3 -9
  38. package/dist/src/decision/qualification/gates.js +2 -1
  39. package/dist/src/decision/qualification/release.js +6 -64
  40. package/dist/src/decision/routing/report.js +2 -0
  41. package/dist/src/decision/sdlc-screening.js +3 -5
  42. package/dist/src/decision/sensitivity/comparative.js +5 -3
  43. package/dist/src/extensions/manifest.js +8 -1
  44. package/dist/src/extensions/project-local-doctor.js +78 -2
  45. package/dist/src/extensions/validation.js +10 -11
  46. package/dist/src/gates/driver.js +6 -77
  47. package/dist/src/gates/evaluate.js +6 -23
  48. package/dist/src/gates/floors.js +4 -4
  49. package/dist/src/gates/index.js +3 -3
  50. package/dist/src/gates/lattice.js +26 -0
  51. package/dist/src/gates/registry.js +2 -1
  52. package/dist/src/gates/report.js +19 -7
  53. package/dist/src/gates/upstream-ceiling.js +111 -0
  54. package/dist/src/issues/audit-cli.js +120 -0
  55. package/dist/src/issues/audit-contract.js +64 -0
  56. package/dist/src/issues/audit-local.js +82 -0
  57. package/dist/src/issues/audit.js +220 -0
  58. package/dist/src/lint/rule-activation.js +15 -1
  59. package/dist/src/mission-protocol/canonical-codecs.js +270 -0
  60. package/dist/src/mission-protocol/codecs.js +22 -550
  61. package/dist/src/mission-protocol/health-trace-codecs.js +281 -0
  62. package/dist/src/mission-protocol/health-trace-types.js +43 -0
  63. package/dist/src/mission-protocol/types.js +2 -42
  64. package/dist/src/mission-protocol/worker-contract-json.js +10 -0
  65. package/dist/src/mission-protocol/worker-review-gate.js +100 -0
  66. package/dist/src/mission-protocol/worker-review-types.js +2 -0
  67. package/dist/src/models/catalog-policy.js +280 -0
  68. package/dist/src/models/index.js +1 -1
  69. package/dist/src/models/model-catalog.v1.json +62 -12
  70. package/dist/src/models/policy-resources.js +28 -0
  71. package/dist/src/models/provider-models.js +5 -8
  72. package/dist/src/models/provider-policy.js +10 -546
  73. package/dist/src/models/resolver.js +26 -8
  74. package/dist/src/models/router.js +15 -2
  75. package/dist/src/models/tiers.js +13 -0
  76. package/dist/src/models/types.js +0 -6
  77. package/dist/src/models/worker-ceilings.js +59 -0
  78. package/dist/src/models/worker-invocation-policy.js +243 -0
  79. package/dist/src/models/worker-plan.js +16 -20
  80. package/dist/src/models/worker-review-lineage.js +55 -0
  81. package/dist/src/models/worker-selection-policy.js +1 -1
  82. package/dist/src/models/wrapper-definitions.js +14 -0
  83. package/dist/src/models/wrapper-deployment.js +48 -25
  84. package/dist/src/models/wrapper-enforcement.js +72 -0
  85. package/dist/src/models/wrapper-route.js +6 -3
  86. package/dist/src/policy/authorization.js +1 -0
  87. package/dist/src/policy/hitl-check.js +80 -0
  88. package/dist/src/policy/hitl-config.js +63 -0
  89. package/dist/src/policy/hitl-receipt.js +57 -0
  90. package/dist/src/policy/hitl-types.js +4 -0
  91. package/dist/src/policy/hitl-validation.js +39 -0
  92. package/dist/src/policy/hitl.js +117 -0
  93. package/dist/src/rules/activation.d.mts +3 -1
  94. package/dist/src/rules/activation.mjs +23 -2
  95. package/dist/src/rules/gate-coverage.js +51 -0
  96. package/dist/src/rules/gate-references.js +16 -0
  97. package/dist/src/rules/rule-frontmatter.schema.json +7 -1
  98. package/dist/src/serve/worker-command-request.js +21 -4
  99. package/dist/src/serve/worker-invocation-preparation.js +3 -1
  100. package/dist/src/serve/worker-invocation.js +21 -10
  101. package/dist/src/sessions/adapters/deepseek-harness.js +1 -0
  102. package/dist/src/sessions/adapters/grok-build-native.js +269 -0
  103. package/dist/src/sessions/adapters/grok-build.js +57 -15
  104. package/dist/src/sessions/adapters/hermes-state-db.js +252 -0
  105. package/dist/src/sessions/adapters/hermes.js +42 -3
  106. package/dist/src/sessions/adapters/warp.js +1 -1
  107. package/dist/src/sessions/batch-import.js +10 -0
  108. package/dist/src/sessions/contracts.js +1 -1
  109. package/dist/src/sessions/discovery-capability.js +38 -0
  110. package/dist/src/sessions/importer.js +8 -251
  111. package/dist/src/sessions/index.js +4 -0
  112. package/dist/src/sessions/intake-dir.js +71 -0
  113. package/dist/src/sessions/normalization.js +251 -0
  114. package/dist/src/sessions/tail.js +91 -0
  115. package/dist/src/sessions/workspace-discovery.js +83 -7
  116. package/dist/src/skills/adapters/local.js +32 -9
  117. package/dist/src/skills/agent-skill-sidecar.js +28 -0
  118. package/dist/src/skills/agent-skills.js +6 -23
  119. package/dist/src/skills/claude-surface-projection.js +25 -0
  120. package/dist/src/skills/cli-display.js +33 -0
  121. package/dist/src/skills/cli.js +2 -26
  122. package/dist/src/skills/collision-discovery.js +84 -0
  123. package/dist/src/skills/deployer.js +26 -361
  124. package/dist/src/skills/deployment-ownership.js +74 -0
  125. package/dist/src/skills/deployment-policy.js +114 -0
  126. package/dist/src/skills/deployment-projection.js +152 -0
  127. package/dist/src/skills/deployment-types.js +20 -0
  128. package/dist/src/skills/doctor.js +2 -2
  129. package/dist/src/skills/exporter.js +8 -31
  130. package/dist/src/skills/importer.js +4 -26
  131. package/dist/src/skills/provider-extensions.js +41 -0
  132. package/dist/src/skills/registry.js +22 -7
  133. package/dist/src/skills/run.js +6 -0
  134. package/dist/src/skills/types.js +0 -8
  135. package/dist/src/skills/validator-resources.js +68 -0
  136. package/dist/src/skills/validator.js +6 -55
  137. package/dist/src/smiths/context-pipeline/parallelism-section.js +7 -3
  138. package/dist/src/storage/cli-migrate-options.js +125 -0
  139. package/dist/src/storage/cli-migrate.js +111 -0
  140. package/dist/src/storage/cli.js +4 -279
  141. package/dist/src/storage/migration-adapter.js +79 -0
  142. package/dist/src/storage/migration-copy.js +108 -0
  143. package/dist/src/storage/migration-protocol.js +14 -197
  144. package/dist/src/storage/migration-records.js +186 -0
  145. package/dist/src/storage/migration-types.js +12 -0
  146. package/dist/src/tracker/forge-http.js +2 -1
  147. package/dist/src/tracker/issue-pages.js +110 -0
  148. package/package.json +3 -1
  149. package/schemas/mission-v1.schema.json +335 -0
  150. package/schemas/models/model-catalog.v1.schema.json +19 -1
  151. package/schemas/models/model-config-compatibility.v1.schema.json +3 -2
  152. package/schemas/models/model-policy.v1.schema.json +1 -1
  153. package/tools/agents/providers/antigravity.mjs +3 -5
  154. package/tools/agents/providers/base.mjs +3 -3
  155. package/tools/agents/providers/claude.mjs +3 -5
  156. package/tools/agents/providers/codex.mjs +3 -5
  157. package/tools/agents/providers/copilot.mjs +3 -5
  158. package/tools/agents/providers/cursor.mjs +3 -5
  159. package/tools/agents/providers/factory.mjs +3 -5
  160. package/tools/agents/providers/grok-build.mjs +9 -7
  161. package/tools/agents/providers/model-wrapper.mjs +86 -0
  162. package/tools/agents/providers/omp.mjs +3 -1
  163. package/tools/agents/providers/openclaw.mjs +3 -5
  164. package/tools/agents/providers/opencode.mjs +3 -5
  165. package/tools/agents/providers/provider-paths-staging.mjs +44 -0
  166. package/tools/agents/providers/rule-binding-targets.mjs +146 -0
  167. package/tools/agents/providers/rule-delivery.mjs +9 -128
  168. package/tools/agents/providers/warp.mjs +3 -5
  169. package/tools/agents/providers/windsurf.mjs +3 -5
  170. package/tools/plugin/package-plugins.mjs +2 -2
  171. package/tools/skills/codex-skill-transform.mjs +232 -0
  172. package/tools/skills/deploy-skills-codex.mjs +8 -249
  173. package/tools/warp/warp-content.mjs +548 -0
  174. package/vscode-extension/schemas/aiwg.config.v1.json +177 -0
@@ -0,0 +1,252 @@
1
+ // Hermes state.db snapshot reader: read-only backup, schema-gated projection (synthetic physical schema v1).
2
+ import { chmod, lstat, mkdir, realpath, rm, stat, writeFile } from 'node:fs/promises';
3
+ import { join, resolve } from 'node:path';
4
+ import { sha256, SessionContractError } from '../contracts.js';
5
+ import { requireFeaturePackage } from '../../features/runtime.js';
6
+ import { matchSessionWorkspace } from '../workspace-matching.js';
7
+ export const HERMES_STATE_DB_FILENAME = 'state.db';
8
+ export const HERMES_NATIVE_PHYSICAL_SCHEMA = 'hermes-synthetic-v1';
9
+ export const HERMES_SNAPSHOT_LOCATOR_CLASS = 'hermes-consistent-snapshot-jsonl';
10
+ const STAGING_DIR_MODE = 0o700;
11
+ const FILE_MODE = 0o600;
12
+ const MAX_SOURCE_BYTES = 1024 * 1024 * 1024;
13
+ const MAX_SESSIONS = 1_000_000;
14
+ /** Owned staging beneath the workspace session store; never inside the provider tree. */
15
+ export function hermesSnapshotStagingDir(workspacePath) {
16
+ return join(resolve(workspacePath), '.aiwg', 'sessions', 'staging', 'hermes');
17
+ }
18
+ export function hermesSnapshotProjectionPath(stagingDir, canonicalRoot) {
19
+ return join(stagingDir, `state-${sha256(canonicalRoot).slice(7, 23)}.snapshot.jsonl`);
20
+ }
21
+ function loadSqlite() {
22
+ try {
23
+ return requireFeaturePackage('better-sqlite3');
24
+ }
25
+ catch {
26
+ throw new SessionContractError('UNSUPPORTED_OPERATION', 'Hermes native discovery requires the optional sqlite backend; '
27
+ + 'run `aiwg features install sqlite`, then rediscover with --hermes-root.');
28
+ }
29
+ }
30
+ function sqliteUnavailable(error, what) {
31
+ if (error instanceof SessionContractError)
32
+ throw error;
33
+ const code = typeof error.code === 'string'
34
+ ? error.code
35
+ : 'SQLITE_ERROR';
36
+ return new SessionContractError('UNSUPPORTED_OPERATION', `Hermes snapshot is unavailable while ${what} (sqlite ${code}); `
37
+ + 'start Hermes so a consistent backup can be taken without writing to its directory, '
38
+ + 'or import a `hermes sessions export` file instead.');
39
+ }
40
+ /**
41
+ * WAL reads need the provider's shared-memory index, and any first read
42
+ * would create it as a provider-tree write. A WAL database without its
43
+ * sidecars present therefore refuses BEFORE any SQLite contact — fail closed
44
+ * rather than writing sidecars or reopening writable. (Hermes runs WAL mode;
45
+ * the export fallback covers a stopped provider.) When the index pre-exists,
46
+ * the read-only open reuses it without creating files; its volatile
47
+ * read-marks may advance through normal WAL read concurrency — the same as
48
+ * any Hermes reader — but tree membership, sizes, and database content never
49
+ * change.
50
+ */
51
+ async function assertReadableWithoutSidecarWrites(live) {
52
+ const shm = await lstat(`${live}-shm`).then((item) => item.isFile()).catch(() => false);
53
+ if (!shm) {
54
+ throw new SessionContractError('UNSUPPORTED_OPERATION', 'Hermes snapshot needs the provider WAL sidecars (state.db-shm); '
55
+ + 'start Hermes so a consistent backup can be taken without writing to its directory, '
56
+ + 'or import a `hermes sessions export` file instead.');
57
+ }
58
+ }
59
+ async function authorizeLiveDb(liveDbPath, allowedRoots) {
60
+ if (allowedRoots.length === 0) {
61
+ throw new SessionContractError('SOURCE_NOT_AUTHORIZED', 'Hermes discovery requires --hermes-root.');
62
+ }
63
+ const selected = resolve(liveDbPath);
64
+ const link = await lstat(selected).catch(() => null);
65
+ if (!link) {
66
+ throw new SessionContractError('SOURCE_NOT_AUTHORIZED', 'Hermes state.db is not available under --hermes-root.');
67
+ }
68
+ if (link.isSymbolicLink()) {
69
+ throw new SessionContractError('SOURCE_SYMLINK', 'Hermes state.db cannot be a symlink.');
70
+ }
71
+ const canonical = await realpath(selected).catch(() => null);
72
+ if (!canonical) {
73
+ throw new SessionContractError('SOURCE_NOT_AUTHORIZED', 'Hermes state.db is not available under --hermes-root.');
74
+ }
75
+ const canonicalRoots = await Promise.all(allowedRoots.map(async (root) => resolve(root)));
76
+ const inside = canonicalRoots.some((root) => canonical === root || canonical.startsWith(`${root}/`));
77
+ if (!inside) {
78
+ throw new SessionContractError('SOURCE_OUTSIDE_ALLOWED_ROOT', 'Hermes state.db escapes the authorized roots.');
79
+ }
80
+ const details = await stat(canonical);
81
+ if (!details.isFile()) {
82
+ throw new SessionContractError('SOURCE_NOT_REGULAR_FILE', 'Hermes state.db must be a regular file.');
83
+ }
84
+ if (details.size > MAX_SOURCE_BYTES) {
85
+ throw new SessionContractError('RESOURCE_LIMIT_EXCEEDED', 'Hermes state.db exceeds the snapshot byte limit', {
86
+ limit: 'maxBytes', configured: MAX_SOURCE_BYTES, observed: details.size,
87
+ });
88
+ }
89
+ return canonical;
90
+ }
91
+ const REQUIRED_SESSION_COLUMNS = new Set([
92
+ 'id', 'source', 'user_id', 'model', 'model_config', 'parent_session_id',
93
+ 'compressed_from_session_id', 'started_at', 'ended_at', 'end_reason',
94
+ 'archived', 'inactive', 'cwd', 'git_branch', 'routing_key', 'input_tokens',
95
+ 'output_tokens', 'cache_read_tokens', 'cache_write_tokens', 'reasoning_tokens',
96
+ 'estimated_cost_usd', 'actual_cost_usd', 'billing_provider',
97
+ 'export_deleted_at', 'provider_deleted_at',
98
+ ]);
99
+ const REQUIRED_MESSAGE_COLUMNS = new Set([
100
+ 'session_id', 'seq', 'id', 'role', 'content', 'tool_call_id', 'tool_calls',
101
+ 'tool_name', 'timestamp', 'token_count', 'finish_reason', 'reasoning',
102
+ 'reasoning_content', 'reasoning_details', 'codex_reasoning_items',
103
+ ]);
104
+ function assertPhysicalSchema(backup) {
105
+ const tables = new Set(backup.prepare("SELECT name FROM sqlite_master WHERE type = 'table'").all().map((row) => String(row.name)));
106
+ if (!tables.has('meta') || !tables.has('sessions') || !tables.has('messages')) {
107
+ throw new SessionContractError('SCHEMA_DRIFT', 'unrecognized Hermes state.db physical schema', { issues: [{ path: 'tables', code: 'custom' }] });
108
+ }
109
+ const marker = backup.prepare('SELECT value FROM meta WHERE key = ?').get('native_schema');
110
+ if (!marker || marker.value !== HERMES_NATIVE_PHYSICAL_SCHEMA) {
111
+ throw new SessionContractError('SCHEMA_DRIFT', 'unsupported Hermes state.db physical schema version', { issues: [{ path: 'meta.native_schema', code: 'custom' }] });
112
+ }
113
+ for (const [table, required] of [['sessions', REQUIRED_SESSION_COLUMNS], ['messages', REQUIRED_MESSAGE_COLUMNS]]) {
114
+ const columns = new Set(backup.prepare(`PRAGMA table_info(${table})`).all().map((row) => String(row.name)));
115
+ for (const column of required) {
116
+ if (!columns.has(column)) {
117
+ throw new SessionContractError('SCHEMA_DRIFT', `Hermes state.db table ${table} is missing column ${column}`, { issues: [{ path: `${table}.${column}`, code: 'custom' }] });
118
+ }
119
+ }
120
+ }
121
+ }
122
+ function parseJsonColumn(value, path) {
123
+ if (value === null || value === undefined)
124
+ return undefined;
125
+ if (typeof value !== 'string')
126
+ return value;
127
+ try {
128
+ return JSON.parse(value);
129
+ }
130
+ catch {
131
+ throw new SessionContractError('SCHEMA_DRIFT', `Hermes state.db column ${path} is not valid JSON`, { issues: [{ path, code: 'invalid_json' }] });
132
+ }
133
+ }
134
+ function optional(value) {
135
+ return value === null || value === undefined ? undefined : value;
136
+ }
137
+ /**
138
+ * Take a consistent backup of the live database (never opened for writing)
139
+ * and project workspace-matching sessions to snapshot JSONL. Returns null
140
+ * when no session matches the authorized workspace.
141
+ */
142
+ export async function snapshotHermesStateDb(options) {
143
+ const canonicalRoot = await realpath(resolve(options.hermesRoot)).catch(() => resolve(options.hermesRoot));
144
+ const live = await authorizeLiveDb(join(options.hermesRoot, HERMES_STATE_DB_FILENAME), options.allowedRoots);
145
+ await assertReadableWithoutSidecarWrites(live);
146
+ const Database = loadSqlite();
147
+ await mkdir(options.stagingDir, { recursive: true, mode: STAGING_DIR_MODE });
148
+ const staging = await realpath(options.stagingDir);
149
+ const backupPath = join(staging, `.backup-${process.pid}-${Date.now()}.db`);
150
+ const projectionPath = hermesSnapshotProjectionPath(staging, canonicalRoot);
151
+ let source;
152
+ let backup;
153
+ try {
154
+ source = new Database(live, { readonly: true, fileMustExist: true });
155
+ await source.backup(backupPath);
156
+ }
157
+ catch (error) {
158
+ throw sqliteUnavailable(error, 'opening the provider database for backup');
159
+ }
160
+ finally {
161
+ source?.close();
162
+ }
163
+ try {
164
+ backup = new Database(backupPath, { readonly: true, fileMustExist: true });
165
+ assertPhysicalSchema(backup);
166
+ const sessions = backup.prepare('SELECT * FROM sessions ORDER BY started_at ASC, id ASC').all();
167
+ const lines = [];
168
+ let matched = 0;
169
+ let excluded = 0;
170
+ let bytes = 0;
171
+ for (const row of sessions) {
172
+ if (matched + excluded >= MAX_SESSIONS) {
173
+ throw new SessionContractError('RESOURCE_LIMIT_EXCEEDED', 'Hermes snapshot exceeds the session limit', {
174
+ limit: 'maxSessions', configured: MAX_SESSIONS, observed: matched + excluded + 1,
175
+ });
176
+ }
177
+ const cwd = typeof row.cwd === 'string' && row.cwd.length > 0 ? row.cwd : null;
178
+ const workspaceMatch = cwd ? await matchSessionWorkspace(cwd, options.workspaceId) : null;
179
+ if (!workspaceMatch) {
180
+ excluded += 1;
181
+ continue;
182
+ }
183
+ const messages = backup.prepare('SELECT * FROM messages WHERE session_id = ? ORDER BY seq ASC').all(String(row.id));
184
+ const record = {
185
+ schemaVersion: 23,
186
+ id: String(row.id),
187
+ source: String(row.source ?? 'cli'),
188
+ user_id: optional(row.user_id),
189
+ model: optional(row.model),
190
+ model_config: parseJsonColumn(row.model_config, 'sessions.model_config'),
191
+ parent_session_id: optional(row.parent_session_id),
192
+ compressed_from_session_id: optional(row.compressed_from_session_id),
193
+ started_at: row.started_at,
194
+ ended_at: optional(row.ended_at),
195
+ end_reason: optional(row.end_reason),
196
+ archived: row.archived,
197
+ inactive: row.inactive,
198
+ cwd,
199
+ git_branch: optional(row.git_branch),
200
+ routing_key: optional(row.routing_key),
201
+ input_tokens: optional(row.input_tokens),
202
+ output_tokens: optional(row.output_tokens),
203
+ cache_read_tokens: optional(row.cache_read_tokens),
204
+ cache_write_tokens: optional(row.cache_write_tokens),
205
+ reasoning_tokens: optional(row.reasoning_tokens),
206
+ estimated_cost_usd: optional(row.estimated_cost_usd),
207
+ actual_cost_usd: optional(row.actual_cost_usd),
208
+ billing_provider: optional(row.billing_provider),
209
+ messages: messages.map((message) => ({
210
+ id: message.id,
211
+ role: String(message.role),
212
+ content: parseJsonColumn(message.content, 'messages.content'),
213
+ tool_call_id: optional(message.tool_call_id),
214
+ tool_calls: parseJsonColumn(message.tool_calls, 'messages.tool_calls'),
215
+ tool_name: optional(message.tool_name),
216
+ timestamp: optional(message.timestamp),
217
+ token_count: optional(message.token_count),
218
+ finish_reason: optional(message.finish_reason),
219
+ reasoning: optional(message.reasoning),
220
+ reasoning_content: optional(message.reasoning_content),
221
+ reasoning_details: parseJsonColumn(message.reasoning_details, 'messages.reasoning_details'),
222
+ codex_reasoning_items: parseJsonColumn(message.codex_reasoning_items, 'messages.codex_reasoning_items'),
223
+ })),
224
+ export_deleted_at: optional(row.export_deleted_at),
225
+ provider_deleted_at: optional(row.provider_deleted_at),
226
+ snapshotConsistency: 'sqlite-backup',
227
+ };
228
+ const line = `${JSON.stringify(record)}\n`;
229
+ bytes += Buffer.byteLength(line);
230
+ if (bytes > MAX_SOURCE_BYTES) {
231
+ throw new SessionContractError('RESOURCE_LIMIT_EXCEEDED', 'Hermes snapshot exceeds the projection byte limit', {
232
+ limit: 'maxBytes', configured: MAX_SOURCE_BYTES, observed: bytes,
233
+ });
234
+ }
235
+ lines.push(line);
236
+ matched += 1;
237
+ }
238
+ if (matched === 0)
239
+ return null;
240
+ await writeFile(projectionPath, lines.join(''), { mode: FILE_MODE });
241
+ await chmod(projectionPath, FILE_MODE);
242
+ return { projectionPath, authorizedRoot: staging, matched, excluded };
243
+ }
244
+ catch (error) {
245
+ throw sqliteUnavailable(error, 'reading the snapshot');
246
+ }
247
+ finally {
248
+ backup?.close();
249
+ await rm(backupPath, { force: true });
250
+ }
251
+ }
252
+ //# sourceMappingURL=hermes-state-db.js.map
@@ -1,7 +1,10 @@
1
+ import { lstat } from 'node:fs/promises';
2
+ import { join } from 'node:path';
1
3
  import { z } from 'zod';
2
4
  import { number } from '../../schema/zod-validation.mjs';
3
5
  import { schemaRejectionDetail, schemaIssueDetail, SessionContractError, assertSupportedSchemaMajor, } from '../contracts.js';
4
6
  import { streamBoundedJsonLines, } from '../readers.js';
7
+ import { HERMES_SNAPSHOT_LOCATOR_CLASS, HERMES_STATE_DB_FILENAME, hermesSnapshotStagingDir, snapshotHermesStateDb, } from './hermes-state-db.js';
5
8
  export const HERMES_ADAPTER_VERSION = '1.0.0';
6
9
  export const HERMES_EXPORT_SCHEMA_VERSION = '1.0.0';
7
10
  export const HERMES_NATIVE_SCHEMA_VERSION = '23.0.0';
@@ -64,14 +67,42 @@ export class HermesSessionAdapter {
64
67
  provider = 'hermes';
65
68
  adapterVersion = HERMES_ADAPTER_VERSION;
66
69
  disposition = 'implemented';
67
- supportedOperations = ['inspect', 'stream'];
70
+ supportedOperations = ['discover', 'inspect', 'stream'];
68
71
  acquisitionModes = ['jsonl', 'api', 'sqlite-snapshot'];
69
72
  constructor(limits, localApi) {
70
73
  this.limits = limits;
71
74
  this.localApi = localApi;
72
75
  }
73
- async *discover(_scope) {
74
- // Native exports and consistent snapshots require explicit selection.
76
+ /**
77
+ * Discover through a consistent `sqlite3.backup()` snapshot of the
78
+ * explicitly authorized `<root>/state.db`. The live database is never
79
+ * opened for writing and never streamed directly; matching sessions are
80
+ * projected to an owned staging snapshot the existing consistent-snapshot
81
+ * path already validates.
82
+ */
83
+ async *discover(scope) {
84
+ if (scope.allowedRoots.length === 0) {
85
+ throw new SessionContractError('SOURCE_NOT_AUTHORIZED', 'Hermes discovery requires an explicitly authorized Hermes home; pass --hermes-root.');
86
+ }
87
+ const staging = hermesSnapshotStagingDir(scope.workspaceId);
88
+ for (const root of [...scope.allowedRoots].sort()) {
89
+ if (!(await isStateDbFile(join(root, HERMES_STATE_DB_FILENAME))))
90
+ continue;
91
+ const snapshot = await snapshotHermesStateDb({
92
+ hermesRoot: root,
93
+ stagingDir: staging,
94
+ allowedRoots: scope.allowedRoots,
95
+ workspaceId: scope.workspaceId,
96
+ limits: this.limits,
97
+ });
98
+ if (!snapshot)
99
+ continue;
100
+ yield {
101
+ provider: 'hermes',
102
+ locator: snapshot.projectionPath,
103
+ locatorClass: HERMES_SNAPSHOT_LOCATOR_CLASS,
104
+ };
105
+ }
75
106
  }
76
107
  async inspect(source) {
77
108
  if (source.locatorClass === 'hermes-export-jsonl'
@@ -284,6 +315,14 @@ function normalizeMessage(sessionId, message, index, line, locatorClass, common)
284
315
  }));
285
316
  return records;
286
317
  }
318
+ async function isStateDbFile(path) {
319
+ try {
320
+ return (await lstat(path)).isFile();
321
+ }
322
+ catch {
323
+ return false;
324
+ }
325
+ }
287
326
  function ended(value) {
288
327
  return Boolean(value.ended_at || value.provider_deleted_at || value.archived || value.inactive);
289
328
  }
@@ -50,7 +50,7 @@ export class WarpSessionAdapter {
50
50
  if (blocks.length === 0) {
51
51
  throw new SessionContractError('MALFORMED_SOURCE', 'Warp Markdown export contains no recognized user or assistant conversation blocks', schemaIssueDetail('headings'));
52
52
  }
53
- const stableSessionId = `manual:${createHash('sha256').update(value).digest('hex').slice(0, 32)}`;
53
+ const stableSessionId = source.nativeSessionId ?? `manual:${createHash('sha256').update(value).digest('hex').slice(0, 32)}`;
54
54
  const lifecycleEvidence = /<!--\s*warp-lifecycle:\s*complete\s*-->/i.test(value)
55
55
  ? 'completed-at-import' : 'unknown-at-import';
56
56
  const title = /^#\s+(.+)$/m.exec(value)?.[1]?.trim();
@@ -327,6 +327,16 @@ function providerProfile(provider, locatorClass) {
327
327
  return 'muse-native-session-log-v1';
328
328
  if (provider === 'grokbot')
329
329
  return 'grokbot-native-transcript-replica-v1';
330
+ if (provider === 'grok-build') {
331
+ return locatorClass === 'grok-build-native-chat-history'
332
+ ? 'grok-build-native-chat-history-v1'
333
+ : 'documented-cli-markdown-export';
334
+ }
335
+ if (provider === 'hermes') {
336
+ return locatorClass === 'hermes-consistent-snapshot-jsonl'
337
+ ? 'native-state-db-backup-snapshot-v1'
338
+ : 'native-schema-23-export';
339
+ }
330
340
  return 'manual-interchange';
331
341
  }
332
342
  function importErrorCode(error) {
@@ -76,7 +76,7 @@ export const SessionErrorCodeSchema = z.enum([
76
76
  'OPERATION_NOT_AUTHORIZED',
77
77
  'IMPORT_CONFLICT', 'IMPORT_INTERRUPTED', 'MALFORMED_SOURCE',
78
78
  'DUPLICATE_NATIVE_ID', 'AMBIGUOUS_TIMESTAMP', 'TRUNCATED_SOURCE',
79
- 'UNSUPPORTED_OPERATION',
79
+ 'UNSUPPORTED_OPERATION', 'UNSUPPORTED_PROVIDER',
80
80
  'INVALID_SEARCH_QUERY', 'INVALID_ARGUMENT',
81
81
  ]);
82
82
  const VersionSchema = z.string().regex(/^\d+\.\d+\.\d+(?:[-+].+)?$/);
@@ -0,0 +1,38 @@
1
+ const REQUIRED_FLAGS = {
2
+ claude: [],
3
+ codex: ['--codex-root'],
4
+ cursor: [],
5
+ factory: [],
6
+ pi: [],
7
+ omp: ['--omp-root'],
8
+ 'deepseek-harness': ['--dsh-root'],
9
+ muse: ['--muse-root'],
10
+ grokbot: ['--grokbot-root'],
11
+ 'grok-build': ['--grok-root'],
12
+ hermes: ['--hermes-root'],
13
+ };
14
+ const LIVE_DETECTION = {
15
+ 'grok-build': 'supported',
16
+ };
17
+ /**
18
+ * `discoverable` requires a wired `discover` operation on the loaded adapter,
19
+ * not merely an implemented ingest path; otherwise the provider stays
20
+ * `manual-export` (or `unsupported` when it has no ingest path at all).
21
+ */
22
+ export function providerDiscoveryCapability(provider, supportedOperations) {
23
+ if (supportedOperations.includes('discover')) {
24
+ return {
25
+ disposition: 'discoverable',
26
+ authorization: 'explicit-root',
27
+ requiredFlags: REQUIRED_FLAGS[provider] ?? [],
28
+ liveDetection: LIVE_DETECTION[provider] ?? 'unsupported',
29
+ };
30
+ }
31
+ return {
32
+ disposition: 'manual-export',
33
+ authorization: 'none',
34
+ requiredFlags: [],
35
+ liveDetection: 'unsupported',
36
+ };
37
+ }
38
+ //# sourceMappingURL=discovery-capability.js.map