pi-better-server 0.4.0 → 0.6.0
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/package.json +8 -1
- package/scripts/copy-pi-test-providers.mjs +10 -0
- package/scripts/event-publication/README.md +26 -0
- package/scripts/event-publication/commit.mjs +21 -0
- package/scripts/event-publication/measure.mjs +87 -0
- package/scripts/event-publication/writer.mjs +6 -0
- package/scripts/measure-full-runtime/frontend.ts +24 -0
- package/scripts/measure-full-runtime/hosted-extension.ts +28 -0
- package/scripts/measure-full-runtime/probe.mjs +29 -0
- package/scripts/measure-full-runtime/recovery-trace-loader.mjs +51 -0
- package/scripts/measure-full-runtime/recovery-trace.mjs +16 -0
- package/scripts/measure-full-runtime.mjs +146 -0
- package/scripts/measure-shared-reads/probe.mjs +26 -2
- package/scripts/measure-shared-reads.mjs +44 -9
- package/scripts/private-runtime/package-lock.json +66 -4
- package/scripts/private-runtime/package.json +10 -2
- package/scripts/source-provenance.mjs +31 -0
- package/scripts/test-on-pi.sh +3 -9
- package/src/handshake.ts +1 -1
- package/src/hosted-session.ts +32 -4
- package/src/maintenance.ts +35 -7
- package/src/registry.ts +28 -4
- package/src/runtime/attempt-invalidation.ts +54 -0
- package/src/runtime/background-history.ts +151 -45
- package/src/runtime/background-policy.ts +27 -0
- package/src/runtime/background-tools.ts +389 -0
- package/src/runtime/background.ts +410 -48
- package/src/runtime/cancellation.ts +28 -7
- package/src/runtime/catalog-sources.ts +199 -0
- package/src/runtime/catalog.ts +53 -21
- package/src/runtime/client.ts +22 -2
- package/src/runtime/domain/assignment-inbox.mjs +119 -0
- package/src/runtime/domain/assignment-observation.d.mts +1 -1
- package/src/runtime/domain/assignment-observation.mjs +71 -33
- package/src/runtime/domain/background/process-identity.mjs +20 -2
- package/src/runtime/domain/background/process.mjs +3 -3
- package/src/runtime/domain/background/registry.mjs +89 -4
- package/src/runtime/domain/background/types.mjs +1 -0
- package/src/runtime/domain/background-service/adapter-contract.domain.mjs +83 -0
- package/src/runtime/domain/background-service/adapter-contract.ts +70 -0
- package/src/runtime/domain/background-service/batch.domain.mjs +91 -0
- package/src/runtime/domain/background-service/batch.ts +111 -0
- package/src/runtime/domain/background-service/conditions.domain.mjs +94 -0
- package/src/runtime/domain/background-service/conditions.ts +99 -0
- package/src/runtime/domain/background-service/delivery-observer.domain.mjs +37 -0
- package/src/runtime/domain/background-service/delivery-observer.ts +42 -0
- package/src/runtime/domain/background-service/failures.domain.mjs +209 -0
- package/src/runtime/domain/background-service/failures.ts +212 -0
- package/src/runtime/domain/background-service/goal-provider.domain.mjs +193 -0
- package/src/runtime/domain/background-service/goal-provider.ts +209 -0
- package/src/runtime/domain/background-service/index.domain.mjs +54 -0
- package/src/runtime/domain/background-service/index.ts +55 -0
- package/src/runtime/domain/background-service/logs.domain.mjs +129 -0
- package/src/runtime/domain/background-service/logs.ts +134 -0
- package/src/runtime/domain/background-service/maintenance.domain.mjs +95 -0
- package/src/runtime/domain/background-service/maintenance.ts +98 -0
- package/src/runtime/domain/background-service/managed-authority.domain.mjs +32 -0
- package/src/runtime/domain/background-service/managed-authority.ts +30 -0
- package/src/runtime/domain/background-service/managed-client.domain.mjs +79 -0
- package/src/runtime/domain/background-service/managed-client.ts +73 -0
- package/src/runtime/domain/background-service/managed-frontend.domain.mjs +225 -0
- package/src/runtime/domain/background-service/managed-frontend.ts +176 -0
- package/src/runtime/domain/background-service/navigator-provider.domain.mjs +492 -0
- package/src/runtime/domain/background-service/navigator-provider.ts +485 -0
- package/src/runtime/domain/background-service/observed-wait-client.domain.mjs +6 -0
- package/src/runtime/domain/background-service/observed-wait-client.ts +10 -0
- package/src/runtime/domain/background-service/observed-waits.domain.mjs +4080 -0
- package/src/runtime/domain/background-service/observed-waits.ts +4513 -0
- package/src/runtime/domain/background-service/output.domain.mjs +867 -0
- package/src/runtime/domain/background-service/output.ts +952 -0
- package/src/runtime/domain/background-service/process-identity.domain.mjs +129 -0
- package/src/runtime/domain/background-service/process-identity.ts +134 -0
- package/src/runtime/domain/background-service/process.domain.mjs +512 -0
- package/src/runtime/domain/background-service/process.ts +532 -0
- package/src/runtime/domain/background-service/prompt.domain.mjs +58 -0
- package/src/runtime/domain/background-service/prompt.ts +72 -0
- package/src/runtime/domain/background-service/registry.domain.mjs +460 -0
- package/src/runtime/domain/background-service/registry.ts +450 -0
- package/src/runtime/domain/background-service/remote-task-preset.domain.mjs +67 -0
- package/src/runtime/domain/background-service/remote-task-preset.ts +127 -0
- package/src/runtime/domain/background-service/runtime.domain.mjs +1511 -0
- package/src/runtime/domain/background-service/runtime.ts +1636 -0
- package/src/runtime/domain/background-service/sandbox.domain.mjs +735 -0
- package/src/runtime/domain/background-service/sandbox.ts +913 -0
- package/src/runtime/domain/background-service/shared-callback-batcher.domain.mjs +777 -0
- package/src/runtime/domain/background-service/shared-callback-batcher.ts +956 -0
- package/src/runtime/domain/background-service/shared-execution-policy.domain.mjs +50 -0
- package/src/runtime/domain/background-service/shared-execution-policy.ts +61 -0
- package/src/runtime/domain/background-service/shared-failure-observations.domain.mjs +1078 -0
- package/src/runtime/domain/background-service/shared-failure-observations.ts +1166 -0
- package/src/runtime/domain/background-service/shared-harness-settings.domain.mjs +126 -0
- package/src/runtime/domain/background-service/shared-harness-settings.ts +116 -0
- package/src/runtime/domain/background-service/shared-log-utils.domain.mjs +1223 -0
- package/src/runtime/domain/background-service/shared-log-utils.ts +1492 -0
- package/src/runtime/domain/background-service/shared-navigator-panels.domain.mjs +289 -0
- package/src/runtime/domain/background-service/shared-navigator-panels.ts +272 -0
- package/src/runtime/domain/background-service/shared-navigator.domain.mjs +1930 -0
- package/src/runtime/domain/background-service/shared-navigator.ts +1962 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/assignment-inbox.mjs +144 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/assignment-observation.mjs +189 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/index.domain.mjs +51 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/index.ts +122 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-changes.domain.mjs +75 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-changes.ts +73 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-outcomes.domain.mjs +163 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-outcomes.ts +174 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-parent-callbacks.domain.mjs +66 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-parent-callbacks.ts +68 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.domain.mjs +87 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.ts +90 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.domain.mjs +97 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.ts +139 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/errors.domain.mjs +12 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/errors.ts +79 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.domain.mjs +342 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.ts +513 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.domain.mjs +283 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.ts +458 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/recovery.domain.mjs +52 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/recovery.ts +55 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.domain.mjs +114 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.ts +140 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.domain.mjs +280 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.ts +442 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.domain.mjs +420 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.ts +441 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/sqlite.domain.mjs +194 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/sqlite.ts +239 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.domain.mjs +275 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.ts +585 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.domain.mjs +120 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.ts +142 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/task-cancellation.domain.mjs +188 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/task-cancellation.ts +224 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.domain.mjs +25 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.ts +707 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/upgrade.domain.mjs +22 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/upgrade.ts +22 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/validate.domain.mjs +234 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/validate.ts +241 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/waits.domain.mjs +851 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/waits.ts +1424 -0
- package/src/runtime/domain/background-service/shared-permission-blocker.domain.mjs +40 -0
- package/src/runtime/domain/background-service/shared-permission-blocker.ts +48 -0
- package/src/runtime/domain/background-service/shared-render-scheduler.domain.mjs +41 -0
- package/src/runtime/domain/background-service/shared-render-scheduler.ts +47 -0
- package/src/runtime/domain/background-service/shared-sandbox-core.domain.mjs +1531 -0
- package/src/runtime/domain/background-service/shared-sandbox-core.ts +1757 -0
- package/src/runtime/domain/background-service/shared-sandbox-diagnostics.domain.mjs +591 -0
- package/src/runtime/domain/background-service/shared-sandbox-diagnostics.ts +491 -0
- package/src/runtime/domain/background-service/shared-ssh-core/index.domain.mjs +698 -0
- package/src/runtime/domain/background-service/shared-ssh-core/index.ts +979 -0
- package/src/runtime/domain/background-service/shared-stall-detector.domain.mjs +37 -0
- package/src/runtime/domain/background-service/shared-stall-detector.ts +69 -0
- package/src/runtime/domain/background-service/shared-work-client.mjs +303 -0
- package/src/runtime/domain/background-service/stall-attention.domain.mjs +29 -0
- package/src/runtime/domain/background-service/stall-attention.ts +31 -0
- package/src/runtime/domain/background-service/stall.domain.mjs +57 -0
- package/src/runtime/domain/background-service/stall.ts +57 -0
- package/src/runtime/domain/background-service/supervisor/README.md +111 -0
- package/src/runtime/domain/background-service/supervisor/emit-runner.mjs +90 -0
- package/src/runtime/domain/background-service/supervisor/generated/conditions.mjs +96 -0
- package/src/runtime/domain/background-service/supervisor/generated/identity.mjs +95 -0
- package/src/runtime/domain/background-service/supervisor/generated/process-identity.mjs +131 -0
- package/src/runtime/domain/background-service/supervisor/generated/process.mjs +514 -0
- package/src/runtime/domain/background-service/supervisor/generated/runner.mjs +872 -0
- package/src/runtime/domain/background-service/supervisor/generated/store.mjs +609 -0
- package/src/runtime/domain/background-service/supervisor/generated/types.mjs +50 -0
- package/src/runtime/domain/background-service/supervisor/identity.domain.mjs +93 -0
- package/src/runtime/domain/background-service/supervisor/identity.ts +99 -0
- package/src/runtime/domain/background-service/supervisor/index.domain.mjs +22 -0
- package/src/runtime/domain/background-service/supervisor/index.ts +37 -0
- package/src/runtime/domain/background-service/supervisor/invocation.domain.mjs +30 -0
- package/src/runtime/domain/background-service/supervisor/invocation.ts +44 -0
- package/src/runtime/domain/background-service/supervisor/runner.domain.mjs +870 -0
- package/src/runtime/domain/background-service/supervisor/runner.ts +982 -0
- package/src/runtime/domain/background-service/supervisor/store.domain.mjs +605 -0
- package/src/runtime/domain/background-service/supervisor/store.ts +651 -0
- package/src/runtime/domain/background-service/supervisor/supervisor.domain.mjs +721 -0
- package/src/runtime/domain/background-service/supervisor/supervisor.ts +804 -0
- package/src/runtime/domain/background-service/supervisor/types.domain.mjs +48 -0
- package/src/runtime/domain/background-service/supervisor/types.ts +394 -0
- package/src/runtime/domain/background-service/task-diagnostics.domain.mjs +60 -0
- package/src/runtime/domain/background-service/task-diagnostics.ts +71 -0
- package/src/runtime/domain/background-service/tools.domain.mjs +1050 -0
- package/src/runtime/domain/background-service/tools.ts +1142 -0
- package/src/runtime/domain/background-service/types.domain.mjs +5 -0
- package/src/runtime/domain/background-service/types.ts +236 -0
- package/src/runtime/domain/background-service/work-observation.domain.mjs +176 -0
- package/src/runtime/domain/background-service/work-observation.ts +144 -0
- package/src/runtime/domain/catalog/catalog-store.d.mts +9 -1
- package/src/runtime/domain/catalog/catalog-store.mjs +20 -22
- package/src/runtime/domain/coordinator/src/assignment-changes.mjs +75 -0
- package/src/runtime/domain/coordinator/src/assignment-outcomes.mjs +2 -0
- package/src/runtime/domain/coordinator/src/background-parent-callbacks.mjs +65 -0
- package/src/runtime/domain/coordinator/src/background-requests.mjs +86 -0
- package/src/runtime/domain/coordinator/src/discovery.mjs +4 -2
- package/src/runtime/domain/coordinator/src/operations.mjs +44 -4
- package/src/runtime/domain/coordinator/src/result-supervision.mjs +12 -0
- package/src/runtime/domain/coordinator/src/rows.mjs +2 -0
- package/src/runtime/domain/coordinator/src/schema.mjs +73 -21
- package/src/runtime/domain/coordinator/src/store.mjs +32 -3
- package/src/runtime/domain/coordinator/src/subagent-launch.mjs +119 -0
- package/src/runtime/domain/coordinator/src/types.mjs +1 -1
- package/src/runtime/domain/coordinator/src/upgrade.mjs +22 -0
- package/src/runtime/domain/health-observation.d.mts +3 -1
- package/src/runtime/domain/health-observation.mjs +189 -190
- package/src/runtime/domain/log-cursor.d.mts +2 -0
- package/src/runtime/domain/log-cursor.mjs +85 -16
- package/src/runtime/domain/parse.d.mts +4 -1
- package/src/runtime/domain/parse.mjs +50 -5
- package/src/runtime/domain/sandbox-policy/README.md +633 -0
- package/src/runtime/domain/sandbox-policy/background-admission.domain.mjs +83 -0
- package/src/runtime/domain/sandbox-policy/background-admission.ts +75 -0
- package/src/runtime/domain/sandbox-policy/commands.domain.mjs +245 -0
- package/src/runtime/domain/sandbox-policy/commands.ts +336 -0
- package/src/runtime/domain/sandbox-policy/deny-rules.domain.mjs +440 -0
- package/src/runtime/domain/sandbox-policy/deny-rules.ts +620 -0
- package/src/runtime/domain/sandbox-policy/diagnostics-command.domain.mjs +30 -0
- package/src/runtime/domain/sandbox-policy/diagnostics-command.ts +27 -0
- package/src/runtime/domain/sandbox-policy/events.domain.mjs +49 -0
- package/src/runtime/domain/sandbox-policy/events.ts +85 -0
- package/src/runtime/domain/sandbox-policy/files.domain.mjs +153 -0
- package/src/runtime/domain/sandbox-policy/files.ts +224 -0
- package/src/runtime/domain/sandbox-policy/index.domain.mjs +289 -0
- package/src/runtime/domain/sandbox-policy/index.ts +386 -0
- package/src/runtime/domain/sandbox-policy/package.json +66 -0
- package/src/runtime/domain/sandbox-policy/permission-settings.domain.mjs +36 -0
- package/src/runtime/domain/sandbox-policy/permission-settings.ts +46 -0
- package/src/runtime/domain/sandbox-policy/permissions-page.domain.mjs +309 -0
- package/src/runtime/domain/sandbox-policy/permissions-page.ts +295 -0
- package/src/runtime/domain/sandbox-policy/permissions.domain.mjs +98 -0
- package/src/runtime/domain/sandbox-policy/permissions.ts +125 -0
- package/src/runtime/domain/sandbox-policy/policy.domain.mjs +80 -0
- package/src/runtime/domain/sandbox-policy/policy.ts +102 -0
- package/src/runtime/domain/sandbox-policy/preferences.domain.mjs +55 -0
- package/src/runtime/domain/sandbox-policy/preferences.ts +82 -0
- package/src/runtime/domain/sandbox-policy/rules-page.domain.mjs +138 -0
- package/src/runtime/domain/sandbox-policy/rules-page.ts +176 -0
- package/src/runtime/domain/sandbox-policy/session-permissions.domain.mjs +22 -0
- package/src/runtime/domain/sandbox-policy/session-permissions.ts +24 -0
- package/src/runtime/domain/sandbox-policy/shared-harness-settings.domain.mjs +126 -0
- package/src/runtime/domain/sandbox-policy/shared-harness-settings.ts +116 -0
- package/src/runtime/domain/sandbox-policy/shared-permission-blocker.domain.mjs +40 -0
- package/src/runtime/domain/sandbox-policy/shared-permission-blocker.ts +48 -0
- package/src/runtime/domain/sandbox-policy/shared-sandbox-core.domain.mjs +1531 -0
- package/src/runtime/domain/sandbox-policy/shared-sandbox-core.ts +1757 -0
- package/src/runtime/domain/sandbox-policy/shared-sandbox-diagnostics.domain.mjs +591 -0
- package/src/runtime/domain/sandbox-policy/shared-sandbox-diagnostics.ts +491 -0
- package/src/runtime/domain/sandbox-policy/shared-task-application.domain.mjs +185 -0
- package/src/runtime/domain/sandbox-policy/shared-task-application.ts +185 -0
- package/src/runtime/domain/sandbox-policy/shared-task-apply-patch.domain.mjs +416 -0
- package/src/runtime/domain/sandbox-policy/shared-task-apply-patch.ts +409 -0
- package/src/runtime/domain/sandbox-policy/shared-task-exec.domain.mjs +325 -0
- package/src/runtime/domain/sandbox-policy/shared-task-exec.ts +335 -0
- package/src/runtime/domain/sandbox-policy/shared-task-files.domain.mjs +346 -0
- package/src/runtime/domain/sandbox-policy/shared-task-files.ts +342 -0
- package/src/runtime/domain/sandbox-policy/shared-task-process-identity.domain.mjs +140 -0
- package/src/runtime/domain/sandbox-policy/shared-task-process-identity.ts +126 -0
- package/src/runtime/domain/sandbox-policy/shared-task-process-list.domain.mjs +220 -0
- package/src/runtime/domain/sandbox-policy/shared-task-process-list.ts +209 -0
- package/src/runtime/domain/sandbox-policy/shared-task-sandbox.domain.mjs +227 -0
- package/src/runtime/domain/sandbox-policy/shared-task-sandbox.ts +224 -0
- package/src/runtime/domain/sandbox-policy/shared-task-tools.domain.mjs +92 -0
- package/src/runtime/domain/sandbox-policy/shared-task-tools.ts +123 -0
- package/src/runtime/domain/sandbox-policy/shell.domain.mjs +93 -0
- package/src/runtime/domain/sandbox-policy/shell.ts +129 -0
- package/src/runtime/domain/sandbox-policy/state.domain.mjs +307 -0
- package/src/runtime/domain/sandbox-policy/state.ts +408 -0
- package/src/runtime/domain/sandbox-policy/status.domain.mjs +64 -0
- package/src/runtime/domain/sandbox-policy/status.ts +76 -0
- package/src/runtime/domain/sandbox-policy/subagent-admission.domain.mjs +69 -0
- package/src/runtime/domain/sandbox-policy/subagent-admission.ts +60 -0
- package/src/runtime/domain/subagents/CONTEXT.md +202 -0
- package/src/runtime/domain/subagents/PRODUCT.md +49 -0
- package/src/runtime/domain/subagents/README.md +201 -0
- package/src/runtime/domain/subagents/agent-catalog.mjs +64 -0
- package/src/runtime/domain/subagents/agent-commands.domain.mjs +822 -0
- package/src/runtime/domain/subagents/agent-commands.ts +905 -0
- package/src/runtime/domain/subagents/agent-inspection.domain.mjs +398 -0
- package/src/runtime/domain/subagents/agent-inspection.ts +574 -0
- package/src/runtime/domain/subagents/agent-operations.domain.mjs +40 -0
- package/src/runtime/domain/subagents/agent-operations.ts +61 -0
- package/src/runtime/domain/subagents/agent-session-settings.domain.mjs +112 -0
- package/src/runtime/domain/subagents/agent-session-settings.ts +118 -0
- package/src/runtime/domain/subagents/agents-catalog-tool.domain.mjs +84 -0
- package/src/runtime/domain/subagents/agents-catalog-tool.ts +118 -0
- package/src/runtime/domain/subagents/assignment-outcomes.domain.mjs +276 -0
- package/src/runtime/domain/subagents/assignment-outcomes.ts +212 -0
- package/src/runtime/domain/subagents/assignment-projection.mjs +261 -0
- package/src/runtime/domain/subagents/assignment-report.domain.mjs +174 -0
- package/src/runtime/domain/subagents/assignment-report.ts +156 -0
- package/src/runtime/domain/subagents/batch.mjs +275 -0
- package/src/runtime/domain/subagents/callback-fields.domain.mjs +72 -0
- package/src/runtime/domain/subagents/callback-fields.ts +95 -0
- package/src/runtime/domain/subagents/capacity.mjs +108 -0
- package/src/runtime/domain/subagents/catalog-editor.domain.mjs +98 -0
- package/src/runtime/domain/subagents/catalog-editor.ts +125 -0
- package/src/runtime/domain/subagents/catalog-host-admission.domain.mjs +104 -0
- package/src/runtime/domain/subagents/catalog-host-admission.ts +85 -0
- package/src/runtime/domain/subagents/catalog-identity.domain.mjs +222 -0
- package/src/runtime/domain/subagents/catalog-identity.ts +258 -0
- package/src/runtime/domain/subagents/catalog-overlay.domain.mjs +9 -0
- package/src/runtime/domain/subagents/catalog-overlay.ts +10 -0
- package/src/runtime/domain/subagents/catalog-preferences.domain.mjs +164 -0
- package/src/runtime/domain/subagents/catalog-preferences.ts +139 -0
- package/src/runtime/domain/subagents/catalog-resolver.domain.mjs +366 -0
- package/src/runtime/domain/subagents/catalog-resolver.ts +540 -0
- package/src/runtime/domain/subagents/catalog-runtime.domain.mjs +570 -0
- package/src/runtime/domain/subagents/catalog-runtime.ts +680 -0
- package/src/runtime/domain/subagents/catalog-schema.domain.mjs +1331 -0
- package/src/runtime/domain/subagents/catalog-schema.ts +1563 -0
- package/src/runtime/domain/subagents/catalog-skill-edits.domain.mjs +95 -0
- package/src/runtime/domain/subagents/catalog-skill-edits.ts +116 -0
- package/src/runtime/domain/subagents/catalog-store.domain.mjs +808 -0
- package/src/runtime/domain/subagents/catalog-store.ts +1006 -0
- package/src/runtime/domain/subagents/catalog-ui.domain.mjs +651 -0
- package/src/runtime/domain/subagents/catalog-ui.ts +611 -0
- package/src/runtime/domain/subagents/child-apply-patch.domain.mjs +13 -0
- package/src/runtime/domain/subagents/child-apply-patch.ts +13 -0
- package/src/runtime/domain/subagents/child-codemode.domain.mjs +16 -0
- package/src/runtime/domain/subagents/child-codemode.ts +17 -0
- package/src/runtime/domain/subagents/child-dependencies.mjs +193 -0
- package/src/runtime/domain/subagents/child-incidents.domain.mjs +170 -0
- package/src/runtime/domain/subagents/child-incidents.ts +169 -0
- package/src/runtime/domain/subagents/child-operations.domain.mjs +986 -0
- package/src/runtime/domain/subagents/child-operations.ts +1191 -0
- package/src/runtime/domain/subagents/child-ownership.domain.mjs +205 -0
- package/src/runtime/domain/subagents/child-ownership.ts +160 -0
- package/src/runtime/domain/subagents/child-preflight.mjs +38 -0
- package/src/runtime/domain/subagents/child-process-list.domain.mjs +7 -0
- package/src/runtime/domain/subagents/child-process-list.ts +8 -0
- package/src/runtime/domain/subagents/child-runtime.mjs +67 -0
- package/src/runtime/domain/subagents/child-steer.domain.mjs +109 -0
- package/src/runtime/domain/subagents/child-steer.ts +102 -0
- package/src/runtime/domain/subagents/cleanup.domain.mjs +818 -0
- package/src/runtime/domain/subagents/cleanup.ts +1017 -0
- package/src/runtime/domain/subagents/codex-import.domain.mjs +575 -0
- package/src/runtime/domain/subagents/codex-import.ts +717 -0
- package/src/runtime/domain/subagents/completion.domain.mjs +6 -0
- package/src/runtime/domain/subagents/completion.mjs +152 -0
- package/src/runtime/domain/subagents/completion.ts +11 -0
- package/src/runtime/domain/subagents/config.domain.mjs +248 -0
- package/src/runtime/domain/subagents/config.json +15 -0
- package/src/runtime/domain/subagents/config.ts +328 -0
- package/src/runtime/domain/subagents/continuation-authority.domain.mjs +38 -0
- package/src/runtime/domain/subagents/continuation-authority.ts +31 -0
- package/src/runtime/domain/subagents/continuation-runtime.domain.mjs +89 -0
- package/src/runtime/domain/subagents/continuation-runtime.ts +88 -0
- package/src/runtime/domain/subagents/continuation.domain.mjs +942 -0
- package/src/runtime/domain/subagents/continuation.ts +1051 -0
- package/src/runtime/domain/subagents/delegation.domain.mjs +19 -0
- package/src/runtime/domain/subagents/delegation.ts +24 -0
- package/src/runtime/domain/subagents/effective-settings.domain.mjs +130 -0
- package/src/runtime/domain/subagents/effective-settings.ts +184 -0
- package/src/runtime/domain/subagents/extensions.domain.mjs +6 -0
- package/src/runtime/domain/subagents/extensions.mjs +164 -0
- package/src/runtime/domain/subagents/extensions.ts +19 -0
- package/src/runtime/domain/subagents/failures.domain.mjs +362 -0
- package/src/runtime/domain/subagents/failures.ts +319 -0
- package/src/runtime/domain/subagents/finalization.domain.mjs +168 -0
- package/src/runtime/domain/subagents/finalization.ts +218 -0
- package/src/runtime/domain/subagents/git-remotes.domain.mjs +351 -0
- package/src/runtime/domain/subagents/git-remotes.ts +413 -0
- package/src/runtime/domain/subagents/git-workspace.domain.mjs +337 -0
- package/src/runtime/domain/subagents/git-workspace.ts +430 -0
- package/src/runtime/domain/subagents/goal-provider.domain.mjs +125 -0
- package/src/runtime/domain/subagents/goal-provider.ts +132 -0
- package/src/runtime/domain/subagents/health-observation.domain.mjs +617 -0
- package/src/runtime/domain/subagents/health-observation.ts +818 -0
- package/src/runtime/domain/subagents/health-surface.mjs +284 -0
- package/src/runtime/domain/subagents/health.domain.mjs +261 -0
- package/src/runtime/domain/subagents/health.ts +343 -0
- package/src/runtime/domain/subagents/historical-attention.domain.mjs +37 -0
- package/src/runtime/domain/subagents/historical-attention.ts +35 -0
- package/src/runtime/domain/subagents/incident-model.domain.mjs +322 -0
- package/src/runtime/domain/subagents/incident-model.ts +358 -0
- package/src/runtime/domain/subagents/index.domain.mjs +4731 -0
- package/src/runtime/domain/subagents/index.ts +4781 -0
- package/src/runtime/domain/subagents/launch-abort.domain.mjs +13 -0
- package/src/runtime/domain/subagents/launch-abort.ts +21 -0
- package/src/runtime/domain/subagents/launch-context.domain.mjs +24 -0
- package/src/runtime/domain/subagents/launch-context.ts +23 -0
- package/src/runtime/domain/subagents/launch-digest.mjs +6 -0
- package/src/runtime/domain/subagents/lifecycle.domain.mjs +265 -0
- package/src/runtime/domain/subagents/lifecycle.ts +360 -0
- package/src/runtime/domain/subagents/list.domain.mjs +2 -0
- package/src/runtime/domain/subagents/list.mjs +152 -0
- package/src/runtime/domain/subagents/list.ts +19 -0
- package/src/runtime/domain/subagents/log-cursor.domain.mjs +217 -0
- package/src/runtime/domain/subagents/log-cursor.ts +268 -0
- package/src/runtime/domain/subagents/managed-background-capability.domain.mjs +10 -0
- package/src/runtime/domain/subagents/managed-background-capability.ts +9 -0
- package/src/runtime/domain/subagents/managed-failure-worker.mjs +36 -0
- package/src/runtime/domain/subagents/managed-launch-bootstrap.mjs +48 -0
- package/src/runtime/domain/subagents/managed-launch-client.domain.mjs +75 -0
- package/src/runtime/domain/subagents/managed-launch-client.ts +59 -0
- package/src/runtime/domain/subagents/managed-launch-host.domain.mjs +627 -0
- package/src/runtime/domain/subagents/managed-launch-host.ts +504 -0
- package/src/runtime/domain/subagents/managed-launch-journal.mjs +17 -0
- package/src/runtime/domain/subagents/managed-launch-ownership.domain.mjs +29 -0
- package/src/runtime/domain/subagents/managed-launch-ownership.ts +22 -0
- package/src/runtime/domain/subagents/managed-launch-port.domain.mjs +2 -0
- package/src/runtime/domain/subagents/managed-launch-port.ts +25 -0
- package/src/runtime/domain/subagents/managed-launch-recovery.domain.mjs +29 -0
- package/src/runtime/domain/subagents/managed-launch-recovery.ts +45 -0
- package/src/runtime/domain/subagents/managed-worker-bridge.domain.mjs +63 -0
- package/src/runtime/domain/subagents/managed-worker-bridge.ts +48 -0
- package/src/runtime/domain/subagents/managed-worker.mjs +13 -0
- package/src/runtime/domain/subagents/model-resolution-core.domain.mjs +822 -0
- package/src/runtime/domain/subagents/model-resolution-core.ts +1074 -0
- package/src/runtime/domain/subagents/model-resolution.domain.mjs +22 -0
- package/src/runtime/domain/subagents/model-resolution.ts +32 -0
- package/src/runtime/domain/subagents/navigator.domain.mjs +6 -0
- package/src/runtime/domain/subagents/navigator.mjs +1233 -0
- package/src/runtime/domain/subagents/navigator.ts +39 -0
- package/src/runtime/domain/subagents/operation-bridge-types.domain.mjs +1012 -0
- package/src/runtime/domain/subagents/operation-bridge-types.ts +1156 -0
- package/src/runtime/domain/subagents/outage-observations.domain.mjs +84 -0
- package/src/runtime/domain/subagents/outage-observations.ts +73 -0
- package/src/runtime/domain/subagents/output-payload.domain.mjs +767 -0
- package/src/runtime/domain/subagents/output-payload.ts +987 -0
- package/src/runtime/domain/subagents/owned-exit.domain.mjs +12 -0
- package/src/runtime/domain/subagents/owned-exit.ts +12 -0
- package/src/runtime/domain/subagents/package.json +86 -0
- package/src/runtime/domain/subagents/park-checkpoint.domain.mjs +55 -0
- package/src/runtime/domain/subagents/park-checkpoint.ts +61 -0
- package/src/runtime/domain/subagents/parse.domain.mjs +1218 -0
- package/src/runtime/domain/subagents/parse.ts +1451 -0
- package/src/runtime/domain/subagents/permission-policy.domain.mjs +232 -0
- package/src/runtime/domain/subagents/permission-policy.ts +291 -0
- package/src/runtime/domain/subagents/process-identity.mjs +33 -0
- package/src/runtime/domain/subagents/registry.domain.mjs +1584 -0
- package/src/runtime/domain/subagents/registry.ts +1904 -0
- package/src/runtime/domain/subagents/role-assignment.domain.mjs +104 -0
- package/src/runtime/domain/subagents/role-assignment.ts +141 -0
- package/src/runtime/domain/subagents/roles/role.architect.md +13 -0
- package/src/runtime/domain/subagents/roles/role.developer.md +16 -0
- package/src/runtime/domain/subagents/roles/role.explorer.md +13 -0
- package/src/runtime/domain/subagents/roles/role.product-manager.md +13 -0
- package/src/runtime/domain/subagents/roles/role.researcher.md +13 -0
- package/src/runtime/domain/subagents/roles/role.reviewer.md +13 -0
- package/src/runtime/domain/subagents/roles/role.writer.md +12 -0
- package/src/runtime/domain/subagents/sandbox.domain.mjs +64 -0
- package/src/runtime/domain/subagents/sandbox.ts +92 -0
- package/src/runtime/domain/subagents/session-selection.domain.mjs +32 -0
- package/src/runtime/domain/subagents/session-selection.ts +35 -0
- package/src/runtime/domain/subagents/session-store.domain.mjs +489 -0
- package/src/runtime/domain/subagents/session-store.ts +468 -0
- package/src/runtime/domain/subagents/settings-page.domain.mjs +313 -0
- package/src/runtime/domain/subagents/settings-page.ts +363 -0
- package/src/runtime/domain/subagents/shared-callback-batcher.domain.mjs +777 -0
- package/src/runtime/domain/subagents/shared-callback-batcher.ts +956 -0
- package/src/runtime/domain/subagents/shared-catalog.domain.mjs +70 -0
- package/src/runtime/domain/subagents/shared-catalog.ts +61 -0
- package/src/runtime/domain/subagents/shared-execution-policy.domain.mjs +50 -0
- package/src/runtime/domain/subagents/shared-execution-policy.ts +61 -0
- package/src/runtime/domain/subagents/shared-failure-observations.domain.mjs +1078 -0
- package/src/runtime/domain/subagents/shared-failure-observations.ts +1166 -0
- package/src/runtime/domain/subagents/shared-harness-settings.domain.mjs +126 -0
- package/src/runtime/domain/subagents/shared-harness-settings.ts +116 -0
- package/src/runtime/domain/subagents/shared-log-utils.domain.mjs +1223 -0
- package/src/runtime/domain/subagents/shared-log-utils.ts +1492 -0
- package/src/runtime/domain/subagents/shared-navigator-panels.domain.mjs +289 -0
- package/src/runtime/domain/subagents/shared-navigator-panels.ts +272 -0
- package/src/runtime/domain/subagents/shared-navigator.domain.mjs +1930 -0
- package/src/runtime/domain/subagents/shared-navigator.ts +1962 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-inbox.mjs +144 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-observation.mjs +189 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/index.domain.mjs +51 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/index.ts +122 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-changes.domain.mjs +75 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-changes.ts +73 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.domain.mjs +163 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.ts +174 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-parent-callbacks.domain.mjs +66 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-parent-callbacks.ts +68 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.domain.mjs +87 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.ts +90 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.domain.mjs +97 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.ts +139 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/errors.domain.mjs +12 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/errors.ts +79 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.domain.mjs +342 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.ts +513 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.domain.mjs +283 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.ts +458 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/recovery.domain.mjs +52 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/recovery.ts +55 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.domain.mjs +114 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.ts +140 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.domain.mjs +280 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.ts +442 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.domain.mjs +420 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.ts +441 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/sqlite.domain.mjs +194 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/sqlite.ts +239 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.domain.mjs +275 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.ts +585 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.domain.mjs +120 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.ts +142 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/task-cancellation.domain.mjs +188 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/task-cancellation.ts +224 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.domain.mjs +25 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.ts +707 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/upgrade.domain.mjs +22 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/upgrade.ts +22 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/validate.domain.mjs +234 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/validate.ts +241 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/waits.domain.mjs +851 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/waits.ts +1424 -0
- package/src/runtime/domain/subagents/shared-permission-blocker.domain.mjs +40 -0
- package/src/runtime/domain/subagents/shared-permission-blocker.ts +48 -0
- package/src/runtime/domain/subagents/shared-render-scheduler.domain.mjs +41 -0
- package/src/runtime/domain/subagents/shared-render-scheduler.ts +47 -0
- package/src/runtime/domain/subagents/shared-sandbox-core.domain.mjs +1531 -0
- package/src/runtime/domain/subagents/shared-sandbox-core.ts +1757 -0
- package/src/runtime/domain/subagents/shared-sandbox-diagnostics.domain.mjs +591 -0
- package/src/runtime/domain/subagents/shared-sandbox-diagnostics.ts +491 -0
- package/src/runtime/domain/subagents/shared-stall-detector.domain.mjs +37 -0
- package/src/runtime/domain/subagents/shared-stall-detector.ts +69 -0
- package/src/runtime/domain/subagents/shared-task-application.domain.mjs +185 -0
- package/src/runtime/domain/subagents/shared-task-application.ts +185 -0
- package/src/runtime/domain/subagents/shared-task-apply-patch.domain.mjs +416 -0
- package/src/runtime/domain/subagents/shared-task-apply-patch.ts +409 -0
- package/src/runtime/domain/subagents/shared-task-exec.domain.mjs +325 -0
- package/src/runtime/domain/subagents/shared-task-exec.ts +335 -0
- package/src/runtime/domain/subagents/shared-task-files.domain.mjs +346 -0
- package/src/runtime/domain/subagents/shared-task-files.ts +342 -0
- package/src/runtime/domain/subagents/shared-task-process-identity.domain.mjs +140 -0
- package/src/runtime/domain/subagents/shared-task-process-identity.ts +126 -0
- package/src/runtime/domain/subagents/shared-task-process-list.domain.mjs +220 -0
- package/src/runtime/domain/subagents/shared-task-process-list.ts +209 -0
- package/src/runtime/domain/subagents/shared-task-sandbox.domain.mjs +227 -0
- package/src/runtime/domain/subagents/shared-task-sandbox.ts +224 -0
- package/src/runtime/domain/subagents/shared-task-tools.domain.mjs +92 -0
- package/src/runtime/domain/subagents/shared-task-tools.ts +123 -0
- package/src/runtime/domain/subagents/shared-work-client.mjs +303 -0
- package/src/runtime/domain/subagents/shared-worktree-context.domain.mjs +142 -0
- package/src/runtime/domain/subagents/shared-worktree-context.ts +158 -0
- package/src/runtime/domain/subagents/skill-picker.domain.mjs +316 -0
- package/src/runtime/domain/subagents/skill-picker.ts +353 -0
- package/src/runtime/domain/subagents/skills.domain.mjs +138 -0
- package/src/runtime/domain/subagents/skills.ts +183 -0
- package/src/runtime/domain/subagents/spawn.domain.mjs +72 -0
- package/src/runtime/domain/subagents/spawn.ts +80 -0
- package/src/runtime/domain/subagents/stop.domain.mjs +184 -0
- package/src/runtime/domain/subagents/stop.ts +217 -0
- package/src/runtime/domain/subagents/subagent-tools.domain.mjs +101 -0
- package/src/runtime/domain/subagents/subagent-tools.ts +137 -0
- package/src/runtime/domain/subagents/task-guard.domain.mjs +163 -0
- package/src/runtime/domain/subagents/task-guard.ts +144 -0
- package/src/runtime/domain/subagents/task-policy.domain.mjs +201 -0
- package/src/runtime/domain/subagents/task-policy.ts +236 -0
- package/src/runtime/domain/subagents/task-runtime.mjs +53 -0
- package/src/runtime/domain/subagents/task-tool-owner.domain.mjs +18 -0
- package/src/runtime/domain/subagents/task-tool-owner.ts +21 -0
- package/src/runtime/domain/subagents/thinking.domain.mjs +22 -0
- package/src/runtime/domain/subagents/thinking.ts +28 -0
- package/src/runtime/domain/subagents/tier-policy.domain.mjs +75 -0
- package/src/runtime/domain/subagents/tier-policy.ts +126 -0
- package/src/runtime/domain/subagents/timing-notifications.domain.mjs +51 -0
- package/src/runtime/domain/subagents/timing-notifications.ts +37 -0
- package/src/runtime/domain/subagents/timing.domain.mjs +487 -0
- package/src/runtime/domain/subagents/timing.ts +634 -0
- package/src/runtime/domain/subagents/tools.domain.mjs +558 -0
- package/src/runtime/domain/subagents/tools.ts +629 -0
- package/src/runtime/domain/subagents/widget.domain.mjs +6 -0
- package/src/runtime/domain/subagents/widget.mjs +246 -0
- package/src/runtime/domain/subagents/widget.ts +30 -0
- package/src/runtime/domain/subagents/work-observation.domain.mjs +316 -0
- package/src/runtime/domain/subagents/work-observation.ts +248 -0
- package/src/runtime/domain/subagents/worker-catalog.domain.mjs +120 -0
- package/src/runtime/domain/subagents/worker-catalog.ts +162 -0
- package/src/runtime/domain/subagents/worker-operations-host.domain.mjs +1009 -0
- package/src/runtime/domain/subagents/worker-operations-host.ts +1238 -0
- package/src/runtime/domain/subagents/worker-waits.domain.mjs +2336 -0
- package/src/runtime/domain/subagents/worker-waits.ts +2878 -0
- package/src/runtime/domain/subagents/workspace-scope.domain.mjs +52 -0
- package/src/runtime/domain/subagents/workspace-scope.ts +50 -0
- package/src/runtime/health-config.ts +27 -11
- package/src/runtime/log-checkpoints.ts +117 -0
- package/src/runtime/mutation-store.ts +5 -4
- package/src/runtime/queries.ts +27 -3
- package/src/runtime/query-executor.ts +178 -34
- package/src/runtime/query-worker.mjs +119 -22
- package/src/runtime/read-model.ts +939 -113
- package/src/runtime/read-watchdog-probe.ts +4 -0
- package/src/runtime/result-supervision.ts +188 -16
- package/src/runtime/source-watch.ts +175 -0
- package/src/runtime/subagent-launch.ts +73 -0
- package/src/runtime/work-budget.ts +130 -0
- package/src/runtime/work-client.d.mts +8 -0
- package/src/runtime/work-client.mjs +150 -7
- package/src/server.ts +185 -22
- package/src/session-activity.ts +26 -4
- package/src/version.ts +1 -1
|
@@ -0,0 +1,905 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `/agents` list, show/inspect, create, reload, and import-codex.
|
|
3
|
+
*
|
|
4
|
+
* Lifecycle registers `registerAgentCommands`. This module does not edit the
|
|
5
|
+
* extension entry and does not launch children. Import and ambiguous choices
|
|
6
|
+
* write nothing unless the required confirmation is actually collected.
|
|
7
|
+
* Personal scope is the default. Project scope is explicit and trusted-only.
|
|
8
|
+
*/
|
|
9
|
+
import { existsSync, lstatSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
10
|
+
import { isAbsolute, resolve } from "node:path";
|
|
11
|
+
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
12
|
+
import { presentCatalog, presentCatalogEntry, type LaunchEnricher, type OperationView, type ReadSkillDefaults } from "./agent-inspection.ts";
|
|
13
|
+
import { createCatalogComponent } from "./catalog-ui.ts";
|
|
14
|
+
import type { ScopedModelLike } from "./catalog-editor.ts";
|
|
15
|
+
import {
|
|
16
|
+
CATALOG_SCHEMA_VERSION,
|
|
17
|
+
DiagnosticCodes,
|
|
18
|
+
EFFORT_LEVELS,
|
|
19
|
+
canonicalRoleId,
|
|
20
|
+
parseDefinition,
|
|
21
|
+
serializeDefinition,
|
|
22
|
+
shortRoleName,
|
|
23
|
+
type AgentDefinition,
|
|
24
|
+
type Diagnostic,
|
|
25
|
+
type InstructionMode,
|
|
26
|
+
type PortablePreferences,
|
|
27
|
+
type ThinkingLevel,
|
|
28
|
+
} from "./catalog-schema.ts";
|
|
29
|
+
import {
|
|
30
|
+
createDefinition,
|
|
31
|
+
catalogSnapshotFromWire,
|
|
32
|
+
defaultUserRoot,
|
|
33
|
+
loadCatalog,
|
|
34
|
+
projectCatalogPaths,
|
|
35
|
+
refreshCatalog,
|
|
36
|
+
resetRuntimeToBundled,
|
|
37
|
+
resetUserDefinition,
|
|
38
|
+
saveDefinition,
|
|
39
|
+
userCatalogPaths,
|
|
40
|
+
type CatalogSnapshot,
|
|
41
|
+
} from "./catalog-store.ts";
|
|
42
|
+
import { listCatalog } from "./catalog-resolver.ts";
|
|
43
|
+
import {
|
|
44
|
+
CODEX_FORMAT,
|
|
45
|
+
PI_VS_CODEX_PRECEDENCE,
|
|
46
|
+
agentIdFromDisplayName,
|
|
47
|
+
buildImportedAgent,
|
|
48
|
+
codexSourceRef,
|
|
49
|
+
parseCodexSource,
|
|
50
|
+
renderReimportPreview,
|
|
51
|
+
suggestBaseRoles,
|
|
52
|
+
type CodexDocument,
|
|
53
|
+
} from "./codex-import.ts";
|
|
54
|
+
import { resolveRoleAssignment } from "./role-assignment.ts";
|
|
55
|
+
import { saveAgentSessionDefaults, withAgentSessionSettings, type AgentSessionOverrides, type AgentSessionSettings } from "./agent-session-settings.ts";
|
|
56
|
+
import { saveSkillExposure } from "./catalog-skill-edits.ts";
|
|
57
|
+
import type { DiscoveredSkill } from "./skill-picker.ts";
|
|
58
|
+
import { openSharedCatalog } from "./shared-catalog.ts";
|
|
59
|
+
|
|
60
|
+
const MODEL_PATTERN = /^[a-z0-9][a-z0-9._-]*\/[A-Za-z0-9][A-Za-z0-9._+-]*$/;
|
|
61
|
+
const TIER_PATTERN = /^[a-z][a-z0-9-]{0,32}$/;
|
|
62
|
+
const KNOWN_FLAGS = new Set(["role", "scope", "name", "id", "mode", "description", "instructions", "model", "effort", "tier", "help"]);
|
|
63
|
+
const USAGE = [
|
|
64
|
+
"/agents list",
|
|
65
|
+
"/agents show <id> (inspect is the same command)",
|
|
66
|
+
"/agents create [--role <role>] [--name <name>] [--scope user|project] [--mode add|replace] [--instructions <text>] [--model <provider/model>] [--effort <level>] [--tier <label>]",
|
|
67
|
+
"/agents reload",
|
|
68
|
+
"/agents import-codex <file.toml> [--scope user|project] [--role <role>]",
|
|
69
|
+
"Create and import write to the personal catalog unless --scope project is set.",
|
|
70
|
+
"Import confirms one base role and replace mode. It does not scan .codex/agents.",
|
|
71
|
+
].join("\n");
|
|
72
|
+
|
|
73
|
+
export interface AgentCommandDeps {
|
|
74
|
+
sharedCatalog?: boolean;
|
|
75
|
+
/** Invocation-local server state; never reused across workspaces or branches. */
|
|
76
|
+
sharedState?: { snapshot: CatalogSnapshot; edit: (edit: Record<string, unknown>) => Promise<any>; scopedAgents: (scope: "user" | "project") => Promise<ReturnType<typeof listScopeAgents>>; beginEdit?: (id: string) => void; onChange?: (changed: () => void) => void; revoked?: boolean };
|
|
77
|
+
userRoot?: string;
|
|
78
|
+
bundledRoot?: string;
|
|
79
|
+
projectConfigDirName?: string;
|
|
80
|
+
now?: () => string;
|
|
81
|
+
/** Resolution unit injects availability, actual model/effort, and launchability. */
|
|
82
|
+
enrich?: LaunchEnricher;
|
|
83
|
+
/** Live session/config default skill choice; absent keeps the legacy config read. */
|
|
84
|
+
readSkillDefaults?: ReadSkillDefaults;
|
|
85
|
+
/** Read loaded Pi skill metadata for the checkbox picker. */
|
|
86
|
+
discoverSkills?: (ctx: ExtensionCommandContext) => readonly DiscoveredSkill[];
|
|
87
|
+
/** Snapshot captured for this invocation. */
|
|
88
|
+
discoveredSkills?: readonly DiscoveredSkill[];
|
|
89
|
+
sessionSettings?: AgentSessionSettings;
|
|
90
|
+
/** Available foreground registry models, as provider/id. */
|
|
91
|
+
editableModels?: () => readonly string[];
|
|
92
|
+
/**
|
|
93
|
+
* Live slash-command context, before list/inspect/create/reload/import.
|
|
94
|
+
* Lifecycle refreshes the foreground model and settings here. Direct
|
|
95
|
+
* `executeAgentsCommand` callers do not have that context.
|
|
96
|
+
*/
|
|
97
|
+
propagateCommandContext?: (ctx: ExtensionCommandContext) => void;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface AgentCommandUi {
|
|
101
|
+
select(title: string, options: string[]): Promise<string | undefined>;
|
|
102
|
+
confirm(title: string, message: string): Promise<boolean>;
|
|
103
|
+
input(title: string, placeholder?: string): Promise<string | undefined>;
|
|
104
|
+
editor(title: string, prefill?: string): Promise<string | undefined>;
|
|
105
|
+
notify(message: string, type?: "info" | "warning" | "error"): void;
|
|
106
|
+
setWidget?(key: string, content: string[] | undefined): void;
|
|
107
|
+
custom?<T>(factory: (tui: { requestRender(): void }, theme: { fg(color: string, text: string): string }, keybindings: unknown, done: (value: T) => void) => unknown, options?: { overlay: boolean; overlayOptions?: import("@earendil-works/pi-tui").OverlayOptions }): Promise<T>;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface AgentCommandHost {
|
|
111
|
+
cwd: string;
|
|
112
|
+
hasUI: boolean;
|
|
113
|
+
mode?: "tui" | "rpc" | "json" | "print";
|
|
114
|
+
isProjectTrusted(): boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Session model scope from `ctx.scopedModels`. Empty or absent means no
|
|
117
|
+
* scope, which Pi treats as "all available models are usable".
|
|
118
|
+
*/
|
|
119
|
+
scopedModels?: readonly ScopedModelLike[];
|
|
120
|
+
ui: AgentCommandUi;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface AgentCommandResult {
|
|
124
|
+
ok: boolean;
|
|
125
|
+
status: "ok" | "clarification-needed" | "error";
|
|
126
|
+
command: string;
|
|
127
|
+
wrote: boolean;
|
|
128
|
+
path?: string;
|
|
129
|
+
scope?: "user" | "project";
|
|
130
|
+
message: string;
|
|
131
|
+
diagnostics: Diagnostic[];
|
|
132
|
+
data?: unknown;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
interface CatalogLocation {
|
|
136
|
+
snapshot?: CatalogSnapshot;
|
|
137
|
+
cwd: string;
|
|
138
|
+
userRoot: string;
|
|
139
|
+
projectTrusted: boolean;
|
|
140
|
+
projectConfigDirName?: string;
|
|
141
|
+
bundledRoot?: string;
|
|
142
|
+
sessionSettings?: AgentSessionOverrides;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
interface ParsedArgs {
|
|
146
|
+
positionals: string[];
|
|
147
|
+
flags: Map<string, string[]>;
|
|
148
|
+
unknown: string[];
|
|
149
|
+
missing: string[];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function registerAgentCommands(pi: Pick<ExtensionAPI, "registerCommand">, deps: AgentCommandDeps = {}): void {
|
|
153
|
+
pi.registerCommand("agents", {
|
|
154
|
+
description: "[list|show|create|reload|import-codex] — List, inspect, create, reload, or import agent definitions",
|
|
155
|
+
getArgumentCompletions(prefix: string) {
|
|
156
|
+
const commands = ["list", "inspect", "show", "create", "reload", "import-codex", "help"];
|
|
157
|
+
const first = prefix.trim().split(/\s+/)[0] ?? "";
|
|
158
|
+
if (first !== prefix.trim() && first.length > 0) return null;
|
|
159
|
+
const items = commands.filter((command) => command.startsWith(first)).map((value) => ({ value, label: value }));
|
|
160
|
+
return items.length > 0 ? items : null;
|
|
161
|
+
},
|
|
162
|
+
async handler(args: string, ctx: ExtensionCommandContext) {
|
|
163
|
+
return executeAgentsCommandContext(args, ctx, deps);
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Slash commands and settings shortcuts must resolve against the same live context. */
|
|
169
|
+
export function executeAgentsCommandContext(args: string, ctx: ExtensionCommandContext, deps: AgentCommandDeps = {}): Promise<AgentCommandResult> {
|
|
170
|
+
deps.propagateCommandContext?.(ctx);
|
|
171
|
+
const discoveredSkills = deps.discoverSkills?.(ctx) ?? deps.discoveredSkills;
|
|
172
|
+
return executeAgentsCommand(args, {
|
|
173
|
+
cwd: ctx.cwd,
|
|
174
|
+
hasUI: ctx.hasUI,
|
|
175
|
+
mode: ctx.mode,
|
|
176
|
+
isProjectTrusted: () => ctx.isProjectTrusted(),
|
|
177
|
+
scopedModels: scopedModelsFromContext(ctx),
|
|
178
|
+
ui: ctx.ui,
|
|
179
|
+
}, discoveredSkills ? { ...deps, discoveredSkills } : deps);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Older Pi versions do not expose `ctx.scopedModels`, so they retain the
|
|
184
|
+
* unscoped picker. Current hosts use an empty array when no scope is configured.
|
|
185
|
+
*/
|
|
186
|
+
function scopedModelsFromContext(ctx: ExtensionCommandContext): readonly ScopedModelLike[] {
|
|
187
|
+
const scoped = (ctx as unknown as { scopedModels?: unknown }).scopedModels;
|
|
188
|
+
return Array.isArray(scoped) ? scoped as readonly ScopedModelLike[] : [];
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export async function executeAgentsCommand(args: string, host: AgentCommandHost, deps: AgentCommandDeps = {}): Promise<AgentCommandResult> {
|
|
192
|
+
const parsed = parseCommandArgs(args);
|
|
193
|
+
if (parsed.positionals.length === 0 && parsed.flags.size === 0 && host.mode === "tui" && host.hasUI && host.ui.custom) parsed.positionals.push("list");
|
|
194
|
+
if (parsed.unknown.length > 0 || parsed.missing.length > 0) {
|
|
195
|
+
const detail = [
|
|
196
|
+
...parsed.unknown.map((flag) => `Unknown flag --${flag}.`),
|
|
197
|
+
...parsed.missing.map((flag) => `--${flag} needs a value.`),
|
|
198
|
+
].join(" ");
|
|
199
|
+
return finish(host, result("error", parsed.positionals[0] ?? "agents", false, `${detail}\n${USAGE}`));
|
|
200
|
+
}
|
|
201
|
+
if (parsed.flags.has("help") || parsed.positionals[0] === "help" || parsed.positionals.length === 0) {
|
|
202
|
+
return finish(host, result("ok", "help", false, USAGE));
|
|
203
|
+
}
|
|
204
|
+
const command = parsed.positionals[0]!;
|
|
205
|
+
if ((deps.sharedCatalog ?? !deps.userRoot) && !deps.sharedState) {
|
|
206
|
+
const loc = location(host, deps);
|
|
207
|
+
const remote = await openSharedCatalog(host.cwd, loc.userRoot, "agents-command", loc.projectTrusted);
|
|
208
|
+
const writes = new Set<Promise<unknown>>();
|
|
209
|
+
const listeners = new Set<() => void>();
|
|
210
|
+
const editRevisions = new Map<string, string>();
|
|
211
|
+
try {
|
|
212
|
+
const state = { snapshot: await remote.get(), revoked: false, scopedAgents: remote.scopedAgents, beginEdit(id: string) { editRevisions.set(id, state.snapshot.revision); }, onChange(changed: () => void) { listeners.add(changed); }, edit(edit: Record<string, unknown>) {
|
|
213
|
+
if (state.revoked) return Promise.reject(new Error("catalog-host-revoked: reopen the catalog"));
|
|
214
|
+
const write = (async () => {
|
|
215
|
+
const result = await remote.edit({ expectedRevision: editRevisions.get(edit.catalogId as string) ?? state.snapshot.revision, ...edit });
|
|
216
|
+
if (result.ok) editRevisions.delete(edit.catalogId as string);
|
|
217
|
+
state.snapshot = await remote.get();
|
|
218
|
+
return result;
|
|
219
|
+
})();
|
|
220
|
+
writes.add(write);
|
|
221
|
+
void write.then(() => writes.delete(write), () => writes.delete(write));
|
|
222
|
+
return write;
|
|
223
|
+
} };
|
|
224
|
+
let subscriptionChanged = false;
|
|
225
|
+
const initialSnapshot = await remote.subscribe(snapshot => {
|
|
226
|
+
subscriptionChanged = true;
|
|
227
|
+
if (snapshot) { state.snapshot = snapshot; state.revoked = false; }
|
|
228
|
+
else {
|
|
229
|
+
state.revoked = true;
|
|
230
|
+
state.snapshot = catalogSnapshotFromWire({ schema: state.snapshot.schema, revision: "revoked", digest: "revoked", loadedAt: new Date().toISOString(),
|
|
231
|
+
roles: [], agents: [], blocked: [], diagnostics: [diagnostic("catalog-host-revoked", "Catalog access changed. Reopen the catalog.")] });
|
|
232
|
+
}
|
|
233
|
+
for (const changed of listeners) changed();
|
|
234
|
+
});
|
|
235
|
+
// A queued update or revocation can arrive before subscribe resolves.
|
|
236
|
+
if (!subscriptionChanged) state.snapshot = initialSnapshot;
|
|
237
|
+
return await executeAgentsCommand(args, host, { ...deps, sharedState: state });
|
|
238
|
+
}
|
|
239
|
+
finally { await Promise.allSettled(writes); remote.close(); }
|
|
240
|
+
}
|
|
241
|
+
const loc = location(host, deps);
|
|
242
|
+
if (command === "list") return finishInspection(host, await runList(parsed, loc, deps), deps);
|
|
243
|
+
if (command === "show" || command === "inspect") return finishInspection(host, await runShow(command, parsed, host, loc, deps), deps);
|
|
244
|
+
if (command === "reload") return finish(host, await runReload(parsed, loc, deps));
|
|
245
|
+
if (command === "create") return finish(host, await runCreate(parsed, host, loc, deps));
|
|
246
|
+
if (command === "import-codex") return finish(host, await runImport(parsed, host, loc, deps));
|
|
247
|
+
return finish(host, result("error", command, false, `Unknown /agents command ${JSON.stringify(command)}.\n${USAGE}`));
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export function parseCommandArgs(input: string): ParsedArgs {
|
|
251
|
+
const positionals: string[] = [];
|
|
252
|
+
const flags = new Map<string, string[]>();
|
|
253
|
+
const unknown: string[] = [];
|
|
254
|
+
const missing: string[] = [];
|
|
255
|
+
const tokens = tokenize(input);
|
|
256
|
+
for (let index = 0; index < tokens.length; index += 1) {
|
|
257
|
+
const token = tokens[index]!;
|
|
258
|
+
if (token === "--") {
|
|
259
|
+
positionals.push(...tokens.slice(index + 1));
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
if (!token.startsWith("--")) {
|
|
263
|
+
positionals.push(token);
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
const body = token.slice(2);
|
|
267
|
+
const eq = body.indexOf("=");
|
|
268
|
+
const name = eq === -1 ? body : body.slice(0, eq);
|
|
269
|
+
if (!KNOWN_FLAGS.has(name)) {
|
|
270
|
+
unknown.push(name);
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
const value = eq === -1 ? tokens[index + 1] : body.slice(eq + 1);
|
|
274
|
+
if (eq === -1 && (value === undefined || value.startsWith("--"))) {
|
|
275
|
+
missing.push(name);
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
if (eq === -1) index += 1;
|
|
279
|
+
flags.set(name, [...(flags.get(name) ?? []), value ?? ""]);
|
|
280
|
+
}
|
|
281
|
+
return { positionals, flags, unknown, missing };
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
async function runList(parsed: ParsedArgs, loc: CatalogLocation, deps: AgentCommandDeps): Promise<AgentCommandResult> {
|
|
285
|
+
if (parsed.positionals.length > 1) return result("error", "list", false, "list does not take extra arguments. Use /agents show <id> to inspect one definition.");
|
|
286
|
+
const listed = presentCatalog(readCatalog(loc), deps.enrich, deps.readSkillDefaults);
|
|
287
|
+
return {
|
|
288
|
+
...result("ok", "list", false, `Listed from a fresh catalog read. File edits show up on the next list or launch; /agents reload is not required for that.\n${listed.text}`),
|
|
289
|
+
diagnostics: listed.diagnostics,
|
|
290
|
+
data: listed,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
async function runReload(parsed: ParsedArgs, loc: CatalogLocation, deps: AgentCommandDeps): Promise<AgentCommandResult> {
|
|
295
|
+
if (parsed.positionals.length > 1) return result("error", "reload", false, "reload does not take extra arguments.");
|
|
296
|
+
const listed = presentCatalog(loc.snapshot ?? withAgentSessionSettings(refreshCatalog(loc), loc.sessionSettings), deps.enrich, deps.readSkillDefaults);
|
|
297
|
+
return {
|
|
298
|
+
...result("ok", "reload", false, `Reloaded revision ${listed.revision} for inspection. The next launch reads the files again on its own; this command is not a prerequisite.\n${listed.text}`),
|
|
299
|
+
diagnostics: listed.diagnostics,
|
|
300
|
+
data: listed,
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
async function runShow(
|
|
305
|
+
command: string,
|
|
306
|
+
parsed: ParsedArgs,
|
|
307
|
+
host: AgentCommandHost,
|
|
308
|
+
loc: CatalogLocation,
|
|
309
|
+
deps: AgentCommandDeps,
|
|
310
|
+
): Promise<AgentCommandResult> {
|
|
311
|
+
if (parsed.positionals.length > 2) return result("error", command, false, `${command} takes one id. Display names and filenames are not ids.`);
|
|
312
|
+
let id = parsed.positionals[1];
|
|
313
|
+
if (!id) {
|
|
314
|
+
if (!host.hasUI) {
|
|
315
|
+
return clarification(command, `${command} needs an id. UI is unavailable, so none was selected. Run /agents list and pass the id. Nothing was written.`);
|
|
316
|
+
}
|
|
317
|
+
if (host.mode === "tui" && host.ui.custom) {
|
|
318
|
+
const listed = presentCatalog(readCatalog(loc), deps.enrich, deps.readSkillDefaults);
|
|
319
|
+
return { ...result("ok", command, false, listed.text), diagnostics: listed.diagnostics, data: listed };
|
|
320
|
+
}
|
|
321
|
+
const ids = listCatalog(readCatalog(loc)).map((entry) => entry.id);
|
|
322
|
+
if (ids.length === 0) return result("error", command, false, "The catalog has no definitions to inspect.");
|
|
323
|
+
const selected = await host.ui.select("Inspect a role or agent", ids);
|
|
324
|
+
if (!selected) return clarification(command, "Inspect was dismissed. Nothing was written.");
|
|
325
|
+
id = selected;
|
|
326
|
+
}
|
|
327
|
+
const view = presentCatalogEntry(readCatalog(loc), id, deps.enrich, deps.readSkillDefaults);
|
|
328
|
+
return {
|
|
329
|
+
ok: view.found,
|
|
330
|
+
status: view.found ? "ok" : "error",
|
|
331
|
+
command,
|
|
332
|
+
wrote: false,
|
|
333
|
+
message: view.found ? view.text : `${view.text}\nNothing was written.`,
|
|
334
|
+
diagnostics: viewDiagnostics(view),
|
|
335
|
+
data: view,
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
async function runCreate(
|
|
340
|
+
parsed: ParsedArgs,
|
|
341
|
+
host: AgentCommandHost,
|
|
342
|
+
loc: CatalogLocation,
|
|
343
|
+
deps: AgentCommandDeps,
|
|
344
|
+
): Promise<AgentCommandResult> {
|
|
345
|
+
if (parsed.positionals.length > 1) {
|
|
346
|
+
return result("error", "create", false, "create takes flags, not a bare role name. Use --role <role>. Nothing was written.");
|
|
347
|
+
}
|
|
348
|
+
const scope = readScope(parsed.flags);
|
|
349
|
+
if (scope.error) return result("error", "create", false, `${scope.error} Nothing was written.`);
|
|
350
|
+
if (scope.value === "project" && !loc.projectTrusted) return untrusted("create");
|
|
351
|
+
const snapshot = readCatalog(loc);
|
|
352
|
+
const roles = catalogRoles(snapshot);
|
|
353
|
+
let roleIds = (parsed.flags.get("role") ?? []).map(canonicalRoleId);
|
|
354
|
+
if (roleIds.length > 1) {
|
|
355
|
+
const decision = await resolveRoleAssignment(roleIds.map((roleId) => ({ roleId })), {
|
|
356
|
+
hasUI: host.hasUI,
|
|
357
|
+
select: host.hasUI ? (title, options) => host.ui.select(title, options) : undefined,
|
|
358
|
+
});
|
|
359
|
+
if (decision.status !== "resolved" || decision.jobs.length !== 1) {
|
|
360
|
+
return clarification("create", `${decision.message} A named agent was not created. Split does not write two agents or an agent with multiple parents.`);
|
|
361
|
+
}
|
|
362
|
+
roleIds = [decision.jobs[0]!.roleId];
|
|
363
|
+
}
|
|
364
|
+
let roleId = roleIds[0];
|
|
365
|
+
if (!roleId) {
|
|
366
|
+
if (!host.hasUI) {
|
|
367
|
+
return clarification("create", `create needs --role <role>. UI is unavailable, so no role was chosen. Roles: ${roles.map((role) => shortRoleName(role.id)).join(", ") || "none"}. Nothing was written.`);
|
|
368
|
+
}
|
|
369
|
+
if (roles.length === 0) return result("error", "create", false, "No roles are available to use as a base. Nothing was written.");
|
|
370
|
+
const selected = await host.ui.select("Choose one base role", roles.map(roleOption));
|
|
371
|
+
if (!selected) return clarification("create", "Role choice was dismissed. Nothing was written.");
|
|
372
|
+
roleId = selected.split(" ")[0];
|
|
373
|
+
}
|
|
374
|
+
if (!roleId || !roles.some((role) => role.id === roleId)) {
|
|
375
|
+
return result("error", "create", false, `Unknown role ${shortRoleName(roleId ?? "")}. Valid roles: ${roles.map((role) => shortRoleName(role.id)).join(", ") || "none"}. Nothing was written.`);
|
|
376
|
+
}
|
|
377
|
+
let name = parsed.flags.get("name")?.[0];
|
|
378
|
+
if (!name?.trim()) {
|
|
379
|
+
if (!host.hasUI) return clarification("create", "create needs --name. UI is unavailable, so no name was chosen. Nothing was written.");
|
|
380
|
+
const entered = await host.ui.input("Agent display name", "Payments Developer");
|
|
381
|
+
if (!entered?.trim()) return clarification("create", "Name was dismissed. Nothing was written.");
|
|
382
|
+
name = entered.trim();
|
|
383
|
+
} else {
|
|
384
|
+
name = name.trim();
|
|
385
|
+
}
|
|
386
|
+
const explicitId = parsed.flags.get("id")?.[0];
|
|
387
|
+
const id = explicitId ?? agentIdFromDisplayName(name);
|
|
388
|
+
if (!id || !/^agent\.[a-z0-9]+(?:[.-][a-z0-9]+)*$/.test(id)) {
|
|
389
|
+
return result("error", "create", false, `Id ${JSON.stringify(explicitId ?? name)} is not agent.<slug>. Nothing was written.`);
|
|
390
|
+
}
|
|
391
|
+
const modeFlag = parsed.flags.get("mode")?.[0] ?? "add";
|
|
392
|
+
if (modeFlag !== "add" && modeFlag !== "replace") {
|
|
393
|
+
return result("error", "create", false, "mode must be add or replace. Nothing was written.");
|
|
394
|
+
}
|
|
395
|
+
const mode: InstructionMode = modeFlag;
|
|
396
|
+
let instructions = parsed.flags.get("instructions")?.[0];
|
|
397
|
+
if (!parsed.flags.has("instructions")) {
|
|
398
|
+
if (host.hasUI) {
|
|
399
|
+
const edited = await host.ui.editor(mode === "replace" ? "Replacement instructions" : "Instructions to add", "");
|
|
400
|
+
if (edited === undefined) return clarification("create", "Instruction editor was dismissed. Nothing was written.");
|
|
401
|
+
instructions = edited;
|
|
402
|
+
} else {
|
|
403
|
+
instructions = "";
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
if (mode === "replace" && instructions!.trim() === "") {
|
|
407
|
+
return clarification("create", "replace mode needs nonempty instruction text. Model and effort still inherit unless you set overrides. Nothing was written.");
|
|
408
|
+
}
|
|
409
|
+
const overrides: PortablePreferences = {};
|
|
410
|
+
const overrideError = readOverrides(parsed.flags, overrides);
|
|
411
|
+
if (overrideError) return result("error", "create", false, `${overrideError} Nothing was written.`);
|
|
412
|
+
const description = parsed.flags.get("description")?.[0];
|
|
413
|
+
const definition: AgentDefinition = {
|
|
414
|
+
schema: CATALOG_SCHEMA_VERSION,
|
|
415
|
+
kind: "agent",
|
|
416
|
+
id,
|
|
417
|
+
name,
|
|
418
|
+
description: description?.trim() || undefined,
|
|
419
|
+
roleId,
|
|
420
|
+
instructionMode: mode,
|
|
421
|
+
overrides,
|
|
422
|
+
executionRestrictions: [],
|
|
423
|
+
provenance: { origin: "local" },
|
|
424
|
+
body: instructions ?? "",
|
|
425
|
+
};
|
|
426
|
+
const saved = deps.sharedState ? await deps.sharedState.edit({ action: "definition", catalogId: definition.id, markdown: serializeDefinition(definition).markdown, scope: scope.value, replace: false })
|
|
427
|
+
: createDefinition({ ...loc, definition, scope: scope.value, replace: false });
|
|
428
|
+
if (deps.sharedState) loc.snapshot = withAgentSessionSettings(deps.sharedState.snapshot, loc.sessionSettings);
|
|
429
|
+
if (!saved.ok || !saved.path) {
|
|
430
|
+
return { ...result("error", "create", false, saved.diagnostics.map((item) => item.message).join("\n") || "Create did not write a file."), diagnostics: saved.diagnostics };
|
|
431
|
+
}
|
|
432
|
+
const view = presentCatalogEntry(readCatalog(loc), id, deps.enrich, deps.readSkillDefaults);
|
|
433
|
+
return {
|
|
434
|
+
ok: true,
|
|
435
|
+
status: "ok",
|
|
436
|
+
command: "create",
|
|
437
|
+
wrote: true,
|
|
438
|
+
path: saved.path,
|
|
439
|
+
scope: scope.value,
|
|
440
|
+
message: `Created ${id} in the ${scopeLabel(scope.value)} catalog at ${saved.path}. Only the role reference and explicit overrides were stored.\n${view.text}`,
|
|
441
|
+
diagnostics: [...saved.diagnostics, ...viewDiagnostics(view)],
|
|
442
|
+
data: view,
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
async function runImport(
|
|
447
|
+
parsed: ParsedArgs,
|
|
448
|
+
host: AgentCommandHost,
|
|
449
|
+
loc: CatalogLocation,
|
|
450
|
+
deps: AgentCommandDeps,
|
|
451
|
+
): Promise<AgentCommandResult> {
|
|
452
|
+
if (parsed.positionals.length > 2) {
|
|
453
|
+
return result("error", "import-codex", false, "import-codex takes one file. It does not scan a directory. Nothing was imported.");
|
|
454
|
+
}
|
|
455
|
+
const scope = readScope(parsed.flags);
|
|
456
|
+
if (scope.error) return result("error", "import-codex", false, `${scope.error} Nothing was imported.`);
|
|
457
|
+
if (scope.value === "project" && !loc.projectTrusted) return untrusted("import-codex");
|
|
458
|
+
let filePath = parsed.positionals[1];
|
|
459
|
+
if (!filePath) {
|
|
460
|
+
if (!host.hasUI) {
|
|
461
|
+
return clarification("import-codex", "import-codex needs a TOML file path. UI is unavailable, so no path was chosen and .codex/agents was not scanned. Example: /agents import-codex .codex/agents/reviewer.toml. Nothing was imported.");
|
|
462
|
+
}
|
|
463
|
+
const entered = await host.ui.input("Codex TOML file", ".codex/agents/name.toml");
|
|
464
|
+
if (!entered?.trim()) return clarification("import-codex", "Import path was dismissed. Nothing was imported.");
|
|
465
|
+
filePath = entered.trim();
|
|
466
|
+
}
|
|
467
|
+
const resolved = isAbsolute(filePath) ? filePath : resolve(loc.cwd, filePath);
|
|
468
|
+
let fileStats;
|
|
469
|
+
try {
|
|
470
|
+
fileStats = statSync(resolved);
|
|
471
|
+
} catch (error) {
|
|
472
|
+
return result("error", "import-codex", false, `Cannot read ${resolved}: ${error instanceof Error ? error.message : String(error)}. Nothing was imported.`);
|
|
473
|
+
}
|
|
474
|
+
if (fileStats.isDirectory()) {
|
|
475
|
+
return result("error", "import-codex", false, `${resolved} is a directory. import-codex does not scan directories, including .codex/agents. Pass one TOML file. Nothing was imported.`);
|
|
476
|
+
}
|
|
477
|
+
let source: string;
|
|
478
|
+
try {
|
|
479
|
+
source = readFileSync(resolved, "utf8");
|
|
480
|
+
} catch (error) {
|
|
481
|
+
return result("error", "import-codex", false, `Cannot read ${resolved}: ${error instanceof Error ? error.message : String(error)}. Nothing was imported.`);
|
|
482
|
+
}
|
|
483
|
+
const parsedSource = parseCodexSource(source, resolved);
|
|
484
|
+
if (!parsedSource.ok) {
|
|
485
|
+
return { ...result("error", "import-codex", false, parsedSource.diagnostics.map((item) => item.message).join("\n")), diagnostics: parsedSource.diagnostics };
|
|
486
|
+
}
|
|
487
|
+
const document = parsedSource.document;
|
|
488
|
+
const snapshot = readCatalog(loc);
|
|
489
|
+
const roles = catalogRoles(snapshot);
|
|
490
|
+
if (roles.length === 0) return result("error", "import-codex", false, "No roles are available to use as the one base role. Nothing was imported.");
|
|
491
|
+
const suggestion = suggestBaseRoles(`${document.name}\n${document.description}\n${document.developerInstructions}`, roles);
|
|
492
|
+
const requestedRoles = (parsed.flags.get("role") ?? []).map(canonicalRoleId);
|
|
493
|
+
if (requestedRoles.length > 1) {
|
|
494
|
+
const decision = await resolveRoleAssignment(requestedRoles.map((roleId) => ({ roleId })), {
|
|
495
|
+
hasUI: host.hasUI,
|
|
496
|
+
select: host.hasUI ? (title, options) => host.ui.select(title, options) : undefined,
|
|
497
|
+
});
|
|
498
|
+
if (decision.status !== "resolved" || decision.jobs.length !== 1) {
|
|
499
|
+
return clarification("import-codex", `${decision.message} Import did not write an agent with multiple parents.`);
|
|
500
|
+
}
|
|
501
|
+
requestedRoles.splice(0, requestedRoles.length, decision.jobs[0]!.roleId);
|
|
502
|
+
}
|
|
503
|
+
let roleId = requestedRoles[0];
|
|
504
|
+
if (roleId && !roles.some((role) => role.id === roleId)) {
|
|
505
|
+
return result("error", "import-codex", false, `Unknown role ${shortRoleName(roleId)}. Valid roles: ${roles.map((role) => shortRoleName(role.id)).join(", ")}. Nothing was imported.`);
|
|
506
|
+
}
|
|
507
|
+
const sourceRef = codexSourceRef(resolved);
|
|
508
|
+
const scoped = deps.sharedState ? await deps.sharedState.scopedAgents(scope.value) : listScopeAgents(loc, scope.value);
|
|
509
|
+
const existingLookup = matchExisting(scoped.agents, document.proposedId, sourceRef);
|
|
510
|
+
if (existingLookup.conflict) return clarification("import-codex", `${existingLookup.conflict} Nothing was imported.`);
|
|
511
|
+
if (!roleId) {
|
|
512
|
+
if (!host.hasUI) {
|
|
513
|
+
return clarification("import-codex", headlessImportMessage(document, suggestion, roles, existingLookup.match?.definition, sourceRef, scope.value, deps));
|
|
514
|
+
}
|
|
515
|
+
const ordered = [...roles].sort((left, right) => left.id.localeCompare(right.id));
|
|
516
|
+
if (suggestion.unique) {
|
|
517
|
+
const index = ordered.findIndex((role) => role.id === suggestion.unique);
|
|
518
|
+
if (index > 0) ordered.unshift(...ordered.splice(index, 1));
|
|
519
|
+
}
|
|
520
|
+
const title = suggestion.unique
|
|
521
|
+
? `Confirm one base role. Suggested ${suggestion.unique}. Imported instructions use replace mode.`
|
|
522
|
+
: suggestion.ambiguous.length > 0
|
|
523
|
+
? `Choose one base role. ${suggestion.ambiguous.join(" and ")} tied, and an agent cannot have both.`
|
|
524
|
+
: "Choose one base role. None was suggested from the Codex name.";
|
|
525
|
+
const selected = await host.ui.select(title, ordered.map(roleOption));
|
|
526
|
+
if (!selected) return clarification("import-codex", "Role confirmation was dismissed. Nothing was imported.");
|
|
527
|
+
roleId = selected.split(" ")[0];
|
|
528
|
+
if (!roleId || !roles.some((role) => role.id === roleId)) {
|
|
529
|
+
return result("error", "import-codex", false, `Unknown role choice ${JSON.stringify(selected)}. Nothing was imported.`);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
if (!host.hasUI) {
|
|
533
|
+
return clarification("import-codex", headlessImportMessage(document, { ...suggestion, unique: roleId, ambiguous: [] }, roles, existingLookup.match?.definition, sourceRef, scope.value, deps, roleId));
|
|
534
|
+
}
|
|
535
|
+
if (!roleId) return result("error", "import-codex", false, "No role was confirmed. Nothing was imported.");
|
|
536
|
+
const confirmedMode = await host.ui.confirm(
|
|
537
|
+
"Import instructions in replace mode?",
|
|
538
|
+
[
|
|
539
|
+
`Imported developer_instructions replace the ${roleId} instruction text.`,
|
|
540
|
+
"Model, effort, and tier still inherit unless you explicitly save Codex values as overrides.",
|
|
541
|
+
`Destination: ${scopeLabel(scope.value)} catalog.`,
|
|
542
|
+
`Proposed id: ${existingLookup.match?.definition.id ?? document.proposedId}.`,
|
|
543
|
+
`${PI_VS_CODEX_PRECEDENCE.codex} ${PI_VS_CODEX_PRECEDENCE.pi}`,
|
|
544
|
+
"The native file is an independent copy. Later edits to the Codex source do not change it.",
|
|
545
|
+
].join("\n"),
|
|
546
|
+
);
|
|
547
|
+
if (!confirmedMode) {
|
|
548
|
+
return clarification("import-codex", "Import cancelled. Codex instructions are only imported in replace mode, and that was not confirmed. Nothing was written.");
|
|
549
|
+
}
|
|
550
|
+
let saveOverrides = false;
|
|
551
|
+
if (document.storableModel || document.storableEffort) {
|
|
552
|
+
const choice = await host.ui.select("Codex model and effort are not copied into overrides unless you say so", [
|
|
553
|
+
"Inherit model and effort from the selected role",
|
|
554
|
+
"Save supported Codex model and effort as explicit overrides",
|
|
555
|
+
]);
|
|
556
|
+
if (!choice) return clarification("import-codex", "Override confirmation was dismissed. Inherited role values were not flattened into overrides. Nothing was imported.");
|
|
557
|
+
saveOverrides = choice.startsWith("Save ");
|
|
558
|
+
}
|
|
559
|
+
const id = existingLookup.match?.definition.id ?? document.proposedId;
|
|
560
|
+
const built = buildImportedAgent(document, {
|
|
561
|
+
id,
|
|
562
|
+
roleId,
|
|
563
|
+
saveOverrides,
|
|
564
|
+
importedAt: deps.now?.() ?? new Date().toISOString(),
|
|
565
|
+
sourceRef,
|
|
566
|
+
});
|
|
567
|
+
if (!built.ok || !built.definition) {
|
|
568
|
+
return { ...result("error", "import-codex", false, built.diagnostics.map((item) => item.message).join("\n") || "The native copy could not be built. Nothing was imported."), diagnostics: built.diagnostics };
|
|
569
|
+
}
|
|
570
|
+
if (existingLookup.match) {
|
|
571
|
+
const preview = renderReimportPreview(existingLookup.match.definition, built.definition);
|
|
572
|
+
const confirmed = await host.ui.confirm(`Replace ${id}?`, preview.text);
|
|
573
|
+
if (!confirmed) {
|
|
574
|
+
return clarification("import-codex", `${preview.text}\nReplacement was not confirmed. The existing definition was left unchanged.`);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
const saved = deps.sharedState ? await deps.sharedState.edit({ action: "definition", catalogId: built.definition.id, markdown: serializeDefinition(built.definition).markdown, scope: scope.value, replace: !!existingLookup.match }) : existingLookup.match
|
|
578
|
+
? saveDefinition({ ...loc, definition: built.definition, scope: scope.value, replace: true })
|
|
579
|
+
: createDefinition({ ...loc, definition: built.definition, scope: scope.value, replace: false });
|
|
580
|
+
if (deps.sharedState) loc.snapshot = withAgentSessionSettings(deps.sharedState.snapshot, loc.sessionSettings);
|
|
581
|
+
if (!saved.ok || !saved.path) {
|
|
582
|
+
return { ...result("error", "import-codex", false, saved.diagnostics.map((item) => item.message).join("\n") || "Import did not write a file."), diagnostics: [...parsedSource.diagnostics, ...built.diagnostics, ...saved.diagnostics] };
|
|
583
|
+
}
|
|
584
|
+
const view = presentCatalogEntry(readCatalog(loc), built.definition.id, deps.enrich, deps.readSkillDefaults);
|
|
585
|
+
const launchNote = view.catalogLaunchable
|
|
586
|
+
? "Catalog validation passed. Definition validity is not launchability."
|
|
587
|
+
: "The file was saved and is not launchable.";
|
|
588
|
+
return {
|
|
589
|
+
ok: true,
|
|
590
|
+
status: "ok",
|
|
591
|
+
command: "import-codex",
|
|
592
|
+
wrote: true,
|
|
593
|
+
path: saved.path,
|
|
594
|
+
scope: scope.value,
|
|
595
|
+
message: `Imported ${built.definition.id} into the ${scopeLabel(scope.value)} catalog at ${saved.path}. ${launchNote}\n${PI_VS_CODEX_PRECEDENCE.codex} ${PI_VS_CODEX_PRECEDENCE.pi}\n${view.text}`,
|
|
596
|
+
diagnostics: [...parsedSource.diagnostics, ...built.diagnostics, ...saved.diagnostics, ...viewDiagnostics(view)],
|
|
597
|
+
data: { view, replaced: Boolean(existingLookup.match) },
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
function headlessImportMessage(
|
|
602
|
+
document: CodexDocument,
|
|
603
|
+
suggestion: { unique?: string; ambiguous: string[] },
|
|
604
|
+
roles: { id: string; name: string }[],
|
|
605
|
+
existing: AgentDefinition | undefined,
|
|
606
|
+
sourceRef: string,
|
|
607
|
+
scope: "user" | "project",
|
|
608
|
+
deps: AgentCommandDeps,
|
|
609
|
+
confirmedRole?: string,
|
|
610
|
+
): string {
|
|
611
|
+
const roleLine = confirmedRole
|
|
612
|
+
? `Role ${confirmedRole} was passed but replacement mode is not confirmed.`
|
|
613
|
+
: suggestion.unique
|
|
614
|
+
? `Suggested role: ${suggestion.unique}. It is not confirmed.`
|
|
615
|
+
: suggestion.ambiguous.length > 0
|
|
616
|
+
? `Role suggestion ties ${suggestion.ambiguous.join(" and ")}. Choose one; an agent cannot have both.`
|
|
617
|
+
: `No role was suggested. Choose one of: ${roles.map((role) => role.id).join(", ")}.`;
|
|
618
|
+
const lines = [
|
|
619
|
+
"import-codex needs confirmation of one base role and replace mode.",
|
|
620
|
+
`UI is unavailable (${"print/json or hasUI=false"}). Nothing was written.`,
|
|
621
|
+
roleLine,
|
|
622
|
+
"Instruction mode would be replace. Imported developer_instructions would replace role instructions, not append to them.",
|
|
623
|
+
"Unspecified model and effort would inherit from the role. They are not flattened into overrides unless that is confirmed.",
|
|
624
|
+
`Destination would be the ${scopeLabel(scope)} catalog.`,
|
|
625
|
+
`Proposed id: ${existing?.id ?? document.proposedId}.`,
|
|
626
|
+
`developer_instructions: ${JSON.stringify(document.developerInstructions)}`,
|
|
627
|
+
`${PI_VS_CODEX_PRECEDENCE.codex} ${PI_VS_CODEX_PRECEDENCE.pi}`,
|
|
628
|
+
`Source ${sourceRef} would be copied, not watched.`,
|
|
629
|
+
];
|
|
630
|
+
const roleForPreview = confirmedRole ?? suggestion.unique;
|
|
631
|
+
if (existing && roleForPreview) {
|
|
632
|
+
const built = buildImportedAgent(document, {
|
|
633
|
+
id: existing.id,
|
|
634
|
+
roleId: roleForPreview,
|
|
635
|
+
saveOverrides: false,
|
|
636
|
+
importedAt: deps.now?.() ?? "unconfirmed",
|
|
637
|
+
sourceRef,
|
|
638
|
+
});
|
|
639
|
+
if (built.definition) lines.push(renderReimportPreview(existing, built.definition).text);
|
|
640
|
+
} else if (existing) {
|
|
641
|
+
lines.push(`instructions currently: ${JSON.stringify(existing.body)}`);
|
|
642
|
+
lines.push(`role currently: ${existing.roleId}`);
|
|
643
|
+
lines.push(`imported developer_instructions: ${JSON.stringify(document.developerInstructions)}`);
|
|
644
|
+
lines.push("The replacement role is not confirmed, so the native file was not changed.");
|
|
645
|
+
}
|
|
646
|
+
return lines.join("\n");
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
function matchExisting(
|
|
650
|
+
agents: { path: string; definition: AgentDefinition }[],
|
|
651
|
+
proposedId: string,
|
|
652
|
+
sourceRef: string,
|
|
653
|
+
): { match?: { path: string; definition: AgentDefinition }; conflict?: string } {
|
|
654
|
+
const hits = agents.filter((agent) => agent.definition.id === proposedId || (agent.definition.provenance?.format === CODEX_FORMAT && agent.definition.provenance.sourceRef === sourceRef));
|
|
655
|
+
if (hits.length > 1) {
|
|
656
|
+
return { conflict: `This import matches ${hits.length} files (${hits.map((hit) => `${hit.definition.id} at ${hit.path}`).join("; ")}). Keep one file. No merge and no write were done.` };
|
|
657
|
+
}
|
|
658
|
+
return { match: hits[0] };
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
function listScopeAgents(loc: CatalogLocation, scope: "user" | "project"): { agents: { path: string; definition: AgentDefinition }[]; diagnostics: Diagnostic[] } {
|
|
662
|
+
const diagnostics: Diagnostic[] = [];
|
|
663
|
+
if (scope === "project" && !loc.projectTrusted) return { agents: [], diagnostics };
|
|
664
|
+
const directory = scope === "project"
|
|
665
|
+
? projectCatalogPaths(loc.cwd, loc.projectConfigDirName).agents
|
|
666
|
+
: userCatalogPaths(loc.userRoot).agents;
|
|
667
|
+
if (!existsSync(directory)) return { agents: [], diagnostics };
|
|
668
|
+
let directoryStats;
|
|
669
|
+
try {
|
|
670
|
+
directoryStats = lstatSync(directory);
|
|
671
|
+
} catch (error) {
|
|
672
|
+
diagnostics.push(diagnostic(DiagnosticCodes.ioError, error instanceof Error ? error.message : String(error)));
|
|
673
|
+
return { agents: [], diagnostics };
|
|
674
|
+
}
|
|
675
|
+
if (directoryStats.isSymbolicLink() || !directoryStats.isDirectory()) return { agents: [], diagnostics };
|
|
676
|
+
const agents: { path: string; definition: AgentDefinition }[] = [];
|
|
677
|
+
for (const name of readdirSync(directory).sort()) {
|
|
678
|
+
if (name.startsWith(".") || !name.endsWith(".md")) continue;
|
|
679
|
+
const path = resolve(directory, name);
|
|
680
|
+
let fileStats;
|
|
681
|
+
try {
|
|
682
|
+
fileStats = lstatSync(path);
|
|
683
|
+
} catch {
|
|
684
|
+
continue;
|
|
685
|
+
}
|
|
686
|
+
if (fileStats.isSymbolicLink() || !fileStats.isFile()) continue;
|
|
687
|
+
let parsed;
|
|
688
|
+
try {
|
|
689
|
+
parsed = parseDefinition(readFileSync(path, "utf8"), path);
|
|
690
|
+
} catch {
|
|
691
|
+
continue;
|
|
692
|
+
}
|
|
693
|
+
if (parsed.definition?.kind === "agent") agents.push({ path, definition: parsed.definition });
|
|
694
|
+
}
|
|
695
|
+
return { agents, diagnostics };
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
function readOverrides(flags: Map<string, string[]>, overrides: PortablePreferences): string | undefined {
|
|
699
|
+
if (flags.has("model")) {
|
|
700
|
+
const model = flags.get("model")![0]!;
|
|
701
|
+
if (!MODEL_PATTERN.test(model)) return `model must be provider/model, got ${JSON.stringify(model)}. No provider was guessed.`;
|
|
702
|
+
overrides.model = model;
|
|
703
|
+
}
|
|
704
|
+
if (flags.has("effort")) {
|
|
705
|
+
const effort = flags.get("effort")![0]!;
|
|
706
|
+
if (!(EFFORT_LEVELS as readonly string[]).includes(effort)) return `effort must be one of ${EFFORT_LEVELS.join(", ")}, got ${JSON.stringify(effort)}.`;
|
|
707
|
+
overrides.effort = effort as ThinkingLevel;
|
|
708
|
+
}
|
|
709
|
+
if (flags.has("tier")) {
|
|
710
|
+
const tier = flags.get("tier")![0]!;
|
|
711
|
+
if (!TIER_PATTERN.test(tier)) return `tier must be a short lowercase label, got ${JSON.stringify(tier)}.`;
|
|
712
|
+
overrides.tier = tier;
|
|
713
|
+
}
|
|
714
|
+
return undefined;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
function catalogRoles(snapshot: CatalogSnapshot): { id: string; name: string }[] {
|
|
718
|
+
return listCatalog(snapshot)
|
|
719
|
+
.filter((entry) => entry.kind === "role" && entry.name)
|
|
720
|
+
.map((entry) => ({ id: entry.id, name: entry.name! }));
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
function roleOption(role: { id: string; name: string }): string {
|
|
724
|
+
return `${role.id} (${role.name})`;
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
function readScope(flags: Map<string, string[]>): { value: "user" | "project"; error?: string } {
|
|
728
|
+
const values = flags.get("scope") ?? [];
|
|
729
|
+
if (values.length === 0) return { value: "user" };
|
|
730
|
+
if (values.length > 1) return { value: "user", error: "Pass --scope once. Use user or project." };
|
|
731
|
+
if (values[0] === "user" || values[0] === "personal") return { value: "user" };
|
|
732
|
+
if (values[0] === "project") return { value: "project" };
|
|
733
|
+
return { value: "user", error: `Unknown scope ${JSON.stringify(values[0])}. Use user (the default) or project.` };
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
function scopeLabel(scope: "user" | "project"): string {
|
|
737
|
+
return scope === "project" ? "project" : "personal";
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
function location(host: AgentCommandHost, deps: AgentCommandDeps): CatalogLocation {
|
|
741
|
+
return {
|
|
742
|
+
snapshot: deps.sharedState ? withAgentSessionSettings(deps.sharedState.snapshot, deps.sessionSettings?.snapshot()) : undefined,
|
|
743
|
+
cwd: host.cwd,
|
|
744
|
+
userRoot: deps.userRoot ?? defaultUserRoot(),
|
|
745
|
+
projectTrusted: host.isProjectTrusted(),
|
|
746
|
+
projectConfigDirName: deps.projectConfigDirName,
|
|
747
|
+
bundledRoot: deps.bundledRoot,
|
|
748
|
+
sessionSettings: deps.sessionSettings?.snapshot(),
|
|
749
|
+
};
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
function readCatalog(loc: CatalogLocation): CatalogSnapshot {
|
|
753
|
+
if (loc.snapshot) return loc.snapshot;
|
|
754
|
+
return withAgentSessionSettings(loadCatalog(loc), loc.sessionSettings);
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
function untrusted(command: string): AgentCommandResult {
|
|
758
|
+
return result("error", command, false, "Refusing to write the project catalog because the project is not trusted. Omit --scope to save personally, or trust the project and pass --scope project. Nothing was written.");
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
function clarification(command: string, message: string, diagnostics: Diagnostic[] = []): AgentCommandResult {
|
|
762
|
+
return {
|
|
763
|
+
ok: false,
|
|
764
|
+
status: "clarification-needed",
|
|
765
|
+
command,
|
|
766
|
+
wrote: false,
|
|
767
|
+
message,
|
|
768
|
+
diagnostics: diagnostics.length > 0 ? diagnostics : [diagnostic("clarification-needed", message)],
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
function result(status: AgentCommandResult["status"], command: string, wrote: boolean, message: string): AgentCommandResult {
|
|
773
|
+
return { ok: status === "ok", status, command, wrote, message, diagnostics: status === "error" ? [diagnostic("agents-command", message.split("\n")[0] ?? message)] : [] };
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
function viewDiagnostics(view: OperationView): Diagnostic[] {
|
|
777
|
+
return view.validation.map((item) => diagnostic(item.code, item.message, item.blocking, item.path, item.field));
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
function diagnostic(code: string, message: string, blocking = true, path?: string, field?: string): Diagnostic {
|
|
781
|
+
return { severity: blocking ? "error" : "warning", code, message, path, field, blocking, structural: false };
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
function finish(host: AgentCommandHost, commandResult: AgentCommandResult): AgentCommandResult {
|
|
785
|
+
if (!host.hasUI) return commandResult;
|
|
786
|
+
const level = commandResult.status === "error" ? "error" : commandResult.status === "clarification-needed" ? "warning" : "info";
|
|
787
|
+
try {
|
|
788
|
+
host.ui.notify(commandResult.message, level);
|
|
789
|
+
} catch {
|
|
790
|
+
/* Notification is not a write. */
|
|
791
|
+
}
|
|
792
|
+
return commandResult;
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
async function finishInspection(host: AgentCommandHost, commandResult: AgentCommandResult, deps: AgentCommandDeps): Promise<AgentCommandResult> {
|
|
796
|
+
if (commandResult.ok && host.mode === "tui" && host.hasUI && host.ui.custom) {
|
|
797
|
+
const catalog = commandResult.data && typeof commandResult.data === "object" && "entries" in commandResult.data
|
|
798
|
+
? commandResult.data as ReturnType<typeof presentCatalog> : undefined;
|
|
799
|
+
const view = catalog ? undefined : commandResult.data as OperationView;
|
|
800
|
+
const entries = catalog ?? { entries: [view!], diagnostics: commandResult.diagnostics, revision: "", text: "" };
|
|
801
|
+
try {
|
|
802
|
+
host.ui.setWidget?.("agents-catalog", undefined);
|
|
803
|
+
let viewportHeight = 30;
|
|
804
|
+
await host.ui.custom<void>((tui, theme, _keys, done) =>
|
|
805
|
+
createCatalogComponent(entries, theme, () => tui.requestRender(), () => done(), view?.id, deps.sessionSettings ? {
|
|
806
|
+
onChange: deps.sharedState?.onChange,
|
|
807
|
+
beginEdit: deps.sharedState?.beginEdit,
|
|
808
|
+
get: () => presentCatalog(readCatalog(location(host, deps)), deps.enrich, deps.readSkillDefaults),
|
|
809
|
+
models: () => deps.editableModels?.() ?? [],
|
|
810
|
+
scopedModels: () => host.scopedModels ?? [],
|
|
811
|
+
settings: () => deps.sessionSettings!.snapshot(),
|
|
812
|
+
change: (id, key, value) => deps.sessionSettings!.change(id, key, value),
|
|
813
|
+
changeSkills(entry, edit) {
|
|
814
|
+
if (deps.sharedState) return deps.sharedState.edit({ action: "skills", catalogId: entry.id, edit }).then(saved => {
|
|
815
|
+
if (saved.ok && saved.path) { commandResult.wrote = true; commandResult.path = saved.path; commandResult.scope = saved.scope; }
|
|
816
|
+
return { ok: saved.ok, message: saved.message };
|
|
817
|
+
});
|
|
818
|
+
const result = saveSkillExposure({ ...location(host, deps), entry }, edit);
|
|
819
|
+
if (result.ok && result.path) {
|
|
820
|
+
commandResult.wrote = true;
|
|
821
|
+
commandResult.path = result.path;
|
|
822
|
+
commandResult.scope = result.scope;
|
|
823
|
+
}
|
|
824
|
+
return { ok: result.ok, message: result.message };
|
|
825
|
+
},
|
|
826
|
+
discoverSkills: () => deps.discoveredSkills ?? [],
|
|
827
|
+
save(id) {
|
|
828
|
+
if (deps.sharedState) return deps.sharedState.edit({ action: "preferences", catalogId: id, preferences: deps.sessionSettings!.snapshot()[id] ?? {} }).then(saved => {
|
|
829
|
+
if (saved.ok) { commandResult.wrote = true; commandResult.path = saved.path; commandResult.scope = saved.scope; }
|
|
830
|
+
return { ok: saved.ok, message: saved.ok ? `Defaults saved (${saved.scope}): ${id}.` : saved.diagnostics.map((item: Diagnostic) => item.message).join(" ") };
|
|
831
|
+
});
|
|
832
|
+
const loc = location(host, deps);
|
|
833
|
+
const saved = saveAgentSessionDefaults(loadCatalog(loc), id, deps.sessionSettings!.snapshot(), loc);
|
|
834
|
+
if (saved.ok) {
|
|
835
|
+
commandResult.wrote = true;
|
|
836
|
+
commandResult.path = saved.path;
|
|
837
|
+
commandResult.scope = saved.scope;
|
|
838
|
+
}
|
|
839
|
+
return { ok: saved.ok, message: saved.ok ? `Defaults saved (${saved.scope}): ${id}.` : saved.diagnostics.map((item) => item.message).join(" ") };
|
|
840
|
+
},
|
|
841
|
+
resetToBundled(entry) {
|
|
842
|
+
if (deps.sharedState) return deps.sharedState.edit({ action: "reset-runtime", catalogId: entry.id }).then(saved => {
|
|
843
|
+
if (saved.ok) { commandResult.wrote = true; commandResult.path = saved.path; commandResult.scope = saved.scope; deps.sessionSettings!.reset(entry.id); }
|
|
844
|
+
return { ok: saved.ok, message: saved.ok ? `Bundled model/effort restored: ${entry.id}. Role instructions unchanged.` : saved.diagnostics.map((item: Diagnostic) => item.message).join(" ") };
|
|
845
|
+
});
|
|
846
|
+
const source = entry.winningSource;
|
|
847
|
+
if (!source) return { ok: false, message: "The definition source is unavailable. Reopen its settings." };
|
|
848
|
+
const reset = resetRuntimeToBundled({ ...location(host, deps), id: entry.id, expectedPath: source.path, expectedDigest: source.contentDigest });
|
|
849
|
+
if (reset.ok) {
|
|
850
|
+
commandResult.wrote = true;
|
|
851
|
+
commandResult.path = reset.path;
|
|
852
|
+
commandResult.scope = "user";
|
|
853
|
+
try { deps.sessionSettings!.reset(entry.id); }
|
|
854
|
+
catch (error) {
|
|
855
|
+
return { ok: false, message: `Saved defaults reset for ${entry.id}, but current-session overrides remain active: ${error instanceof Error ? error.message : String(error)}. Retry Reset to bundled to clear them.` };
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
return { ok: reset.ok, message: reset.ok
|
|
859
|
+
? `Bundled model/effort restored: ${entry.id}. Role instructions unchanged.`
|
|
860
|
+
: reset.diagnostics.map(item => item.message).join(" ") };
|
|
861
|
+
},
|
|
862
|
+
resetDefinition(entry) {
|
|
863
|
+
if (deps.sharedState) return deps.sharedState.edit({ action: "reset-definition", catalogId: entry.id }).then(saved => {
|
|
864
|
+
if (saved.ok) { commandResult.wrote = true; commandResult.path = saved.path; commandResult.scope = saved.scope; }
|
|
865
|
+
return { ok: saved.ok, message: saved.ok ? `Bundled instructions restored: ${entry.id}. Model/effort kept. Backup: ${saved.backupPath}.` : saved.diagnostics.map((item: Diagnostic) => item.message).join(" ") };
|
|
866
|
+
});
|
|
867
|
+
if (entry.identity.scope === "bundled") return { ok: true, message: `Already using bundled instructions: ${entry.id}. Model/effort unchanged.` };
|
|
868
|
+
const source = entry.winningSource;
|
|
869
|
+
if (!source) return { ok: false, message: "The definition source is unavailable. Reopen its settings." };
|
|
870
|
+
const reset = resetUserDefinition({ ...location(host, deps), id: entry.id, expectedPath: source.path, expectedDigest: source.contentDigest });
|
|
871
|
+
if (reset.ok) {
|
|
872
|
+
commandResult.wrote = true;
|
|
873
|
+
commandResult.path = reset.path;
|
|
874
|
+
commandResult.scope = "user";
|
|
875
|
+
}
|
|
876
|
+
return { ok: reset.ok, message: reset.ok
|
|
877
|
+
? `Bundled instructions restored: ${entry.id}. Model/effort kept. Backup: ${reset.backupPath}.`
|
|
878
|
+
: reset.diagnostics.map(item => item.message).join(" ") };
|
|
879
|
+
},
|
|
880
|
+
} : undefined, () => viewportHeight), {
|
|
881
|
+
overlay: true,
|
|
882
|
+
overlayOptions: {
|
|
883
|
+
anchor: "top-left", width: "100%", maxHeight: "100%", margin: 0,
|
|
884
|
+
visible: (_width, height) => { viewportHeight = height; return true; },
|
|
885
|
+
},
|
|
886
|
+
});
|
|
887
|
+
if (deps.sessionSettings) {
|
|
888
|
+
const current = readCatalog(location(host, deps));
|
|
889
|
+
const refreshed = view ? presentCatalogEntry(current, view.id, deps.enrich, deps.readSkillDefaults) : presentCatalog(current, deps.enrich, deps.readSkillDefaults);
|
|
890
|
+
commandResult.data = refreshed;
|
|
891
|
+
commandResult.message = refreshed.text;
|
|
892
|
+
}
|
|
893
|
+
return commandResult;
|
|
894
|
+
} catch {
|
|
895
|
+
// A non-interactive host may expose custom() without supporting overlays.
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
return finish(host, commandResult);
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
function tokenize(input: string): string[] {
|
|
902
|
+
const tokens: string[] = [];
|
|
903
|
+
for (const match of input.matchAll(/"([^"]*)"|'([^']*)'|(\S+)/g)) tokens.push(match[1] ?? match[2] ?? match[3] ?? "");
|
|
904
|
+
return tokens;
|
|
905
|
+
}
|