@adhdev/daemon-core 0.9.82-rc.36 → 0.9.82-rc.360
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 +8 -0
- package/dist/boot/process-hardening.d.ts +50 -0
- package/dist/build-info.d.ts +37 -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 +55 -2
- package/dist/cli-adapters/cli-script-runner.d.ts +117 -0
- package/dist/cli-adapters/cli-state-engine.d.ts +198 -0
- package/dist/cli-adapters/provider-cli-adapter.d.ts +116 -64
- package/dist/cli-adapters/provider-cli-parse.d.ts +4 -0
- package/dist/cli-adapters/provider-cli-runtime.d.ts +34 -0
- package/dist/cli-adapters/provider-cli-shared.d.ts +53 -0
- package/dist/cli-adapters/raw-terminal-io.d.ts +37 -0
- package/dist/cli-adapters/resolve-executable.d.ts +14 -0
- package/dist/cli-adapters/terminal-backends/ghostty-vt-backend.d.ts +6 -3
- package/dist/cli-adapters/terminal-backends/types.d.ts +10 -2
- package/dist/cli-adapters/terminal-screen.d.ts +4 -11
- package/dist/commands/cli-manager.d.ts +2 -1
- package/dist/commands/handler.d.ts +125 -0
- package/dist/commands/mesh-coordinator.d.ts +85 -1
- package/dist/commands/router.d.ts +336 -1
- package/dist/commands/upgrade-helper.d.ts +41 -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 +77 -1
- package/dist/detection/ide-detector.d.ts +13 -0
- package/dist/detection/win32-ide-version.d.ts +37 -0
- package/dist/git/change-impact-config.d.ts +159 -0
- package/dist/git/git-commands.d.ts +11 -1
- package/dist/git/git-diff.d.ts +6 -0
- package/dist/git/git-executor.d.ts +11 -0
- package/dist/git/git-status.d.ts +23 -0
- package/dist/git/git-types.d.ts +2 -50
- package/dist/git/index.d.ts +2 -0
- package/dist/index.d.ts +54 -13
- package/dist/index.js +44143 -17595
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43858 -17438
- 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/logging/log-redactor.d.ts +24 -0
- package/dist/logging/log-tail-reader.d.ts +46 -0
- package/dist/logging/logger.d.ts +1 -1
- 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 +174 -0
- package/dist/mesh/mesh-delivery-policy.d.ts +131 -0
- package/dist/mesh/mesh-event-trace.d.ts +21 -0
- package/dist/mesh/mesh-events-coordinator.d.ts +170 -0
- package/dist/mesh/mesh-events-pending.d.ts +55 -0
- package/dist/mesh/mesh-events-stale.d.ts +40 -0
- package/dist/mesh/mesh-events-utils.d.ts +62 -0
- package/dist/mesh/mesh-events.d.ts +6 -49
- package/dist/mesh/mesh-fast-forward.d.ts +81 -0
- package/dist/mesh/mesh-host-ownership.d.ts +9 -0
- package/dist/mesh/mesh-init.d.ts +86 -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 +164 -0
- package/dist/mesh/mesh-reconcile-loop.d.ts +7 -0
- package/dist/mesh/mesh-refine-batch.d.ts +68 -0
- package/dist/mesh/mesh-refine-status.d.ts +62 -0
- package/dist/mesh/mesh-review-inbox.d.ts +90 -0
- package/dist/mesh/mesh-routing.d.ts +70 -0
- package/dist/mesh/mesh-runtime-store.d.ts +429 -0
- package/dist/mesh/mesh-task-stats.d.ts +49 -0
- package/dist/mesh/mesh-unresolved-forward-outbox.d.ts +30 -0
- package/dist/mesh/mesh-work-queue.d.ts +246 -5
- package/dist/mesh/preview-freshness.d.ts +18 -0
- package/dist/mesh/refine-config.d.ts +216 -0
- package/dist/mesh/worktree-bootstrap-config.d.ts +135 -0
- package/dist/providers/acp-provider-instance.d.ts +5 -0
- package/dist/providers/approval-utils.d.ts +20 -0
- package/dist/providers/chat-message-normalization.d.ts +12 -0
- package/dist/providers/cli-provider-instance.d.ts +106 -3
- package/dist/providers/contracts.d.ts +139 -6
- package/dist/providers/external-sources.d.ts +71 -0
- package/dist/providers/manual-attendance.d.ts +63 -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 +14 -0
- package/dist/providers/provider-instance.d.ts +23 -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 +86 -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 +91 -0
- package/dist/providers/spec/cli-adapter.d.ts +223 -0
- package/dist/providers/spec/evaluator.d.ts +45 -0
- package/dist/providers/spec/fsm-driver.d.ts +368 -0
- package/dist/providers/spec/fsm-evaluator.d.ts +76 -0
- package/dist/providers/spec/fsm-loader.d.ts +14 -0
- package/dist/providers/spec/fsm-types.d.ts +174 -0
- package/dist/providers/spec/native-history-executor.d.ts +41 -0
- package/dist/providers/spec/pre-launch-trust.d.ts +16 -0
- package/dist/providers/spec/route.d.ts +4 -0
- package/dist/providers/spec/types.d.ts +222 -0
- package/dist/providers/status-monitor.d.ts +7 -7
- package/dist/providers/transcript-v2.d.ts +176 -0
- package/dist/providers/types/interactive-prompt.d.ts +84 -0
- package/dist/providers/working-dir.d.ts +17 -0
- package/dist/repo-mesh-types.d.ts +295 -13
- package/dist/sessions/registry.d.ts +6 -0
- package/dist/shared-types-extra.d.ts +2 -4
- package/dist/shared-types.d.ts +59 -2
- 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 +26 -0
- package/dist/system/load-better-sqlite3.d.ts +21 -0
- package/dist/types.d.ts +5 -0
- package/package.json +7 -3
- package/src/agent-stream/poller.ts +2 -3
- package/src/agent-stream/provider-adapter.ts +1 -1
- package/src/boot/daemon-lifecycle.ts +55 -12
- package/src/boot/process-hardening.ts +89 -0
- package/src/build-info.ts +73 -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 +56 -2
- package/src/cli-adapters/cli-script-runner.ts +421 -0
- package/src/cli-adapters/cli-state-engine.ts +1215 -0
- package/src/cli-adapters/provider-cli-adapter.d.ts +1 -1
- package/src/cli-adapters/provider-cli-adapter.ts +774 -1141
- 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 +56 -7
- package/src/cli-adapters/provider-cli-shared.d.ts +4 -0
- package/src/cli-adapters/provider-cli-shared.ts +100 -11
- package/src/cli-adapters/pty-transport.ts +2 -1
- package/src/cli-adapters/raw-terminal-io.ts +252 -0
- package/src/cli-adapters/resolve-executable.ts +90 -0
- package/src/cli-adapters/session-host-transport.ts +2 -1
- package/src/cli-adapters/terminal-backends/ghostty-vt-backend.ts +53 -29
- package/src/cli-adapters/terminal-backends/types.ts +10 -3
- package/src/cli-adapters/terminal-screen.ts +16 -81
- package/src/commands/WINDOWS-UPGRADE-LOCK-FAILURE.md +198 -0
- package/src/commands/chat-commands.ts +1823 -62
- package/src/commands/cli-manager.ts +336 -19
- package/src/commands/handler.ts +841 -2
- package/src/commands/mesh-coordinator.ts +332 -122
- package/src/commands/router.ts +7624 -1312
- package/src/commands/stream-commands.ts +8 -0
- package/src/commands/upgrade-helper.ts +310 -45
- package/src/config/chat-history.ts +483 -24
- package/src/config/config.ts +12 -0
- package/src/config/mesh-config.ts +388 -6
- 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/cli-detector.ts +28 -9
- package/src/detection/ide-detector.ts +55 -16
- package/src/detection/win32-ide-version.ts +106 -0
- package/src/git/change-impact-config.ts +354 -0
- package/src/git/git-commands.ts +55 -14
- package/src/git/git-diff.ts +81 -11
- package/src/git/git-executor.ts +12 -0
- package/src/git/git-status.ts +574 -43
- package/src/git/git-types.ts +14 -62
- package/src/git/git-worktree.ts +8 -1
- package/src/git/index.ts +16 -0
- package/src/index.ts +156 -12
- 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/command-log.ts +7 -5
- package/src/logging/log-redactor.ts +100 -0
- package/src/logging/log-tail-reader.ts +220 -0
- package/src/logging/logger.ts +14 -7
- package/src/mesh/contracts.ts +329 -0
- package/src/mesh/coordinator-prompt.ts +234 -31
- package/src/mesh/coordinator-registry.ts +121 -0
- package/src/mesh/mesh-active-work.ts +667 -0
- package/src/mesh/mesh-delivery-policy.ts +315 -0
- package/src/mesh/mesh-event-trace.ts +67 -0
- package/src/mesh/mesh-events-coordinator.ts +2572 -0
- package/src/mesh/mesh-events-pending.ts +599 -0
- package/src/mesh/mesh-events-stale.ts +309 -0
- package/src/mesh/mesh-events-utils.ts +381 -0
- package/src/mesh/mesh-events.ts +30 -1035
- package/src/mesh/mesh-fast-forward.ts +839 -0
- package/src/mesh/mesh-host-ownership.ts +73 -0
- package/src/mesh/mesh-init.ts +260 -0
- package/src/mesh/mesh-ledger-reconciliation.ts +12 -5
- package/src/mesh/mesh-ledger.ts +591 -102
- package/src/mesh/mesh-missions.ts +322 -0
- package/src/mesh/mesh-reconcile-loop.ts +1096 -0
- package/src/mesh/mesh-refine-batch.ts +197 -0
- package/src/mesh/mesh-refine-status.ts +231 -0
- package/src/mesh/mesh-review-inbox.ts +307 -0
- package/src/mesh/mesh-routing.ts +291 -0
- package/src/mesh/mesh-runtime-store.ts +1697 -0
- package/src/mesh/mesh-task-stats.ts +161 -0
- package/src/mesh/mesh-unresolved-forward-outbox.ts +185 -0
- package/src/mesh/mesh-work-queue.ts +997 -141
- package/src/mesh/preview-freshness.ts +118 -0
- package/src/mesh/refine-config.ts +423 -0
- package/src/mesh/worktree-bootstrap-config.ts +331 -0
- package/src/providers/acp-provider-instance.ts +43 -10
- package/src/providers/approval-utils.d.ts +5 -0
- package/src/providers/approval-utils.ts +57 -5
- package/src/providers/chat-message-normalization.ts +45 -5
- package/src/providers/cli-provider-instance.ts +1254 -101
- package/src/providers/contracts.d.ts +55 -0
- package/src/providers/contracts.ts +150 -6
- package/src/providers/extension-provider-instance.ts +12 -7
- package/src/providers/external-sources.ts +218 -0
- package/src/providers/ide-provider-instance.ts +35 -12
- package/src/providers/manual-attendance.ts +85 -0
- 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 +479 -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 +19 -1
- package/src/providers/provider-loader.ts +670 -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 +313 -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 +235 -0
- package/src/providers/spec/cli-adapter.ts +1051 -0
- package/src/providers/spec/evaluator.ts +407 -0
- package/src/providers/spec/fsm-driver.ts +1251 -0
- package/src/providers/spec/fsm-evaluator.ts +272 -0
- package/src/providers/spec/fsm-loader.ts +120 -0
- package/src/providers/spec/fsm-types.ts +273 -0
- package/src/providers/spec/native-history-executor.ts +1136 -0
- package/src/providers/spec/pre-launch-trust.ts +104 -0
- package/src/providers/spec/route.ts +51 -0
- package/src/providers/spec/types.ts +262 -0
- package/src/providers/status-monitor.d.ts +7 -7
- package/src/providers/status-monitor.ts +37 -22
- package/src/providers/transcript-v2.ts +567 -0
- package/src/providers/types/interactive-prompt.ts +536 -0
- package/src/providers/version-archive.ts +64 -24
- package/src/providers/working-dir.ts +23 -0
- package/src/repo-mesh-types.ts +378 -14
- package/src/sessions/registry.ts +6 -0
- package/src/shared-types-extra.ts +2 -4
- package/src/shared-types.d.ts +8 -0
- package/src/shared-types.ts +64 -1
- package/src/status/builders.ts +26 -6
- package/src/status/normalize.ts +2 -0
- package/src/status/reporter.ts +19 -1
- package/src/status/snapshot.ts +95 -26
- package/src/system/host-memory.ts +29 -12
- package/src/system/load-better-sqlite3.ts +68 -0
- 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
|
@@ -22,6 +22,7 @@ import { LOG } from '../logging/logger.js';
|
|
|
22
22
|
import { VersionArchive } from './version-archive.js';
|
|
23
23
|
import type {
|
|
24
24
|
ProviderCompatibilityEntry,
|
|
25
|
+
ProviderControlDef,
|
|
25
26
|
ProviderModule,
|
|
26
27
|
ProviderCategory,
|
|
27
28
|
ProviderScripts,
|
|
@@ -30,8 +31,34 @@ import type {
|
|
|
30
31
|
ResolvedProvider,
|
|
31
32
|
} from './contracts.js';
|
|
32
33
|
import { validateProviderDefinition } from './provider-schema.js';
|
|
34
|
+
import {
|
|
35
|
+
loadProvidersActive,
|
|
36
|
+
resolveActiveSource,
|
|
37
|
+
} from './external-sources.js';
|
|
33
38
|
import type { ProviderSourceMode } from '../config/config.js';
|
|
34
39
|
import type { ProviderSourceConfigSnapshot, ProviderUserDirSource } from '../config/provider-source-config.js';
|
|
40
|
+
import { executeNativeHistory } from './spec/native-history-executor.js';
|
|
41
|
+
import { createNativeHistoryDispatcher, type ReaderId } from './native-history/dispatcher.js';
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Adds a provider-script root to the require whitelist. Wrapped in a
|
|
45
|
+
* try/catch + null check so a loader hot-path can't crash on a path
|
|
46
|
+
* that doesn't exist yet or one the whitelist hook rejects.
|
|
47
|
+
*
|
|
48
|
+
* The require-whitelist module is loaded lazily on first call. Eagerly
|
|
49
|
+
* top-level importing it pulls `node:fs.realpathSync.native` into
|
|
50
|
+
* module evaluation, which breaks unit tests that partially mock `fs`
|
|
51
|
+
* (e.g. test/commands/get-logs-incremental.test.ts mocks only
|
|
52
|
+
* existsSync + readFileSync). Lazy load keeps that mock surface valid.
|
|
53
|
+
*/
|
|
54
|
+
function registerProviderScriptRootSafely(root: string | null | undefined): void {
|
|
55
|
+
if (!root || typeof root !== 'string') return;
|
|
56
|
+
try {
|
|
57
|
+
const { registerProviderScriptRoot } =
|
|
58
|
+
require('./sdk/v1/sandbox/require-whitelist.js') as typeof import('./sdk/v1/sandbox/require-whitelist.js');
|
|
59
|
+
registerProviderScriptRoot(root);
|
|
60
|
+
} catch { /* boot-time only — swallow */ }
|
|
61
|
+
}
|
|
35
62
|
|
|
36
63
|
interface ProviderAvailabilityState {
|
|
37
64
|
installed: boolean;
|
|
@@ -61,6 +88,78 @@ export interface MachineProviderConfig {
|
|
|
61
88
|
lastVerification?: MachineProviderCheckResult;
|
|
62
89
|
}
|
|
63
90
|
|
|
91
|
+
/**
|
|
92
|
+
* Translate a spec `control_bar` array into the web-facing
|
|
93
|
+
* `ProviderControlDef[]` shape the dashboard renders.
|
|
94
|
+
*
|
|
95
|
+
* The two shapes are distinct: `control_bar` entries are daemon-side
|
|
96
|
+
* `{ id, label, visible_when_state, action }` records driving
|
|
97
|
+
* SpecCliAdapter.invokeScript, while the dashboard's chat bar reads
|
|
98
|
+
* `ProviderControlDef` (`{ id, type, label, placement, ... }`). Spec
|
|
99
|
+
* providers (claude-cli / codex-cli) historically declared *only*
|
|
100
|
+
* `control_bar`, so the dashboard saw no controls at all — the Model / Mode
|
|
101
|
+
* pickers never rendered. This bridges that gap without changing how the
|
|
102
|
+
* controls actually dispatch.
|
|
103
|
+
*
|
|
104
|
+
* Script-name contract: the dashboard sends the control's
|
|
105
|
+
* `listScript` / `setScript` / `invokeScript` name through
|
|
106
|
+
* `invoke_provider_script`, which gates on `provider.scripts[<name>]` and then
|
|
107
|
+
* routes to `SpecCliAdapter.invokeScript(<name>)` — which matches the name
|
|
108
|
+
* against `control_bar[].id`. So every synthesized script name MUST equal the
|
|
109
|
+
* control id (the loader stubs `provider.scripts[id]` from the same source).
|
|
110
|
+
*
|
|
111
|
+
* Mapping:
|
|
112
|
+
* open_picker → select (dynamic): list + set both keyed on the control id;
|
|
113
|
+
* the adapter distinguishes LIST vs SELECT by the presence of
|
|
114
|
+
* a choice arg, so one id serves both roles.
|
|
115
|
+
* send_keys → action: one-shot keystroke (stop, cycle_mode).
|
|
116
|
+
* attach_image → skipped: it needs an image blob from a file picker, not a
|
|
117
|
+
* bare bar button; surfacing it as an `action` would only
|
|
118
|
+
* produce a button that errors with "requires args.blob".
|
|
119
|
+
*/
|
|
120
|
+
function synthesizeControlsFromControlBar(specControls: any[]): ProviderControlDef[] {
|
|
121
|
+
const out: ProviderControlDef[] = [];
|
|
122
|
+
specControls.forEach((ctl, index) => {
|
|
123
|
+
const id = typeof ctl?.id === 'string' ? ctl.id.trim() : '';
|
|
124
|
+
const actionType = ctl?.action?.type;
|
|
125
|
+
if (!id || !actionType) return;
|
|
126
|
+
const label = typeof ctl?.label === 'string' && ctl.label.trim() ? ctl.label : id;
|
|
127
|
+
// Preserve the spec's state gating so the web bar can mirror the daemon's
|
|
128
|
+
// FsmDriver.handleClickControl enforcement (otherwise the button renders in
|
|
129
|
+
// states where the daemon would silently drop the click).
|
|
130
|
+
const visibleWhenState = Array.isArray(ctl?.visible_when_state)
|
|
131
|
+
? ctl.visible_when_state.filter((s: unknown): s is string => typeof s === 'string')
|
|
132
|
+
: undefined;
|
|
133
|
+
if (actionType === 'open_picker') {
|
|
134
|
+
out.push({
|
|
135
|
+
id,
|
|
136
|
+
type: 'select',
|
|
137
|
+
label,
|
|
138
|
+
placement: 'bar',
|
|
139
|
+
dynamic: true,
|
|
140
|
+
listScript: id,
|
|
141
|
+
setScript: id,
|
|
142
|
+
readFrom: id,
|
|
143
|
+
order: index,
|
|
144
|
+
...(visibleWhenState && visibleWhenState.length > 0 ? { visibleWhenState } : {}),
|
|
145
|
+
});
|
|
146
|
+
} else if (actionType === 'send_keys') {
|
|
147
|
+
out.push({
|
|
148
|
+
id,
|
|
149
|
+
type: 'action',
|
|
150
|
+
label,
|
|
151
|
+
placement: 'bar',
|
|
152
|
+
invokeScript: id,
|
|
153
|
+
resultDisplay: 'none',
|
|
154
|
+
order: index,
|
|
155
|
+
...(visibleWhenState && visibleWhenState.length > 0 ? { visibleWhenState } : {}),
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
// attach_image intentionally skipped — see fn doc.
|
|
159
|
+
});
|
|
160
|
+
return out;
|
|
161
|
+
}
|
|
162
|
+
|
|
64
163
|
type CliDetectionEntry = {
|
|
65
164
|
id: string;
|
|
66
165
|
displayName: string;
|
|
@@ -92,7 +191,9 @@ export class ProviderLoader {
|
|
|
92
191
|
}
|
|
93
192
|
|
|
94
193
|
private static readonly GITHUB_TARBALL_URL = 'https://github.com/vilmire/adhdev-providers/archive/refs/heads/main.tar.gz';
|
|
194
|
+
private static readonly REGISTRY_BASE_URL = 'https://api.adhf.dev/api/v1/registry';
|
|
95
195
|
private static readonly META_FILE = '.meta.json';
|
|
196
|
+
private static readonly REGISTRY_META_FILE = '.registry-meta.json';
|
|
96
197
|
private static readonly REPO_PROVIDER_DIRNAME = 'adhdev-providers';
|
|
97
198
|
private static readonly SIBLING_MARKER_FILE = '.adhdev-provider-root';
|
|
98
199
|
private static readonly SIBLING_ENV_VAR = 'ADHDEV_USE_SIBLING_PROVIDERS';
|
|
@@ -193,6 +294,33 @@ export class ProviderLoader {
|
|
|
193
294
|
sourceMode: options?.sourceMode,
|
|
194
295
|
disableUpstream: options?.disableUpstream,
|
|
195
296
|
});
|
|
297
|
+
|
|
298
|
+
// One-time migration: ~/.adhdev/marketplace → ~/.adhdev/external.
|
|
299
|
+
// The directory was renamed when the "marketplace" install model was
|
|
300
|
+
// dropped in favour of explicit external git sources. Best-effort:
|
|
301
|
+
// if the rename fails we leave both dirs in place and log so the user
|
|
302
|
+
// can investigate.
|
|
303
|
+
this.migrateMarketplaceDirToExternal();
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
private migrateMarketplaceDirToExternal(): void {
|
|
307
|
+
try {
|
|
308
|
+
const home = os.homedir();
|
|
309
|
+
const oldDir = path.join(home, '.adhdev', 'marketplace');
|
|
310
|
+
const newDir = path.join(home, '.adhdev', 'external');
|
|
311
|
+
if (!fs.existsSync(oldDir)) return;
|
|
312
|
+
if (fs.existsSync(newDir)) {
|
|
313
|
+
// Both exist — don't merge. Leave old in place; surface in logs so
|
|
314
|
+
// the user can decide what to keep. Loader still loads from
|
|
315
|
+
// external/ only, so old marketplace/ becomes inert.
|
|
316
|
+
this.log(`Migration skipped: both ~/.adhdev/marketplace and ~/.adhdev/external exist (marketplace dir is now inert and can be removed manually).`);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
fs.renameSync(oldDir, newDir);
|
|
320
|
+
this.log(`Migrated ~/.adhdev/marketplace → ~/.adhdev/external (one-time rename after provider source-layer cleanup).`);
|
|
321
|
+
} catch (e: any) {
|
|
322
|
+
this.log(`Marketplace→external migration failed: ${e?.message || e}`);
|
|
323
|
+
}
|
|
196
324
|
}
|
|
197
325
|
|
|
198
326
|
private log(msg: string): void {
|
|
@@ -224,7 +352,12 @@ export class ProviderLoader {
|
|
|
224
352
|
* Highest-priority editable overrides come first.
|
|
225
353
|
*/
|
|
226
354
|
getProviderRoots(): string[] {
|
|
227
|
-
|
|
355
|
+
// Order matters: user customs > external (3rd-party sources) > upstream
|
|
356
|
+
// (official auto-sync). findProviderDirInternal walks this list in order
|
|
357
|
+
// to locate the provider dir containing the scripts/, so external must
|
|
358
|
+
// be included here even though loadAll() also reads it directly.
|
|
359
|
+
const externalDir = path.join(os.homedir(), '.adhdev', 'external');
|
|
360
|
+
return [this.userDir, externalDir, this.upstreamDir];
|
|
228
361
|
}
|
|
229
362
|
|
|
230
363
|
getSourceConfig(): ProviderSourceConfigSnapshot {
|
|
@@ -316,16 +449,19 @@ export class ProviderLoader {
|
|
|
316
449
|
|
|
317
450
|
/**
|
|
318
451
|
* Load all providers (3-tier priority)
|
|
319
|
-
* 1.
|
|
320
|
-
* 2.
|
|
321
|
-
*
|
|
452
|
+
* 1. ~/.adhdev/providers/.upstream/ — official git, auto-synced
|
|
453
|
+
* 2. ~/.adhdev/external/ — 3rd-party git sources, user-added,
|
|
454
|
+
* bundled providers may include arbitrary JS (untrusted by default)
|
|
455
|
+
* 3. ~/.adhdev/providers/ (excluding .upstream) — user-authored customs,
|
|
456
|
+
* always wins
|
|
457
|
+
* Highest priority listed last (overwrites earlier loads).
|
|
322
458
|
* If .upstream/ is empty, call fetchLatest() before loadAll().
|
|
323
459
|
*/
|
|
324
460
|
loadAll(): void {
|
|
325
461
|
this.providers.clear();
|
|
326
462
|
this.providerAvailability.clear();
|
|
327
463
|
|
|
328
|
-
// 1. Load upstream (GitHub auto-download — primary source)
|
|
464
|
+
// 1. Load upstream (GitHub auto-download — primary official source)
|
|
329
465
|
let upstreamCount = 0;
|
|
330
466
|
if (!this.disableUpstream && fs.existsSync(this.upstreamDir)) {
|
|
331
467
|
upstreamCount = this.loadDir(this.upstreamDir);
|
|
@@ -336,7 +472,90 @@ export class ProviderLoader {
|
|
|
336
472
|
this.log('Upstream loading disabled (sourceMode=no-upstream)');
|
|
337
473
|
}
|
|
338
474
|
|
|
339
|
-
// 2. Load
|
|
475
|
+
// 2. Load external providers from ~/.adhdev/external/<source-name>/
|
|
476
|
+
// (3rd-party git sources). Overrides upstream but is itself overridden
|
|
477
|
+
// by user customs in step 3.
|
|
478
|
+
//
|
|
479
|
+
// Each registered source is a separate subdirectory so two sources can
|
|
480
|
+
// both expose the same provider type without overwriting each other.
|
|
481
|
+
// When more than one source provides the same type, providers-active.json
|
|
482
|
+
// chooses the active one; without an explicit choice we deterministically
|
|
483
|
+
// pick the first in disk-walk order and log the ambiguity so the user
|
|
484
|
+
// can resolve it from the dashboard.
|
|
485
|
+
//
|
|
486
|
+
// Any non-spec manifest (tui block / overrides / scriptDir) coming from
|
|
487
|
+
// an external source runs JavaScript the daemon hasn't audited, so
|
|
488
|
+
// dashboards must surface an "untrusted source" badge before letting
|
|
489
|
+
// the user enable them.
|
|
490
|
+
const externalDir = path.join(os.homedir(), '.adhdev', 'external');
|
|
491
|
+
if (fs.existsSync(externalDir)) {
|
|
492
|
+
// Legacy layout (pre-source-namespace): manifests sit directly at
|
|
493
|
+
// external/<category>/<type>/. Detect by presence of category dirs at
|
|
494
|
+
// the root and migrate inline by treating the whole tree as a single
|
|
495
|
+
// implicit source. Loader behavior unchanged for legacy callers.
|
|
496
|
+
const rootEntries = (() => {
|
|
497
|
+
try { return fs.readdirSync(externalDir, { withFileTypes: true }); }
|
|
498
|
+
catch { return [] as fs.Dirent[]; }
|
|
499
|
+
})();
|
|
500
|
+
const KNOWN_CATEGORIES = new Set(['cli', 'ide', 'extension', 'acp']);
|
|
501
|
+
const looksLegacy = rootEntries.some(e => e.isDirectory() && KNOWN_CATEGORIES.has(e.name));
|
|
502
|
+
if (looksLegacy) {
|
|
503
|
+
// Tree shape predates per-source dirs — treat the whole thing as a
|
|
504
|
+
// single anonymous source so existing installs keep working until
|
|
505
|
+
// they're migrated to a real source registration.
|
|
506
|
+
const externalCount = this.loadDir(externalDir);
|
|
507
|
+
if (externalCount > 0) {
|
|
508
|
+
this.log(`Loaded ${externalCount} external providers (legacy unnamed source)`);
|
|
509
|
+
}
|
|
510
|
+
} else {
|
|
511
|
+
// New layout: external/<source-name>/<category>/<type>/…
|
|
512
|
+
const activeFile = loadProvidersActive();
|
|
513
|
+
let totalLoaded = 0;
|
|
514
|
+
const ambiguousTypes: { type: string; chosen: string; candidates: string[] }[] = [];
|
|
515
|
+
// Per-source load, then filter by active-selection: for each type
|
|
516
|
+
// present in more than one source, only the active source's copy
|
|
517
|
+
// is left in this.providers.
|
|
518
|
+
for (const sourceEntry of rootEntries) {
|
|
519
|
+
if (!sourceEntry.isDirectory()) continue;
|
|
520
|
+
const sourceDir = path.join(externalDir, sourceEntry.name);
|
|
521
|
+
const sourceLoaded = this.loadDir(sourceDir);
|
|
522
|
+
if (sourceLoaded > 0) {
|
|
523
|
+
totalLoaded += sourceLoaded;
|
|
524
|
+
this.log(`Loaded ${sourceLoaded} providers from external source "${sourceEntry.name}"`);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
// Resolve ambiguities — when the same type came from multiple
|
|
528
|
+
// sources, the last load wins by default. Replay with the active
|
|
529
|
+
// selection so the user-chosen source ends up winning.
|
|
530
|
+
for (const [type] of this.providers) {
|
|
531
|
+
const prov = this.providers.get(type);
|
|
532
|
+
if (!prov) continue;
|
|
533
|
+
const resolved = resolveActiveSource(prov.category, type, activeFile);
|
|
534
|
+
if (resolved.candidates.length <= 1) continue;
|
|
535
|
+
if (resolved.ambiguous) {
|
|
536
|
+
ambiguousTypes.push({ type, chosen: resolved.source ?? '?', candidates: resolved.candidates });
|
|
537
|
+
}
|
|
538
|
+
if (resolved.source && resolved.source !== '?') {
|
|
539
|
+
const sourceDir = path.join(externalDir, resolved.source);
|
|
540
|
+
// Reload only this source's copy of the conflicting type so it
|
|
541
|
+
// overwrites whatever else won the initial pass.
|
|
542
|
+
const reloadCount = this.loadDir(sourceDir);
|
|
543
|
+
// reloadCount is a sanity check — we expect ≥1
|
|
544
|
+
if (reloadCount === 0) {
|
|
545
|
+
this.log(`Active source "${resolved.source}" no longer provides ${type}`);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
if (totalLoaded > 0) {
|
|
550
|
+
this.log(`Loaded ${totalLoaded} external providers (3rd-party sources)`);
|
|
551
|
+
}
|
|
552
|
+
for (const a of ambiguousTypes) {
|
|
553
|
+
this.log(`Ambiguous provider "${a.type}" — provided by [${a.candidates.join(', ')}], defaulted to "${a.chosen}". Set the active source from the dashboard to silence this warning.`);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
// 3. Load user custom (excluding .upstream — highest priority, never auto-updated)
|
|
340
559
|
if (fs.existsSync(this.userDir)) {
|
|
341
560
|
const userCount = this.loadDir(this.userDir, ['.upstream']);
|
|
342
561
|
if (userCount > 0) {
|
|
@@ -909,18 +1128,28 @@ export class ProviderLoader {
|
|
|
909
1128
|
|
|
910
1129
|
for (const entry of compat) {
|
|
911
1130
|
if (this.matchesVersion(currentVersion, entry.ideVersion)) {
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
if (
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
1131
|
+
// entry.scriptDir is optional now — spec-driven providers (agy,
|
|
1132
|
+
// codex on >=0.137, claude on >=2.1) only ship `spec` here, so
|
|
1133
|
+
// there's nothing to load from the filesystem. SpecCliAdapter
|
|
1134
|
+
// takes over via the `spec` path later in this method.
|
|
1135
|
+
if (entry.scriptDir) {
|
|
1136
|
+
const loaded = this.loadScriptsFromDir(type, entry.scriptDir);
|
|
1137
|
+
if (loaded) {
|
|
1138
|
+
resolved.scripts = loaded;
|
|
1139
|
+
this.debugLog(` [compatibility] ${type} v${currentVersion} → ${entry.scriptDir}`);
|
|
1140
|
+
resolved._resolvedScriptDir = entry.scriptDir;
|
|
1141
|
+
resolved._resolvedScriptsSource = `compatibility:${entry.ideVersion}`;
|
|
1142
|
+
if (providerDir) {
|
|
1143
|
+
const fullDir = path.join(providerDir, entry.scriptDir);
|
|
1144
|
+
resolved._resolvedScriptsPath = fs.existsSync(path.join(fullDir, 'scripts.js'))
|
|
1145
|
+
? path.join(fullDir, 'scripts.js')
|
|
1146
|
+
: fullDir;
|
|
1147
|
+
}
|
|
1148
|
+
matched = true;
|
|
923
1149
|
}
|
|
1150
|
+
} else {
|
|
1151
|
+
// Spec-only entry — still counts as a match so the
|
|
1152
|
+
// defaultScriptDir fallback below doesn't kick in.
|
|
924
1153
|
matched = true;
|
|
925
1154
|
}
|
|
926
1155
|
break; // first match wins
|
|
@@ -988,7 +1217,12 @@ export class ProviderLoader {
|
|
|
988
1217
|
}
|
|
989
1218
|
|
|
990
1219
|
// 3. Composite override (OS + version)
|
|
991
|
-
|
|
1220
|
+
// Legacy shape: base.overrides is an Array<{ when: {os,version}, scripts }>.
|
|
1221
|
+
// v1 manifests (Phase 3-4) repurposed `overrides` as an object map of
|
|
1222
|
+
// capability overrides (e.g. { detectStatus: { path, schema } }), which is
|
|
1223
|
+
// consumed by the SDK builders, not by this resolver. Only iterate when
|
|
1224
|
+
// the field is in the legacy array shape.
|
|
1225
|
+
if (Array.isArray(base.overrides)) {
|
|
992
1226
|
for (const override of base.overrides) {
|
|
993
1227
|
const osMatch = !override.when.os || override.when.os === currentOs;
|
|
994
1228
|
const verMatch = !override.when.version || (currentVersion && this.matchesVersion(currentVersion, override.when.version));
|
|
@@ -996,6 +1230,40 @@ export class ProviderLoader {
|
|
|
996
1230
|
resolved.scripts = { ...resolved.scripts, ...override.scripts };
|
|
997
1231
|
}
|
|
998
1232
|
}
|
|
1233
|
+
} else if (base.overrides && typeof base.overrides === 'object') {
|
|
1234
|
+
// v1 manifest shape: { detectStatus: { path }, parseSession: { path }, ... }
|
|
1235
|
+
// Each script name maps to a path inside the provider directory. We load
|
|
1236
|
+
// the file and merge its export(s) into resolved.scripts. Lets a
|
|
1237
|
+
// provider override a single primitive (e.g. just detectStatus) while
|
|
1238
|
+
// letting the SDK synthesize the rest from the tui block.
|
|
1239
|
+
const providerDir = this.findProviderDirInternal(base.type);
|
|
1240
|
+
if (providerDir) {
|
|
1241
|
+
for (const [scriptName, override] of Object.entries(base.overrides as Record<string, any>)) {
|
|
1242
|
+
if (!override || typeof override.path !== 'string') continue;
|
|
1243
|
+
const fullPath = path.join(providerDir, override.path);
|
|
1244
|
+
if (!fs.existsSync(fullPath)) {
|
|
1245
|
+
this.log(` [overrides] ${base.type}: ${scriptName} path not found: ${fullPath}`);
|
|
1246
|
+
continue;
|
|
1247
|
+
}
|
|
1248
|
+
try {
|
|
1249
|
+
// Override scripts go through the same whitelist gate as the
|
|
1250
|
+
// main scripts dir. Use the provider parent root so a v1
|
|
1251
|
+
// override can still require ../_shared helpers.
|
|
1252
|
+
registerProviderScriptRootSafely(path.dirname(path.dirname(providerDir)));
|
|
1253
|
+
delete require.cache[require.resolve(fullPath)];
|
|
1254
|
+
const fn = require(fullPath);
|
|
1255
|
+
const target = typeof fn === 'function' ? fn : (fn && fn[scriptName]);
|
|
1256
|
+
if (typeof target === 'function') {
|
|
1257
|
+
resolved.scripts = { ...resolved.scripts, [scriptName]: target } as any;
|
|
1258
|
+
this.log(` [overrides] ${base.type}: ${scriptName} loaded from ${override.path}`);
|
|
1259
|
+
} else {
|
|
1260
|
+
this.log(` [overrides] ${base.type}: ${scriptName} export missing in ${override.path}`);
|
|
1261
|
+
}
|
|
1262
|
+
} catch (e: any) {
|
|
1263
|
+
this.log(` [overrides] ${base.type}: ${scriptName} require failed: ${e?.message || e}`);
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
999
1267
|
}
|
|
1000
1268
|
|
|
1001
1269
|
if ((resolved.category === 'cli' || resolved.category === 'acp') && resolved.spawn?.command) {
|
|
@@ -1006,6 +1274,135 @@ export class ProviderLoader {
|
|
|
1006
1274
|
};
|
|
1007
1275
|
}
|
|
1008
1276
|
|
|
1277
|
+
// (spec migration) Late-binding spec.json native-history hook. Runs
|
|
1278
|
+
// *after* every script-loading path (compatibility / defaultScriptDir /
|
|
1279
|
+
// overrides) so it deterministically wins over a legacy v1 scripts.js
|
|
1280
|
+
// export. Three modes, picked by spec.json's native_history block:
|
|
1281
|
+
// 1. source — declarative jsonl/sqlite executor (new-provider path,
|
|
1282
|
+
// no daemon change needed for new on-disk formats)
|
|
1283
|
+
// 2. override_path — provider-supplied reader file (escape hatch for
|
|
1284
|
+
// exotic formats); module default-exports a reader fn
|
|
1285
|
+
// 3. reader — built-in reader id (claude-cli / codex-cli /
|
|
1286
|
+
// antigravity-cli / hermes-cli), kept for backwards
|
|
1287
|
+
// compatibility with the four shipped providers
|
|
1288
|
+
if (providerDir) {
|
|
1289
|
+
try {
|
|
1290
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
1291
|
+
const fs = require('node:fs');
|
|
1292
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
1293
|
+
const path = require('node:path');
|
|
1294
|
+
// Pick the right spec file for the detected CLI version. Resolution
|
|
1295
|
+
// order:
|
|
1296
|
+
// 1. compatibility[i].spec where ideVersion matches currentVersion
|
|
1297
|
+
// (lets a provider ship specs/2.0.json, specs/2.1.json, etc.
|
|
1298
|
+
// alongside the matching scriptDir)
|
|
1299
|
+
// 2. specs/default.json — explicit fallback
|
|
1300
|
+
// 3. spec.json — legacy single-spec layout
|
|
1301
|
+
// Missing files fall through silently to the next candidate.
|
|
1302
|
+
const candidates: string[] = [];
|
|
1303
|
+
if (Array.isArray((base as any).compatibility)) {
|
|
1304
|
+
for (const entry of (base as any).compatibility) {
|
|
1305
|
+
if (typeof entry?.spec !== 'string') continue;
|
|
1306
|
+
// If currentVersion is unknown (cli-manager hasn't probed yet)
|
|
1307
|
+
// we still let compatibility entries that don't pin a version
|
|
1308
|
+
// through, plus any entry whose pin matches.
|
|
1309
|
+
const matches = !entry.ideVersion
|
|
1310
|
+
|| (currentVersion && this.matchesVersion(currentVersion, entry.ideVersion))
|
|
1311
|
+
|| !currentVersion;
|
|
1312
|
+
if (matches) candidates.push(path.join(providerDir, entry.spec));
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
candidates.push(path.join(providerDir, 'specs', 'default.json'));
|
|
1316
|
+
candidates.push(path.join(providerDir, 'spec.json'));
|
|
1317
|
+
const specPath = candidates.find((p: string) => fs.existsSync(p));
|
|
1318
|
+
if (specPath) {
|
|
1319
|
+
// Hand the resolved spec path off to route.ts via a hidden field
|
|
1320
|
+
// so the routing layer doesn't have to repeat the candidate walk.
|
|
1321
|
+
(resolved as any)._resolvedSpecPath = specPath;
|
|
1322
|
+
// Extract control_bar + native_history directly from the JSON header.
|
|
1323
|
+
let specControls: any[] | undefined;
|
|
1324
|
+
let nh: any | undefined;
|
|
1325
|
+
try {
|
|
1326
|
+
const rawSpec = JSON.parse(fs.readFileSync(specPath, 'utf8'));
|
|
1327
|
+
specControls = rawSpec.control_bar;
|
|
1328
|
+
nh = rawSpec.native_history;
|
|
1329
|
+
} catch { /* unreadable spec — leave controls/native unavailable */ }
|
|
1330
|
+
// Stub each control_bar entry as a provider.scripts.<id>. The
|
|
1331
|
+
// upstream invoke_provider_script gate checks that the script
|
|
1332
|
+
// name exists on provider.scripts before calling adapter.invokeScript;
|
|
1333
|
+
// for spec providers the *actual* dispatch happens inside
|
|
1334
|
+
// SpecCliAdapter.invokeScript which maps the name to control_bar.
|
|
1335
|
+
// The stub is just a presence marker so the gate doesn't reject.
|
|
1336
|
+
if (specControls && specControls.length > 0) {
|
|
1337
|
+
resolved.scripts = { ...(resolved.scripts || {}) };
|
|
1338
|
+
for (const ctl of specControls) {
|
|
1339
|
+
if (!(resolved.scripts as any)[ctl.id]) {
|
|
1340
|
+
(resolved.scripts as any)[ctl.id] = (..._args: unknown[]) => ({
|
|
1341
|
+
__spec_control: true,
|
|
1342
|
+
controlId: ctl.id,
|
|
1343
|
+
actionType: ctl.action.type,
|
|
1344
|
+
});
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
// Bridge the spec control_bar into the web-facing controls schema so
|
|
1348
|
+
// the dashboard chat bar actually renders Model/Mode pickers. Only
|
|
1349
|
+
// synthesize when the provider hasn't already declared its own
|
|
1350
|
+
// `controls` in provider.v1.json (e.g. hermes-cli) — an explicit
|
|
1351
|
+
// declaration wins and must not be clobbered.
|
|
1352
|
+
const hasDeclaredControls = Array.isArray((resolved as any).controls)
|
|
1353
|
+
&& (resolved as any).controls.length > 0;
|
|
1354
|
+
if (!hasDeclaredControls) {
|
|
1355
|
+
const synthesized = synthesizeControlsFromControlBar(specControls);
|
|
1356
|
+
if (synthesized.length > 0) {
|
|
1357
|
+
resolved.controls = synthesized;
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
if (nh) {
|
|
1362
|
+
let reader: ((input: any) => any) | null = null;
|
|
1363
|
+
let format = 'spec';
|
|
1364
|
+
|
|
1365
|
+
if (nh.source) {
|
|
1366
|
+
format = `spec-${nh.source.kind}`;
|
|
1367
|
+
reader = (input: any) => executeNativeHistory(nh, input);
|
|
1368
|
+
} else if (nh.override_path) {
|
|
1369
|
+
const overrideFile = path.resolve(providerDir, nh.override_path);
|
|
1370
|
+
if (fs.existsSync(overrideFile)) {
|
|
1371
|
+
try {
|
|
1372
|
+
registerProviderScriptRootSafely(path.dirname(path.dirname(providerDir)));
|
|
1373
|
+
delete require.cache[require.resolve(overrideFile)];
|
|
1374
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
1375
|
+
const mod = require(overrideFile);
|
|
1376
|
+
const fn = typeof mod === 'function' ? mod : (mod && typeof mod.default === 'function' ? mod.default : null);
|
|
1377
|
+
if (fn) {
|
|
1378
|
+
format = 'spec-override';
|
|
1379
|
+
reader = (input: any) => fn(input);
|
|
1380
|
+
}
|
|
1381
|
+
} catch { /* fall through — leave native unavailable */ }
|
|
1382
|
+
}
|
|
1383
|
+
} else if (nh.reader) {
|
|
1384
|
+
const dispatch = createNativeHistoryDispatcher(nh.reader as ReaderId);
|
|
1385
|
+
format = nh.reader;
|
|
1386
|
+
reader = (input: any) => dispatch(input);
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
if (reader) {
|
|
1390
|
+
resolved.scripts = { ...(resolved.scripts || {}) };
|
|
1391
|
+
(resolved.scripts as any).readNativeHistory = reader;
|
|
1392
|
+
(resolved as any).nativeHistory = {
|
|
1393
|
+
format,
|
|
1394
|
+
watchPath: undefined,
|
|
1395
|
+
scripts: { readSession: 'readNativeHistory' },
|
|
1396
|
+
mode: 'native-source',
|
|
1397
|
+
};
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
} catch {
|
|
1402
|
+
// Best-effort — spec wiring failure must not break legacy providers.
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1009
1406
|
return resolved;
|
|
1010
1407
|
}
|
|
1011
1408
|
|
|
@@ -1016,16 +1413,27 @@ export class ProviderLoader {
|
|
|
1016
1413
|
private loadScriptsFromDir(type: string, scriptDir: string): Partial<ProviderScripts> | null {
|
|
1017
1414
|
const providerDir = this.findProviderDirInternal(type);
|
|
1018
1415
|
if (!providerDir) {
|
|
1019
|
-
this
|
|
1416
|
+
// No provider dir for this type — a spec-only provider with no
|
|
1417
|
+
// legacy scripts/v1 layout is a normal configuration, not a
|
|
1418
|
+
// problem to surface at INFO. resolve() calls this on every
|
|
1419
|
+
// request; INFO spam every 200ms drowns out the real signal.
|
|
1420
|
+
this.debugLog(`[loadScriptsFromDir] ${type}: providerDir not found`);
|
|
1020
1421
|
return null;
|
|
1021
1422
|
}
|
|
1022
1423
|
|
|
1023
1424
|
const dir = path.join(providerDir, scriptDir);
|
|
1024
1425
|
if (!fs.existsSync(dir)) {
|
|
1025
|
-
this.
|
|
1426
|
+
this.debugLog(`[loadScriptsFromDir] ${type}: dir not found: ${dir}`);
|
|
1026
1427
|
return null;
|
|
1027
1428
|
}
|
|
1028
1429
|
|
|
1430
|
+
// Register the provider's *parent root* (e.g. .../adhdev-providers/) so
|
|
1431
|
+
// the require whitelist gates every script + every _shared helper this
|
|
1432
|
+
// provider may reach. Picking the grandparent (one above the category
|
|
1433
|
+
// dir `cli/`) lets sibling helpers in `_shared` resolve while still
|
|
1434
|
+
// blocking `../../etc/...` escapes. Idempotent.
|
|
1435
|
+
registerProviderScriptRootSafely(path.dirname(path.dirname(providerDir)));
|
|
1436
|
+
|
|
1029
1437
|
// Return cached scripts if available (cleared on reload/watch)
|
|
1030
1438
|
const cached = this.scriptsCache.get(dir);
|
|
1031
1439
|
if (cached) return cached;
|
|
@@ -1036,7 +1444,7 @@ export class ProviderLoader {
|
|
|
1036
1444
|
try {
|
|
1037
1445
|
delete require.cache[require.resolve(scriptsJs)];
|
|
1038
1446
|
const loaded = require(scriptsJs);
|
|
1039
|
-
this.
|
|
1447
|
+
this.debugLog(`[loadScriptsFromDir] ${type}: loaded scripts.js from ${dir} (${Object.keys(loaded).length} exports)`);
|
|
1040
1448
|
this.scriptsCache.set(dir, loaded);
|
|
1041
1449
|
return loaded;
|
|
1042
1450
|
} catch (e) {
|
|
@@ -1067,13 +1475,17 @@ export class ProviderLoader {
|
|
|
1067
1475
|
awaitWriteFinish: { stabilityThreshold: 200, pollInterval: 50 },
|
|
1068
1476
|
});
|
|
1069
1477
|
|
|
1478
|
+
let reloadTimer: ReturnType<typeof setTimeout> | null = null;
|
|
1070
1479
|
const handleChange = (filePath: string) => {
|
|
1071
1480
|
if (/[\/\\]fixtures[\/\\]/.test(filePath)) {
|
|
1072
1481
|
return;
|
|
1073
1482
|
}
|
|
1074
1483
|
if (filePath.endsWith('.js') || filePath.endsWith('.json')) {
|
|
1075
|
-
|
|
1076
|
-
|
|
1484
|
+
if (reloadTimer) clearTimeout(reloadTimer);
|
|
1485
|
+
reloadTimer = setTimeout(() => {
|
|
1486
|
+
this.log(`File changed: ${path.basename(filePath)}, reloading...`);
|
|
1487
|
+
this.reload();
|
|
1488
|
+
}, 300);
|
|
1077
1489
|
}
|
|
1078
1490
|
};
|
|
1079
1491
|
|
|
@@ -1124,13 +1536,118 @@ export class ProviderLoader {
|
|
|
1124
1536
|
*
|
|
1125
1537
|
* @returns Whether an update occurred
|
|
1126
1538
|
*/
|
|
1539
|
+
/**
|
|
1540
|
+
* Sync providers from the ADHDev registry (registry.adhf.dev).
|
|
1541
|
+
*
|
|
1542
|
+
* Downloads only providers whose server checksum differs from the locally
|
|
1543
|
+
* cached checksum. Falls back gracefully to the GitHub tarball path if the
|
|
1544
|
+
* registry is unreachable or returns an unexpected response.
|
|
1545
|
+
*
|
|
1546
|
+
* Returns `{ updated: true }` when at least one provider file changed on disk,
|
|
1547
|
+
* `{ updated: false }` when everything is already current, or
|
|
1548
|
+
* `{ updated: false, error }` when the registry couldn't be reached and we
|
|
1549
|
+
* should proceed to the GitHub tarball fallback.
|
|
1550
|
+
*/
|
|
1551
|
+
async fetchFromRegistry(): Promise<{ updated: boolean; error?: string }> {
|
|
1552
|
+
if (this.disableUpstream) {
|
|
1553
|
+
this.log('Registry sync skipped (sourceMode=no-upstream)');
|
|
1554
|
+
return { updated: false };
|
|
1555
|
+
}
|
|
1556
|
+
this.log(`Registry sync starting (${ProviderLoader.REGISTRY_BASE_URL})...`);
|
|
1557
|
+
|
|
1558
|
+
const https = require('https') as typeof import('https');
|
|
1559
|
+
const regMetaPath = path.join(this.upstreamDir, ProviderLoader.REGISTRY_META_FILE);
|
|
1560
|
+
|
|
1561
|
+
// Load cached checksums
|
|
1562
|
+
let cachedChecksums: Record<string, string> = {};
|
|
1563
|
+
try {
|
|
1564
|
+
if (fs.existsSync(regMetaPath)) {
|
|
1565
|
+
cachedChecksums = JSON.parse(fs.readFileSync(regMetaPath, 'utf-8')).checksums ?? {};
|
|
1566
|
+
}
|
|
1567
|
+
} catch { }
|
|
1568
|
+
|
|
1569
|
+
try {
|
|
1570
|
+
// 1. Fetch provider list
|
|
1571
|
+
const listUrl = `${ProviderLoader.REGISTRY_BASE_URL}/providers`;
|
|
1572
|
+
const listBody = await new Promise<string>((resolve, reject) => {
|
|
1573
|
+
const req = https.get(listUrl, { headers: { 'User-Agent': 'adhdev-daemon', 'Accept': 'application/json' }, timeout: 10000 }, (res) => {
|
|
1574
|
+
if (res.statusCode !== 200) { reject(new Error(`registry list HTTP ${res.statusCode}`)); return; }
|
|
1575
|
+
const chunks: Buffer[] = [];
|
|
1576
|
+
res.on('data', (c: Buffer) => chunks.push(c));
|
|
1577
|
+
res.on('end', () => resolve(Buffer.concat(chunks).toString('utf-8')));
|
|
1578
|
+
});
|
|
1579
|
+
req.on('error', reject);
|
|
1580
|
+
req.on('timeout', () => { req.destroy(); reject(new Error('registry list timeout')); });
|
|
1581
|
+
});
|
|
1582
|
+
|
|
1583
|
+
const list = JSON.parse(listBody) as { providers: Array<{ type: string; category: string; checksum: string; version: string }> };
|
|
1584
|
+
if (!Array.isArray(list.providers)) throw new Error('unexpected registry response shape');
|
|
1585
|
+
|
|
1586
|
+
let updatedCount = 0;
|
|
1587
|
+
|
|
1588
|
+
for (const entry of list.providers) {
|
|
1589
|
+
const { type, category, checksum, version } = entry;
|
|
1590
|
+
const cacheKey = `${category}/${type}`;
|
|
1591
|
+
if (cachedChecksums[cacheKey] === checksum) continue; // already current
|
|
1592
|
+
|
|
1593
|
+
// Download this provider's manifest
|
|
1594
|
+
const dlUrl = `${ProviderLoader.REGISTRY_BASE_URL}/providers/${type}/${version}/download`;
|
|
1595
|
+
const manifestBody = await new Promise<string>((resolve, reject) => {
|
|
1596
|
+
const req = https.get(dlUrl, { headers: { 'User-Agent': 'adhdev-daemon', 'Accept': 'application/json' }, timeout: 30000 }, (res) => {
|
|
1597
|
+
if (res.statusCode !== 200) { reject(new Error(`registry download HTTP ${res.statusCode} for ${type}@${version}`)); return; }
|
|
1598
|
+
const chunks: Buffer[] = [];
|
|
1599
|
+
res.on('data', (c: Buffer) => chunks.push(c));
|
|
1600
|
+
res.on('end', () => resolve(Buffer.concat(chunks).toString('utf-8')));
|
|
1601
|
+
});
|
|
1602
|
+
req.on('error', reject);
|
|
1603
|
+
req.on('timeout', () => { req.destroy(); reject(new Error(`download timeout for ${type}`)); });
|
|
1604
|
+
});
|
|
1605
|
+
|
|
1606
|
+
// Verify checksum
|
|
1607
|
+
const actualChecksum = await new Promise<string>((resolve) => {
|
|
1608
|
+
const crypto = require('crypto') as typeof import('crypto');
|
|
1609
|
+
resolve(crypto.createHash('sha256').update(manifestBody, 'utf-8').digest('hex'));
|
|
1610
|
+
});
|
|
1611
|
+
if (actualChecksum !== checksum) {
|
|
1612
|
+
this.log(`⚠ Registry checksum mismatch for ${type}@${version} — skipping`);
|
|
1613
|
+
continue;
|
|
1614
|
+
}
|
|
1615
|
+
|
|
1616
|
+
// Write to upstream dir
|
|
1617
|
+
const providerDir = path.join(this.upstreamDir, category, type);
|
|
1618
|
+
fs.mkdirSync(providerDir, { recursive: true });
|
|
1619
|
+
fs.writeFileSync(path.join(providerDir, 'provider.json'), manifestBody, 'utf-8');
|
|
1620
|
+
|
|
1621
|
+
cachedChecksums[cacheKey] = checksum;
|
|
1622
|
+
updatedCount++;
|
|
1623
|
+
this.log(`✓ Registry updated: ${category}/${type}@${version}`);
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
// Persist updated checksums
|
|
1627
|
+
fs.mkdirSync(this.upstreamDir, { recursive: true });
|
|
1628
|
+
fs.writeFileSync(regMetaPath, JSON.stringify({
|
|
1629
|
+
checksums: cachedChecksums,
|
|
1630
|
+
syncedAt: new Date().toISOString(),
|
|
1631
|
+
providerCount: list.providers.length,
|
|
1632
|
+
}, null, 2));
|
|
1633
|
+
|
|
1634
|
+
this.log(`Registry sync complete: ${list.providers.length} providers, ${updatedCount} updated`);
|
|
1635
|
+
return { updated: updatedCount > 0 };
|
|
1636
|
+
} catch (e: any) {
|
|
1637
|
+
this.log(`⚠ Registry sync failed (falling back to GitHub tarball): ${e?.message}`);
|
|
1638
|
+
return { updated: false, error: e?.message };
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1127
1642
|
async fetchLatest(): Promise<{ updated: boolean; error?: string }> {
|
|
1128
1643
|
if (this.disableUpstream) {
|
|
1129
1644
|
this.log('Upstream fetch skipped (sourceMode=no-upstream)');
|
|
1130
1645
|
return { updated: false };
|
|
1131
1646
|
}
|
|
1132
1647
|
const https = require('https') as typeof import('https');
|
|
1133
|
-
const {
|
|
1648
|
+
const { exec } = require('child_process') as typeof import('child_process');
|
|
1649
|
+
const { promisify } = require('util');
|
|
1650
|
+
const execAsync = promisify(exec);
|
|
1134
1651
|
|
|
1135
1652
|
const metaPath = path.join(this.upstreamDir, ProviderLoader.META_FILE);
|
|
1136
1653
|
let prevEtag = '';
|
|
@@ -1207,7 +1724,7 @@ export class ProviderLoader {
|
|
|
1207
1724
|
|
|
1208
1725
|
// Extract
|
|
1209
1726
|
fs.mkdirSync(tmpExtract, { recursive: true });
|
|
1210
|
-
|
|
1727
|
+
await execAsync(`tar -xzf "${tmpTar}" -C "${tmpExtract}"`, { timeout: 30000 });
|
|
1211
1728
|
|
|
1212
1729
|
// Tarball internal structure: adhdev-providers-main/ide/... → strip 1 level
|
|
1213
1730
|
const extracted = fs.readdirSync(tmpExtract);
|
|
@@ -1315,15 +1832,17 @@ export class ProviderLoader {
|
|
|
1315
1832
|
} catch { }
|
|
1316
1833
|
}
|
|
1317
1834
|
|
|
1318
|
-
/** Count provider files (provider.
|
|
1835
|
+
/** Count provider files (provider.v1.json or provider.json — at most one per dir). */
|
|
1319
1836
|
private countProviders(dir: string): number {
|
|
1320
1837
|
if (!fs.existsSync(dir)) return 0;
|
|
1321
1838
|
let count = 0;
|
|
1322
1839
|
const scan = (d: string) => {
|
|
1323
1840
|
try {
|
|
1324
|
-
|
|
1841
|
+
const entries = fs.readdirSync(d, { withFileTypes: true });
|
|
1842
|
+
const hasManifest = entries.some(e => e.name === 'provider.v1.json' || e.name === 'provider.json');
|
|
1843
|
+
if (hasManifest) count++;
|
|
1844
|
+
for (const entry of entries) {
|
|
1325
1845
|
if (entry.isDirectory()) scan(path.join(d, entry.name));
|
|
1326
|
-
else if (entry.name === 'provider.json') count++;
|
|
1327
1846
|
}
|
|
1328
1847
|
} catch { }
|
|
1329
1848
|
};
|
|
@@ -1372,11 +1891,15 @@ export class ProviderLoader {
|
|
|
1372
1891
|
return args ? args.map((arg) => /\s/.test(arg) ? JSON.stringify(arg) : arg).join(' ') : '';
|
|
1373
1892
|
}
|
|
1374
1893
|
const schemaDef = this.getSettingsSchema(providerType)[key];
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1894
|
+
// (fix) Previously this hard-coded `autoApprove` boolean default to `true`,
|
|
1895
|
+
// overriding whatever schemaDef.default the provider.json declared. That
|
|
1896
|
+
// surfaced as soon as a provider added an `autoApprove` schema entry with
|
|
1897
|
+
// default=false: the user had never opted in but the daemon treated the
|
|
1898
|
+
// session as auto-approve, which then triggered recordAutoApproval every
|
|
1899
|
+
// time the CLI showed an approval modal — producing a flood of system
|
|
1900
|
+
// "Auto-approved: ..." messages and keeping the session pinned to
|
|
1901
|
+
// generating while modals cycled in and out. Trust the schemaDef.default.
|
|
1902
|
+
const defaultVal = schemaDef ? schemaDef.default : undefined;
|
|
1380
1903
|
|
|
1381
1904
|
const config = this.readConfig();
|
|
1382
1905
|
const userVal = config?.providerSettings?.[providerType]?.[key];
|
|
@@ -1490,10 +2013,17 @@ export class ProviderLoader {
|
|
|
1490
2013
|
...this.getSyntheticSettings(type, provider),
|
|
1491
2014
|
...(provider.settings || {}),
|
|
1492
2015
|
};
|
|
2016
|
+
// (fix) Previously this clause forced `autoApprove.default = true` for any
|
|
2017
|
+
// boolean autoApprove schema, even when the provider.json explicitly set
|
|
2018
|
+
// `default: false`. Combined with the synthetic-settings fallback at
|
|
2019
|
+
// getSyntheticSettings (which also defaults autoApprove to true when the
|
|
2020
|
+
// provider doesn't supply one), that meant CLI providers silently turned on
|
|
2021
|
+
// auto-approval, producing a flood of "Auto-approved: ..." system messages
|
|
2022
|
+
// every time an approval modal appeared and pinning the session to
|
|
2023
|
+
// generating while modals cycled. Trust the provider's declared default.
|
|
1493
2024
|
if (result.autoApprove?.type === 'boolean') {
|
|
1494
2025
|
result.autoApprove = {
|
|
1495
2026
|
...result.autoApprove,
|
|
1496
|
-
default: true,
|
|
1497
2027
|
public: true,
|
|
1498
2028
|
label: result.autoApprove.label || 'Auto Approve',
|
|
1499
2029
|
description: result.autoApprove.description || 'Automatically approve actionable prompts without sending approval alerts.',
|
|
@@ -1518,7 +2048,10 @@ export class ProviderLoader {
|
|
|
1518
2048
|
if (!provider.settings?.autoApprove) {
|
|
1519
2049
|
result.autoApprove = {
|
|
1520
2050
|
type: 'boolean',
|
|
1521
|
-
default
|
|
2051
|
+
// (fix) Safe default is *off*. Auto-approving every modal without the
|
|
2052
|
+
// user opting in produced silent-bash-execution surprises and the
|
|
2053
|
+
// "Auto-approved: ..." system-message flood seen on AGY/Codex.
|
|
2054
|
+
default: false,
|
|
1522
2055
|
public: true,
|
|
1523
2056
|
label: 'Auto Approve',
|
|
1524
2057
|
description: 'Automatically approve actionable prompts without sending approval alerts.',
|
|
@@ -1581,23 +2114,32 @@ export class ProviderLoader {
|
|
|
1581
2114
|
const cat = provider.category;
|
|
1582
2115
|
|
|
1583
2116
|
const searchRoots = this.getProviderRoots();
|
|
2117
|
+
const hasManifest = (dir: string) =>
|
|
2118
|
+
fs.existsSync(path.join(dir, 'provider.v1.json')) || fs.existsSync(path.join(dir, 'provider.json'));
|
|
2119
|
+
const readManifestType = (dir: string): string | null => {
|
|
2120
|
+
for (const file of ['provider.v1.json', 'provider.json']) {
|
|
2121
|
+
const p = path.join(dir, file);
|
|
2122
|
+
if (!fs.existsSync(p)) continue;
|
|
2123
|
+
try {
|
|
2124
|
+
const data = JSON.parse(fs.readFileSync(p, 'utf-8'));
|
|
2125
|
+
if (typeof data?.type === 'string') return data.type;
|
|
2126
|
+
} catch { /* skip */ }
|
|
2127
|
+
}
|
|
2128
|
+
return null;
|
|
2129
|
+
};
|
|
1584
2130
|
for (const root of searchRoots) {
|
|
1585
2131
|
if (!fs.existsSync(root)) continue;
|
|
1586
2132
|
const candidate = this.getProviderDir(root, cat, type);
|
|
1587
|
-
if (
|
|
2133
|
+
if (hasManifest(candidate)) return candidate;
|
|
1588
2134
|
// Scan category dir for type match
|
|
1589
2135
|
const catDir = path.join(root, cat);
|
|
1590
2136
|
if (fs.existsSync(catDir)) {
|
|
1591
2137
|
try {
|
|
1592
2138
|
for (const entry of fs.readdirSync(catDir, { withFileTypes: true })) {
|
|
1593
2139
|
if (!entry.isDirectory()) continue;
|
|
1594
|
-
const
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
const data = JSON.parse(fs.readFileSync(jsonPath, 'utf-8'));
|
|
1598
|
-
if (data.type === type) return path.join(catDir, entry.name);
|
|
1599
|
-
} catch { /* skip */ }
|
|
1600
|
-
}
|
|
2140
|
+
const entryDir = path.join(catDir, entry.name);
|
|
2141
|
+
const manifestType = readManifestType(entryDir);
|
|
2142
|
+
if (manifestType === type) return entryDir;
|
|
1601
2143
|
}
|
|
1602
2144
|
} catch { /* skip */ }
|
|
1603
2145
|
}
|
|
@@ -1690,17 +2232,44 @@ export class ProviderLoader {
|
|
|
1690
2232
|
return;
|
|
1691
2233
|
}
|
|
1692
2234
|
|
|
1693
|
-
//
|
|
2235
|
+
// v1-first manifest selection. provider.v1.json (the SDK-shape
|
|
2236
|
+
// manifest with `overrides`, `tui`, `source`, `canonicalHistory`)
|
|
2237
|
+
// wins over provider.json (legacy). Without this branch the v1
|
|
2238
|
+
// file is silently ignored — that's how the codex-cli `overrides`
|
|
2239
|
+
// path and the tui-block builders went un-honored for the first
|
|
2240
|
+
// pass of SDK rollout.
|
|
2241
|
+
const hasV1 = entries.some(e => e.name === 'provider.v1.json');
|
|
1694
2242
|
const hasJson = entries.some(e => e.name === 'provider.json');
|
|
1695
2243
|
|
|
1696
|
-
if (hasJson) {
|
|
1697
|
-
const
|
|
2244
|
+
if (hasV1 || hasJson) {
|
|
2245
|
+
const manifestFile = hasV1 ? 'provider.v1.json' : 'provider.json';
|
|
2246
|
+
const jsonPath = path.join(d, manifestFile);
|
|
1698
2247
|
try {
|
|
1699
2248
|
const raw = fs.readFileSync(jsonPath, 'utf-8');
|
|
1700
2249
|
const mod = JSON.parse(raw) as Omit<ProviderModule, 'extensionIdPattern'> & {
|
|
1701
2250
|
extensionIdPattern?: RegExp | string;
|
|
1702
2251
|
};
|
|
1703
2252
|
|
|
2253
|
+
// Validate v1 manifests against the SDK schema. Failures are
|
|
2254
|
+
// surfaced as a single warning line with all issues attached
|
|
2255
|
+
// so manifest authors don't need to guess which field is wrong.
|
|
2256
|
+
// Loading still proceeds — bricking the daemon on a single
|
|
2257
|
+
// bad field would be worse than running with a known warning.
|
|
2258
|
+
if (hasV1 && mod?.category === 'cli') {
|
|
2259
|
+
try {
|
|
2260
|
+
const { validateCliProviderManifest, formatManifestValidationIssues } =
|
|
2261
|
+
require('./sdk/v1/validators/manifest.js') as typeof import('./sdk/v1/validators/manifest.js');
|
|
2262
|
+
const validation = validateCliProviderManifest(mod);
|
|
2263
|
+
if (!validation.ok) {
|
|
2264
|
+
this.log(`⚠ ${jsonPath}: schema validation failed:\n${formatManifestValidationIssues(validation.issues)}`);
|
|
2265
|
+
}
|
|
2266
|
+
} catch (e: any) {
|
|
2267
|
+
// Validator load failed — log once and continue so a
|
|
2268
|
+
// broken validator can't take down provider loading.
|
|
2269
|
+
this.log(`⚠ ${jsonPath}: validator unavailable: ${e?.message || e}`);
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2272
|
+
|
|
1704
2273
|
// Restore RegExp fields from JSON (extensionIdPattern)
|
|
1705
2274
|
if (typeof mod.extensionIdPattern === 'string') {
|
|
1706
2275
|
const flags = mod.extensionIdPattern_flags || '';
|
|
@@ -1712,6 +2281,22 @@ export class ProviderLoader {
|
|
|
1712
2281
|
...(extensionIdPattern instanceof RegExp ? { extensionIdPattern } : {}),
|
|
1713
2282
|
};
|
|
1714
2283
|
|
|
2284
|
+
// v1 manifests use `nativeHistory` as the canonical field name.
|
|
2285
|
+
// Legacy v0 manifests use `canonicalHistory`. The daemon's
|
|
2286
|
+
// runtime + downstream code reads `provider.nativeHistory`, so
|
|
2287
|
+
// for legacy manifests we copy `canonicalHistory` into
|
|
2288
|
+
// `nativeHistory` here. We also keep `canonicalHistory`
|
|
2289
|
+
// populated in both directions (deprecated alias) so any
|
|
2290
|
+
// external consumers still reading the old name keep working
|
|
2291
|
+
// during the one-release deprecation window.
|
|
2292
|
+
const nh = (normalizedProvider as any).nativeHistory;
|
|
2293
|
+
const ch = (normalizedProvider as any).canonicalHistory;
|
|
2294
|
+
if (nh && !ch) {
|
|
2295
|
+
(normalizedProvider as any).canonicalHistory = nh;
|
|
2296
|
+
} else if (ch && !nh) {
|
|
2297
|
+
(normalizedProvider as any).nativeHistory = ch;
|
|
2298
|
+
}
|
|
2299
|
+
|
|
1715
2300
|
const validation = validateProviderDefinition(normalizedProvider);
|
|
1716
2301
|
for (const warning of validation.warnings) {
|
|
1717
2302
|
this.log(`⚠ ${jsonPath}: ${warning}`);
|
|
@@ -1725,6 +2310,10 @@ export class ProviderLoader {
|
|
|
1725
2310
|
const scriptsPath = path.join(d, 'scripts.js');
|
|
1726
2311
|
if (!hasCompatibility && fs.existsSync(scriptsPath)) {
|
|
1727
2312
|
try {
|
|
2313
|
+
// Gate the IDE/extension scripts.js (legacy single-file
|
|
2314
|
+
// format) under the same whitelist. `d` here is the
|
|
2315
|
+
// provider dir; its grandparent contains _shared.
|
|
2316
|
+
registerProviderScriptRootSafely(path.dirname(path.dirname(d)));
|
|
1728
2317
|
delete require.cache[require.resolve(scriptsPath)];
|
|
1729
2318
|
const scripts = require(scriptsPath) as Partial<ProviderScripts>;
|
|
1730
2319
|
normalizedProvider.scripts = scripts;
|
|
@@ -1733,14 +2322,40 @@ export class ProviderLoader {
|
|
|
1733
2322
|
}
|
|
1734
2323
|
}
|
|
1735
2324
|
|
|
2325
|
+
// Classify trust based on which on-disk layer this manifest
|
|
2326
|
+
// came from + whether it ships JavaScript hooks. The dashboard
|
|
2327
|
+
// uses this to render trust badges; non-spec external manifests
|
|
2328
|
+
// need an explicit user confirm before activation.
|
|
2329
|
+
const externalDirAbs = path.join(os.homedir(), '.adhdev', 'external');
|
|
2330
|
+
const layer: 'user' | 'upstream' | 'external' = d.startsWith(externalDirAbs)
|
|
2331
|
+
? 'external'
|
|
2332
|
+
: (d.startsWith(this.userDir) && !d.includes('.upstream') ? 'user' : 'upstream');
|
|
2333
|
+
try {
|
|
2334
|
+
const { inspectManifestShape, classifyTrust } =
|
|
2335
|
+
require('./provider-trust.js') as typeof import('./provider-trust.js');
|
|
2336
|
+
const shape = inspectManifestShape(mod as Record<string, unknown>);
|
|
2337
|
+
const trust = classifyTrust(layer, shape);
|
|
2338
|
+
(normalizedProvider as any)._sourceLayer = layer;
|
|
2339
|
+
(normalizedProvider as any)._sourceTrust = trust;
|
|
2340
|
+
(normalizedProvider as any)._manifestShape = shape;
|
|
2341
|
+
// For external-namespaced layouts (external/<source>/…) record
|
|
2342
|
+
// which source the manifest came from so dashboards can name
|
|
2343
|
+
// it in the trust badge.
|
|
2344
|
+
if (layer === 'external') {
|
|
2345
|
+
const rel = path.relative(externalDirAbs, d);
|
|
2346
|
+
const firstSeg = rel.split(path.sep)[0];
|
|
2347
|
+
if (firstSeg && firstSeg !== '..') (normalizedProvider as any)._sourceName = firstSeg;
|
|
2348
|
+
}
|
|
2349
|
+
} catch { /* best-effort — trust is enrichment, not gating */ }
|
|
2350
|
+
|
|
1736
2351
|
const existed = this.providers.has(normalizedProvider.type);
|
|
1737
2352
|
this.providers.set(normalizedProvider.type, normalizedProvider);
|
|
1738
2353
|
count++;
|
|
1739
|
-
|
|
1740
|
-
const source = d.startsWith(this.userDir) && !d.includes('.upstream')
|
|
1741
|
-
? 'user' : 'upstream';
|
|
2354
|
+
const source = (normalizedProvider as any)._sourceLayer ?? 'upstream';
|
|
1742
2355
|
const overrideWarning = existed && source === 'user' ? ' ⚠ OVERRIDES upstream' : '';
|
|
1743
|
-
|
|
2356
|
+
const sourceName = (normalizedProvider as any)._sourceName;
|
|
2357
|
+
const sourceLabel = sourceName ? `${source}/${sourceName}` : source;
|
|
2358
|
+
this.log(` ${existed ? '🔄' : '✅'} ${normalizedProvider.type} (${normalizedProvider.category}) — ${normalizedProvider.name} [${sourceLabel}]${overrideWarning}`);
|
|
1744
2359
|
}
|
|
1745
2360
|
} catch (e) {
|
|
1746
2361
|
this.log(`⚠ Failed to load ${jsonPath}: ${(e as Error).message}`);
|
|
@@ -1752,6 +2367,11 @@ export class ProviderLoader {
|
|
|
1752
2367
|
for (const entry of entries) {
|
|
1753
2368
|
if (!entry.isDirectory()) continue;
|
|
1754
2369
|
if (entry.name.startsWith('_') || entry.name.startsWith('.')) continue;
|
|
2370
|
+
// `examples/` is a documentation / scaffold tree (e.g. stub-cli),
|
|
2371
|
+
// not a real provider source. SDK authors copy from here when
|
|
2372
|
+
// writing a new provider; daemon-core tests reference the
|
|
2373
|
+
// manifest by path. Keep it off the dashboard's provider list.
|
|
2374
|
+
if (d === dir && entry.name === 'examples') continue;
|
|
1755
2375
|
if (excludeDirs && d === dir && excludeDirs.includes(entry.name)) continue;
|
|
1756
2376
|
scan(path.join(d, entry.name));
|
|
1757
2377
|
}
|