@adhdev/daemon-core 0.9.82-rc.21 → 0.9.82-rc.210
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.
- package/dist/boot/daemon-lifecycle.d.ts +1 -0
- package/dist/boot/process-hardening.d.ts +50 -0
- package/dist/chat/source-machine.d.ts +166 -0
- package/dist/chat/source-resolver.d.ts +104 -0
- package/dist/chat/subscription-updates.d.ts +1 -0
- package/dist/cli-adapter-types.d.ts +23 -2
- package/dist/cli-adapters/cli-script-runner.d.ts +117 -0
- package/dist/cli-adapters/cli-state-engine.d.ts +178 -0
- package/dist/cli-adapters/provider-cli-adapter.d.ts +106 -63
- package/dist/cli-adapters/provider-cli-parse.d.ts +4 -0
- package/dist/cli-adapters/provider-cli-shared.d.ts +29 -0
- package/dist/cli-adapters/raw-terminal-io.d.ts +37 -0
- package/dist/cli-adapters/terminal-backends/ghostty-vt-backend.d.ts +3 -3
- package/dist/cli-adapters/terminal-backends/types.d.ts +1 -2
- package/dist/cli-adapters/terminal-screen.d.ts +2 -11
- package/dist/commands/cli-manager.d.ts +2 -1
- package/dist/commands/handler.d.ts +110 -0
- package/dist/commands/mesh-coordinator.d.ts +85 -1
- package/dist/commands/router.d.ts +32 -1
- package/dist/config/chat-history.d.ts +9 -0
- package/dist/config/config.d.ts +5 -0
- package/dist/config/mesh-config.d.ts +72 -1
- package/dist/git/git-commands.d.ts +9 -1
- package/dist/git/git-diff.d.ts +6 -0
- package/dist/git/git-types.d.ts +2 -0
- package/dist/index.d.ts +46 -11
- package/dist/index.js +35171 -15756
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34878 -15556
- package/dist/index.mjs.map +1 -1
- package/dist/installer.d.ts +1 -4
- package/dist/ipc/local-ipc-server.d.ts +91 -0
- package/dist/launch.d.ts +1 -1
- package/dist/logging/async-batch-writer.d.ts +10 -0
- package/dist/mesh/contracts.d.ts +164 -0
- package/dist/mesh/coordinator-prompt.d.ts +36 -0
- package/dist/mesh/coordinator-registry.d.ts +59 -0
- package/dist/mesh/mesh-active-work.d.ts +90 -0
- package/dist/mesh/mesh-delivery-policy.d.ts +131 -0
- package/dist/mesh/mesh-events-coordinator.d.ts +151 -0
- package/dist/mesh/mesh-events-pending.d.ts +33 -0
- package/dist/mesh/mesh-events-stale.d.ts +40 -0
- package/dist/mesh/mesh-events-utils.d.ts +14 -0
- package/dist/mesh/mesh-events.d.ts +5 -40
- package/dist/mesh/mesh-fast-forward.d.ts +41 -0
- package/dist/mesh/mesh-host-ownership.d.ts +9 -0
- package/dist/mesh/mesh-ledger-reconciliation.d.ts +23 -3
- package/dist/mesh/mesh-ledger.d.ts +77 -1
- package/dist/mesh/mesh-missions.d.ts +58 -0
- package/dist/mesh/mesh-refine-status.d.ts +26 -0
- package/dist/mesh/mesh-review-inbox.d.ts +90 -0
- package/dist/mesh/mesh-runtime-store.d.ts +324 -0
- package/dist/mesh/mesh-task-stats.d.ts +49 -0
- package/dist/mesh/mesh-work-queue.d.ts +137 -6
- package/dist/mesh/preview-freshness.d.ts +18 -0
- package/dist/mesh/refine-config.d.ts +215 -0
- package/dist/mesh/worktree-bootstrap-config.d.ts +135 -0
- package/dist/providers/acp-provider-instance.d.ts +2 -0
- package/dist/providers/approval-utils.d.ts +13 -0
- package/dist/providers/cli-provider-instance.d.ts +39 -3
- package/dist/providers/contracts.d.ts +130 -6
- package/dist/providers/external-sources.d.ts +71 -0
- package/dist/providers/native-history/antigravity-cli-transcript.d.ts +100 -0
- package/dist/providers/native-history/claude-cli-transcript.d.ts +70 -0
- package/dist/providers/native-history/codex-cli-transcript.d.ts +73 -0
- package/dist/providers/native-history/dispatcher.d.ts +27 -0
- package/dist/providers/native-history/hermes-cli-transcript.d.ts +30 -0
- package/dist/providers/native-history/index.d.ts +13 -0
- package/dist/providers/provider-instance-manager.d.ts +12 -0
- package/dist/providers/provider-instance.d.ts +13 -1
- package/dist/providers/provider-loader.d.ts +26 -4
- package/dist/providers/provider-trust.d.ts +31 -0
- package/dist/providers/read-chat-contract.d.ts +29 -0
- package/dist/providers/sdk/v1/builders/acp/detect-status.d.ts +68 -0
- package/dist/providers/sdk/v1/builders/cli/detect-status.d.ts +85 -0
- package/dist/providers/sdk/v1/builders/cli/parse-approval-squash.d.ts +59 -0
- package/dist/providers/sdk/v1/builders/cli/parse-approval.d.ts +65 -0
- package/dist/providers/sdk/v1/builders/cli/parse-session.d.ts +91 -0
- package/dist/providers/sdk/v1/builders/cli/visible-region.d.ts +42 -0
- package/dist/providers/sdk/v1/fixture-tooling/format.d.ts +126 -0
- package/dist/providers/sdk/v1/fixture-tooling/index.d.ts +8 -0
- package/dist/providers/sdk/v1/fixture-tooling/replay.d.ts +38 -0
- package/dist/providers/sdk/v1/index.d.ts +30 -0
- package/dist/providers/sdk/v1/sandbox/README-design.d.ts +193 -0
- package/dist/providers/sdk/v1/sandbox/require-whitelist.d.ts +74 -0
- package/dist/providers/sdk/v1/sandbox/script-runner.d.ts +98 -0
- package/dist/providers/sdk/v1/types/cli/index.d.ts +277 -0
- package/dist/providers/sdk/v1/types/common/index.d.ts +203 -0
- package/dist/providers/sdk/v1/validators/index.d.ts +5 -0
- package/dist/providers/sdk/v1/validators/manifest.d.ts +40 -0
- package/dist/providers/sdk/v1/validators/taint.d.ts +52 -0
- package/dist/providers/spec/adapter.d.ts +52 -0
- package/dist/providers/spec/cli-adapter.d.ts +101 -0
- package/dist/providers/spec/driver.d.ts +225 -0
- package/dist/providers/spec/evaluator.d.ts +54 -0
- package/dist/providers/spec/loader.d.ts +15 -0
- package/dist/providers/spec/native-history-executor.d.ts +41 -0
- package/dist/providers/spec/route.d.ts +4 -0
- package/dist/providers/spec/schema.gen.d.ts +2025 -0
- package/dist/providers/spec/types.d.ts +302 -0
- package/dist/providers/transcript-v2.d.ts +176 -0
- package/dist/providers/types/interactive-prompt.d.ts +48 -0
- package/dist/repo-mesh-types.d.ts +109 -1
- package/dist/sessions/registry.d.ts +3 -0
- package/dist/shared-types-extra.d.ts +2 -4
- package/dist/shared-types.d.ts +42 -1
- package/dist/status/normalize.d.ts +1 -1
- package/dist/status/normalize.js +1 -0
- package/dist/status/normalize.js.map +1 -1
- package/dist/status/normalize.mjs +1 -0
- package/dist/status/normalize.mjs.map +1 -1
- package/dist/status/reporter.d.ts +2 -0
- package/dist/status/snapshot.d.ts +1 -0
- package/dist/types.d.ts +5 -0
- package/package.json +6 -3
- package/src/agent-stream/poller.ts +2 -3
- package/src/boot/daemon-lifecycle.ts +22 -10
- package/src/boot/process-hardening.ts +89 -0
- package/src/chat/source-machine.ts +534 -0
- package/src/chat/source-resolver.ts +0 -0
- package/src/chat/subscription-updates.ts +20 -1
- package/src/cli-adapter-types.d.ts +1 -0
- package/src/cli-adapter-types.ts +22 -2
- package/src/cli-adapters/cli-script-runner.ts +421 -0
- package/src/cli-adapters/cli-state-engine.ts +1138 -0
- package/src/cli-adapters/provider-cli-adapter.d.ts +1 -1
- package/src/cli-adapters/provider-cli-adapter.ts +673 -1139
- package/src/cli-adapters/provider-cli-parse.d.ts +1 -0
- package/src/cli-adapters/provider-cli-parse.ts +13 -0
- package/src/cli-adapters/provider-cli-runtime.ts +3 -1
- package/src/cli-adapters/provider-cli-shared.d.ts +2 -0
- package/src/cli-adapters/provider-cli-shared.ts +59 -11
- package/src/cli-adapters/raw-terminal-io.ts +252 -0
- package/src/cli-adapters/terminal-backends/ghostty-vt-backend.ts +35 -29
- package/src/cli-adapters/terminal-backends/types.ts +1 -3
- package/src/cli-adapters/terminal-screen.ts +11 -81
- package/src/commands/chat-commands.ts +1787 -60
- package/src/commands/cli-manager.ts +283 -14
- package/src/commands/handler.ts +809 -2
- package/src/commands/mesh-coordinator.ts +332 -122
- package/src/commands/router.ts +4198 -557
- package/src/config/chat-history.ts +95 -24
- package/src/config/config.ts +12 -0
- package/src/config/mesh-config.ts +280 -2
- package/src/config/recent-activity.ts +8 -2
- package/src/daemon/dev-auto-implement.ts +3 -2
- package/src/daemon/dev-cli-debug.ts +10 -1
- package/src/detection/ide-detector.ts +26 -16
- package/src/git/git-commands.ts +42 -12
- package/src/git/git-diff.ts +53 -0
- package/src/git/git-status.ts +35 -6
- package/src/git/git-types.ts +2 -0
- package/src/git/git-worktree.ts +8 -1
- package/src/index.ts +126 -10
- package/src/installer.d.ts +1 -1
- package/src/installer.ts +8 -6
- package/src/ipc/local-ipc-server.ts +278 -0
- package/src/launch.d.ts +1 -1
- package/src/launch.ts +37 -28
- package/src/logging/async-batch-writer.ts +55 -0
- package/src/logging/logger.ts +2 -1
- package/src/mesh/contracts.ts +329 -0
- package/src/mesh/coordinator-prompt.ts +218 -31
- package/src/mesh/coordinator-registry.ts +121 -0
- package/src/mesh/mesh-active-work.ts +437 -0
- package/src/mesh/mesh-delivery-policy.ts +315 -0
- package/src/mesh/mesh-events-coordinator.ts +1404 -0
- package/src/mesh/mesh-events-pending.ts +371 -0
- package/src/mesh/mesh-events-stale.ts +283 -0
- package/src/mesh/mesh-events-utils.ts +161 -0
- package/src/mesh/mesh-events.ts +24 -908
- package/src/mesh/mesh-fast-forward.ts +438 -0
- package/src/mesh/mesh-host-ownership.ts +73 -0
- package/src/mesh/mesh-ledger-reconciliation.ts +12 -5
- package/src/mesh/mesh-ledger.ts +587 -102
- package/src/mesh/mesh-missions.ts +151 -0
- package/src/mesh/mesh-refine-status.ts +144 -0
- package/src/mesh/mesh-review-inbox.ts +307 -0
- package/src/mesh/mesh-runtime-store.ts +1305 -0
- package/src/mesh/mesh-task-stats.ts +154 -0
- package/src/mesh/mesh-work-queue.ts +490 -166
- package/src/mesh/preview-freshness.ts +118 -0
- package/src/mesh/refine-config.ts +403 -0
- package/src/mesh/worktree-bootstrap-config.ts +326 -0
- package/src/providers/acp-provider-instance.ts +15 -1
- package/src/providers/approval-utils.d.ts +4 -0
- package/src/providers/approval-utils.ts +47 -5
- package/src/providers/chat-message-normalization.ts +4 -11
- package/src/providers/cli-provider-instance.ts +833 -64
- package/src/providers/contracts.d.ts +55 -0
- package/src/providers/contracts.ts +141 -6
- package/src/providers/external-sources.ts +218 -0
- package/src/providers/ide-provider-instance.ts +19 -5
- package/src/providers/native-history/antigravity-cli-transcript.ts +643 -0
- package/src/providers/native-history/claude-cli-transcript.ts +396 -0
- package/src/providers/native-history/codex-cli-transcript.ts +419 -0
- package/src/providers/native-history/dispatcher.ts +340 -0
- package/src/providers/native-history/hermes-cli-transcript.ts +230 -0
- package/src/providers/native-history/index.ts +30 -0
- package/src/providers/provider-instance-manager.ts +30 -0
- package/src/providers/provider-instance.ts +10 -1
- package/src/providers/provider-loader.ts +582 -50
- package/src/providers/provider-schema.ts +87 -14
- package/src/providers/provider-trust.ts +114 -0
- package/src/providers/read-chat-contract.ts +76 -16
- package/src/providers/sdk/README.md +49 -0
- package/src/providers/sdk/v1/builders/acp/detect-status.ts +144 -0
- package/src/providers/sdk/v1/builders/cli/detect-status.ts +262 -0
- package/src/providers/sdk/v1/builders/cli/parse-approval-squash.ts +158 -0
- package/src/providers/sdk/v1/builders/cli/parse-approval.ts +250 -0
- package/src/providers/sdk/v1/builders/cli/parse-session.ts +276 -0
- package/src/providers/sdk/v1/builders/cli/visible-region.ts +143 -0
- package/src/providers/sdk/v1/fixture-tooling/format.ts +130 -0
- package/src/providers/sdk/v1/fixture-tooling/index.ts +22 -0
- package/src/providers/sdk/v1/fixture-tooling/replay.ts +352 -0
- package/src/providers/sdk/v1/index.ts +152 -0
- package/src/providers/sdk/v1/sandbox/README-design.ts +195 -0
- package/src/providers/sdk/v1/sandbox/require-whitelist.ts +472 -0
- package/src/providers/sdk/v1/sandbox/script-runner.ts +150 -0
- package/src/providers/sdk/v1/schemas/cli/provider.schema.json +504 -0
- package/src/providers/sdk/v1/schemas/primitives/acp-session-protocol-v1.json +131 -0
- package/src/providers/sdk/v1/schemas/primitives/native-history-codex-rollout-v1.json +66 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-approval-squash-v1.json +91 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-assistant-block-v1.json +91 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-cue-ordering-v1.json +47 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-dispatch-order-v1.json +32 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-footer-chrome-v1.json +42 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-index-finder-v1.json +27 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-modal-v1.json +125 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-prompt-marker-v1.json +45 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-session-id-extraction-v1.json +46 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-settled-prompt-v1.json +71 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-spinner-v1.json +83 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-transcript-pty-v1.json +83 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-visible-region-v1.json +57 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-welcome-screen-v1.json +35 -0
- package/src/providers/sdk/v1/types/cli/index.ts +365 -0
- package/src/providers/sdk/v1/types/common/index.ts +229 -0
- package/src/providers/sdk/v1/validators/index.ts +19 -0
- package/src/providers/sdk/v1/validators/manifest.ts +110 -0
- package/src/providers/sdk/v1/validators/taint.ts +309 -0
- package/src/providers/spec/adapter.ts +138 -0
- package/src/providers/spec/cli-adapter.ts +626 -0
- package/src/providers/spec/driver.ts +912 -0
- package/src/providers/spec/evaluator.ts +597 -0
- package/src/providers/spec/loader.ts +324 -0
- package/src/providers/spec/native-history-executor.ts +939 -0
- package/src/providers/spec/route.ts +51 -0
- package/src/providers/spec/schema.gen.ts +691 -0
- package/src/providers/spec/schema.json +341 -0
- package/src/providers/spec/types.ts +356 -0
- package/src/providers/transcript-v2.ts +567 -0
- package/src/providers/types/interactive-prompt.ts +425 -0
- package/src/providers/version-archive.ts +38 -20
- package/src/repo-mesh-types.ts +119 -1
- package/src/sessions/registry.ts +3 -0
- package/src/shared-types-extra.ts +2 -4
- package/src/shared-types.ts +45 -1
- package/src/status/builders.ts +24 -6
- package/src/status/normalize.ts +2 -0
- package/src/status/reporter.ts +15 -0
- package/src/status/snapshot.ts +84 -25
- package/src/system/host-memory.ts +29 -12
- package/src/types.ts +5 -0
- package/dist/cli-adapters/terminal-backends/xterm-backend.d.ts +0 -17
- package/dist/mesh/mesh-sync.d.ts +0 -53
- package/src/cli-adapters/terminal-backends/ghostty-vt-backend.d.ts +0 -16
- package/src/cli-adapters/terminal-backends/xterm-backend.ts +0 -97
- package/src/mesh/mesh-sync.ts +0 -111
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* spec.json loader + strict validator.
|
|
3
|
+
*
|
|
4
|
+
* Supports both v1 (adhdev:cli/spec@1) and v3 (adhdev:cli/spec@3).
|
|
5
|
+
* v1 specs are auto-migrated to v3 before validation.
|
|
6
|
+
* Rejects spec files that don't conform to the schema.
|
|
7
|
+
*/
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
import * as fs from 'node:fs';
|
|
11
|
+
import * as path from 'node:path';
|
|
12
|
+
import Ajv from 'ajv';
|
|
13
|
+
import type { CliSpec, SectionDef, Condition, ExtractTitle, ExtractButtons } from './types.js';
|
|
14
|
+
import { SCHEMA_V1, SCHEMA_V3 } from './schema.gen.js';
|
|
15
|
+
|
|
16
|
+
const ajvV1 = new Ajv({ allErrors: true, strict: false });
|
|
17
|
+
const validateV1 = ajvV1.compile(SCHEMA_V1);
|
|
18
|
+
|
|
19
|
+
const ajvV3 = new Ajv({ allErrors: true, strict: false });
|
|
20
|
+
const validateV3 = ajvV3.compile<CliSpec>(SCHEMA_V3);
|
|
21
|
+
|
|
22
|
+
export interface SpecLoadResult {
|
|
23
|
+
ok: true;
|
|
24
|
+
spec: CliSpec;
|
|
25
|
+
sourcePath: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface SpecLoadError {
|
|
29
|
+
ok: false;
|
|
30
|
+
errors: string[];
|
|
31
|
+
sourcePath: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function loadSpec(sourcePath: string): SpecLoadResult | SpecLoadError {
|
|
35
|
+
let raw: unknown;
|
|
36
|
+
try {
|
|
37
|
+
const text = fs.readFileSync(sourcePath, 'utf8');
|
|
38
|
+
raw = JSON.parse(text);
|
|
39
|
+
} catch (err) {
|
|
40
|
+
return { ok: false, errors: [`Failed to read spec: ${(err as Error).message}`], sourcePath };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Auto-migrate v1 → v3
|
|
44
|
+
const schemaStr = (raw as any)?.$schema;
|
|
45
|
+
if (schemaStr === 'adhdev:cli/spec@1') {
|
|
46
|
+
// Validate as v1 first
|
|
47
|
+
if (!validateV1(raw)) {
|
|
48
|
+
const errors = (validateV1.errors || []).map(e => `${e.instancePath || '(root)'} ${e.message ?? 'invalid'} (v1 parse)`);
|
|
49
|
+
return { ok: false, errors, sourcePath };
|
|
50
|
+
}
|
|
51
|
+
raw = migrateV1toV3(raw as any);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!validateV3(raw)) {
|
|
55
|
+
const errors = (validateV3.errors || []).map(e => `${e.instancePath || '(root)'} ${e.message ?? 'invalid'}`);
|
|
56
|
+
return { ok: false, errors, sourcePath };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const spec = raw as CliSpec;
|
|
60
|
+
const extra = validateRefs(spec);
|
|
61
|
+
if (extra.length > 0) return { ok: false, errors: extra, sourcePath };
|
|
62
|
+
|
|
63
|
+
// Populate legacy `debounce` alias from `timing` for backward compat
|
|
64
|
+
attachDebounceAlias(spec);
|
|
65
|
+
|
|
66
|
+
return { ok: true, spec, sourcePath };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Populate spec.debounce as a backward-compat alias for spec.timing.
|
|
71
|
+
* The driver and tests read debounce.{busy_hold_ms, idle_hold_ms, ...}.
|
|
72
|
+
* After this call both fields point at equivalent data.
|
|
73
|
+
*/
|
|
74
|
+
function attachDebounceAlias(spec: CliSpec): void {
|
|
75
|
+
const t = spec.timing;
|
|
76
|
+
if (!t) return;
|
|
77
|
+
const cm = t.completion_marker;
|
|
78
|
+
(spec as any).debounce = {
|
|
79
|
+
...(t.busy_hold_ms !== undefined ? { busy_hold_ms: t.busy_hold_ms } : {}),
|
|
80
|
+
...(t.idle_hold_ms !== undefined ? { idle_hold_ms: t.idle_hold_ms } : {}),
|
|
81
|
+
...(t.startup_grace_ms !== undefined ? { startup_grace_ms: t.startup_grace_ms } : {}),
|
|
82
|
+
...(cm ? {
|
|
83
|
+
completion_idle_after: {
|
|
84
|
+
...(cm.section ? { section: cm.section } : {}),
|
|
85
|
+
regex: cm.matches,
|
|
86
|
+
...(cm.flags ? { flags: cm.flags } : {}),
|
|
87
|
+
hold_ms: cm.hold_ms,
|
|
88
|
+
...(cm.force_after_ms !== undefined ? { force_after_ms: cm.force_after_ms } : {}),
|
|
89
|
+
},
|
|
90
|
+
} : {}),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
95
|
+
// Migration: v1 → v3
|
|
96
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
97
|
+
|
|
98
|
+
export function migrateV1toV3(raw: any): any {
|
|
99
|
+
// sections: array → object
|
|
100
|
+
const sections: Record<string, SectionDef> = {};
|
|
101
|
+
for (const sec of raw.layout?.sections ?? []) {
|
|
102
|
+
const { id, anchor_regex, until_regex, until_regex_flags, ...rest } = sec;
|
|
103
|
+
const sectionDef: any = { ...rest };
|
|
104
|
+
|
|
105
|
+
// anchor_regex → anchor
|
|
106
|
+
if (anchor_regex) sectionDef.anchor = anchor_regex;
|
|
107
|
+
|
|
108
|
+
// until: { section: id } → until: id (section reference)
|
|
109
|
+
if (rest.until?.section) {
|
|
110
|
+
sectionDef.until = rest.until.section;
|
|
111
|
+
} else {
|
|
112
|
+
delete sectionDef.until;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// keep until_regex for anchor-based extension
|
|
116
|
+
if (until_regex) sectionDef.until_regex = until_regex;
|
|
117
|
+
if (until_regex_flags) sectionDef.until_regex_flags = until_regex_flags;
|
|
118
|
+
|
|
119
|
+
sections[id] = sectionDef;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// states: convert when/extract_title/modal_buttons
|
|
123
|
+
const states = (raw.states ?? []).map((s: any) => {
|
|
124
|
+
// Convert when: SectionRegex → when: AllCondition | AnyCondition
|
|
125
|
+
let when: any;
|
|
126
|
+
if (s.when?.cursor_above_lines && s.when?.changed) {
|
|
127
|
+
// v1 delta detection condition
|
|
128
|
+
when = {
|
|
129
|
+
any: [
|
|
130
|
+
{ cursor_above: s.when.cursor_above_lines, changed: true as const },
|
|
131
|
+
],
|
|
132
|
+
};
|
|
133
|
+
} else if (s.when?.regex) {
|
|
134
|
+
const regexCond: any = {
|
|
135
|
+
section: s.when.section,
|
|
136
|
+
matches: s.when.regex,
|
|
137
|
+
...(s.when.flags ? { flags: s.when.flags } : {}),
|
|
138
|
+
...(s.when.cursor_row_min !== undefined ? { cursor_row_min: s.when.cursor_row_min } : {}),
|
|
139
|
+
...(s.when.cursor_row_max !== undefined ? { cursor_row_max: s.when.cursor_row_max } : {}),
|
|
140
|
+
...(s.when.cursor_col_min !== undefined ? { cursor_col_min: s.when.cursor_col_min } : {}),
|
|
141
|
+
...(s.when.cursor_col_max !== undefined ? { cursor_col_max: s.when.cursor_col_max } : {}),
|
|
142
|
+
};
|
|
143
|
+
if (!regexCond.section) delete regexCond.section;
|
|
144
|
+
when = { all: [regexCond] };
|
|
145
|
+
} else {
|
|
146
|
+
// No regex — empty all (always matches)
|
|
147
|
+
when = { all: [] };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const extract: any = {};
|
|
151
|
+
if (s.extract_title) {
|
|
152
|
+
if (s.extract_title.first_line) {
|
|
153
|
+
extract.title = { section: s.extract_title.section, first_line: true as const };
|
|
154
|
+
if (!extract.title.section) delete extract.title.section;
|
|
155
|
+
} else if (s.extract_title.regex) {
|
|
156
|
+
extract.title = {
|
|
157
|
+
section: s.extract_title.section,
|
|
158
|
+
regex: s.extract_title.regex,
|
|
159
|
+
...(s.extract_title.flags ? { flags: s.extract_title.flags } : {}),
|
|
160
|
+
};
|
|
161
|
+
if (!extract.title.section) delete extract.title.section;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (s.modal_buttons) {
|
|
165
|
+
const mb = s.modal_buttons;
|
|
166
|
+
// Use first pattern from patterns[] array, or single pattern
|
|
167
|
+
const pat = mb.patterns?.length ? mb.patterns[0].pattern : mb.pattern;
|
|
168
|
+
const flg = mb.patterns?.length ? mb.patterns[0].flags : mb.flags;
|
|
169
|
+
if (pat) {
|
|
170
|
+
extract.buttons = {
|
|
171
|
+
...(mb.section ? { section: mb.section } : {}),
|
|
172
|
+
pattern: pat,
|
|
173
|
+
...(flg ? { flags: flg } : {}),
|
|
174
|
+
key_for_index: mb.key_for_index,
|
|
175
|
+
...(mb.min_count !== undefined ? { min_count: mb.min_count } : {}),
|
|
176
|
+
...(mb.continuation_lines !== undefined ? { continuation_lines: mb.continuation_lines } : {}),
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return {
|
|
182
|
+
id: s.id,
|
|
183
|
+
label: s.label,
|
|
184
|
+
when,
|
|
185
|
+
...(Object.keys(extract).length > 0 ? { extract } : {}),
|
|
186
|
+
};
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// timing (from debounce)
|
|
190
|
+
const d = raw.debounce ?? {};
|
|
191
|
+
const timing: any = {};
|
|
192
|
+
if (d.busy_hold_ms !== undefined) timing.busy_hold_ms = d.busy_hold_ms;
|
|
193
|
+
if (d.idle_hold_ms !== undefined) timing.idle_hold_ms = d.idle_hold_ms;
|
|
194
|
+
if (d.startup_grace_ms !== undefined) timing.startup_grace_ms = d.startup_grace_ms;
|
|
195
|
+
if (d.completion_idle_after) {
|
|
196
|
+
timing.completion_marker = {
|
|
197
|
+
...(d.completion_idle_after.section ? { section: d.completion_idle_after.section } : {}),
|
|
198
|
+
matches: d.completion_idle_after.regex,
|
|
199
|
+
...(d.completion_idle_after.flags ? { flags: d.completion_idle_after.flags } : {}),
|
|
200
|
+
hold_ms: d.completion_idle_after.hold_ms,
|
|
201
|
+
...(d.completion_idle_after.force_after_ms !== undefined
|
|
202
|
+
? { force_after_ms: d.completion_idle_after.force_after_ms } : {}),
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return {
|
|
207
|
+
$schema: 'adhdev:cli/spec@3',
|
|
208
|
+
id: raw.id,
|
|
209
|
+
name: raw.name,
|
|
210
|
+
binary: raw.binary,
|
|
211
|
+
...(raw.cli_version_range ? { cli_version_range: raw.cli_version_range } : {}),
|
|
212
|
+
...(raw.spawn_args ? { spawn_args: raw.spawn_args } : {}),
|
|
213
|
+
...(raw.env ? { env: raw.env } : {}),
|
|
214
|
+
send_message: raw.send_message,
|
|
215
|
+
sections,
|
|
216
|
+
states,
|
|
217
|
+
default_state: raw.default_state,
|
|
218
|
+
...(Object.keys(timing).length > 0 ? { timing } : {}),
|
|
219
|
+
...(raw.control_bar ? { control_bar: raw.control_bar } : {}),
|
|
220
|
+
...(raw.notifications ? { notifications: raw.notifications } : {}),
|
|
221
|
+
...(raw.delegate ? { delegate: raw.delegate } : {}),
|
|
222
|
+
...(raw.native_history ? { native_history: raw.native_history } : {}),
|
|
223
|
+
...(raw.requiresFinalAssistantBeforeIdle
|
|
224
|
+
? { requiresFinalAssistantBeforeIdle: raw.requiresFinalAssistantBeforeIdle } : {}),
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
229
|
+
// Cross-field validation
|
|
230
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
231
|
+
|
|
232
|
+
function validateRefs(spec: CliSpec): string[] {
|
|
233
|
+
const errs: string[] = [];
|
|
234
|
+
const sectionIds = new Set(Object.keys(spec.sections));
|
|
235
|
+
const stateIds = new Set(spec.states.map(s => s.id));
|
|
236
|
+
|
|
237
|
+
if (!stateIds.has(spec.default_state)) {
|
|
238
|
+
errs.push(`default_state "${spec.default_state}" is not defined in states[]`);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
for (const s of spec.states) {
|
|
242
|
+
validateConditionRefs(s.when, `states[${s.id}].when`, sectionIds, errs);
|
|
243
|
+
const ext = s.extract;
|
|
244
|
+
if (ext?.title) {
|
|
245
|
+
if (ext.title.section && !sectionIds.has(ext.title.section)) {
|
|
246
|
+
errs.push(`states[${s.id}].extract.title.section "${ext.title.section}" unknown`);
|
|
247
|
+
}
|
|
248
|
+
if (ext.title.regex) {
|
|
249
|
+
compileRegexCheck(ext.title.regex, ext.title.flags, `states[${s.id}].extract.title.regex`, errs);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
if (ext?.buttons) {
|
|
253
|
+
if (ext.buttons.section && !sectionIds.has(ext.buttons.section)) {
|
|
254
|
+
errs.push(`states[${s.id}].extract.buttons.section "${ext.buttons.section}" unknown`);
|
|
255
|
+
}
|
|
256
|
+
compileRegexCheck(ext.buttons.pattern, ext.buttons.flags ?? 'm', `states[${s.id}].extract.buttons.pattern`, errs);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
for (const c of spec.control_bar ?? []) {
|
|
261
|
+
for (const stId of c.visible_when_state ?? []) {
|
|
262
|
+
if (!stateIds.has(stId)) errs.push(`control_bar[${c.id}].visible_when_state references unknown state "${stId}"`);
|
|
263
|
+
}
|
|
264
|
+
if (c.action.type === 'open_picker') {
|
|
265
|
+
if (c.action.wait_for.section && !sectionIds.has(c.action.wait_for.section ?? '')) {
|
|
266
|
+
errs.push(`control_bar[${c.id}].action.wait_for.section "${c.action.wait_for.section}" unknown`);
|
|
267
|
+
}
|
|
268
|
+
if (c.action.wait_for.regex) {
|
|
269
|
+
compileRegexCheck(c.action.wait_for.regex, c.action.wait_for.flags, `control_bar[${c.id}].action.wait_for.regex`, errs);
|
|
270
|
+
}
|
|
271
|
+
if (c.action.extract_choices.section && !sectionIds.has(c.action.extract_choices.section)) {
|
|
272
|
+
errs.push(`control_bar[${c.id}].action.extract_choices.section "${c.action.extract_choices.section}" unknown`);
|
|
273
|
+
}
|
|
274
|
+
compileRegexCheck(c.action.extract_choices.pattern, c.action.extract_choices.flags ?? 'm', `control_bar[${c.id}].action.extract_choices.pattern`, errs);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
for (const n of spec.notifications ?? []) {
|
|
279
|
+
if (!stateIds.has(n.when_state)) errs.push(`notifications[${n.id}].when_state "${n.when_state}" unknown`);
|
|
280
|
+
}
|
|
281
|
+
for (const d of spec.delegate ?? []) {
|
|
282
|
+
if (!stateIds.has(d.when_state)) errs.push(`delegate[${d.id}].when_state "${d.when_state}" unknown`);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// native_history: exactly one of {reader, source, override_path}.
|
|
286
|
+
const nh = spec.native_history;
|
|
287
|
+
if (nh) {
|
|
288
|
+
const modes = (['reader', 'source', 'override_path'] as const).filter(k => (nh as Record<string, unknown>)[k] !== undefined);
|
|
289
|
+
if (modes.length === 0) {
|
|
290
|
+
errs.push('native_history must set exactly one of {reader, source, override_path}');
|
|
291
|
+
} else if (modes.length > 1) {
|
|
292
|
+
errs.push(`native_history sets ${modes.length} modes (${modes.join(', ')}); pick exactly one`);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return errs;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function validateConditionRefs(cond: any, where: string, sectionIds: Set<string>, errs: string[]): void {
|
|
300
|
+
if (!cond) return;
|
|
301
|
+
if ('all' in cond) {
|
|
302
|
+
for (const c of cond.all ?? []) validateConditionRefs(c, where, sectionIds, errs);
|
|
303
|
+
} else if ('any' in cond) {
|
|
304
|
+
for (const c of cond.any ?? []) validateConditionRefs(c, where, sectionIds, errs);
|
|
305
|
+
} else if ('matches' in cond) {
|
|
306
|
+
if (cond.section && !sectionIds.has(cond.section)) {
|
|
307
|
+
errs.push(`${where}.section "${cond.section}" unknown`);
|
|
308
|
+
}
|
|
309
|
+
compileRegexCheck(cond.matches, cond.flags, `${where}.matches`, errs);
|
|
310
|
+
}
|
|
311
|
+
// ChangedCondition has no section refs
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function compileRegexCheck(source: string | undefined, flags: string | undefined, where: string, errs: string[]): void {
|
|
315
|
+
if (!source) return;
|
|
316
|
+
try { new RegExp(source, flags ?? ''); } catch (err) {
|
|
317
|
+
errs.push(`${where} regex invalid: ${(err as Error).message}`);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** Convenience: look up a provider's spec.json next to its provider dir. */
|
|
322
|
+
export function resolveSpecPath(providerDir: string): string {
|
|
323
|
+
return path.join(providerDir, 'spec.json');
|
|
324
|
+
}
|