@jini-ai/agent-runtime 0.1.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/LICENSE +201 -0
- package/README.md +43 -0
- package/dist/acp-model-probe.d.ts +48 -0
- package/dist/acp-model-probe.d.ts.map +1 -0
- package/dist/acp-model-probe.js +15 -0
- package/dist/acp-model-probe.js.map +1 -0
- package/dist/agent-protocol/acp/account-failure.d.ts +54 -0
- package/dist/agent-protocol/acp/account-failure.d.ts.map +1 -0
- package/dist/agent-protocol/acp/account-failure.js +37 -0
- package/dist/agent-protocol/acp/account-failure.js.map +1 -0
- package/dist/agent-protocol/acp/constants.d.ts +26 -0
- package/dist/agent-protocol/acp/constants.d.ts.map +1 -0
- package/dist/agent-protocol/acp/constants.js +39 -0
- package/dist/agent-protocol/acp/constants.js.map +1 -0
- package/dist/agent-protocol/acp/index.d.ts +14 -0
- package/dist/agent-protocol/acp/index.d.ts.map +1 -0
- package/dist/agent-protocol/acp/index.js +14 -0
- package/dist/agent-protocol/acp/index.js.map +1 -0
- package/dist/agent-protocol/acp/json.d.ts +82 -0
- package/dist/agent-protocol/acp/json.d.ts.map +1 -0
- package/dist/agent-protocol/acp/json.js +144 -0
- package/dist/agent-protocol/acp/json.js.map +1 -0
- package/dist/agent-protocol/acp/models.d.ts +112 -0
- package/dist/agent-protocol/acp/models.d.ts.map +1 -0
- package/dist/agent-protocol/acp/models.js +293 -0
- package/dist/agent-protocol/acp/models.js.map +1 -0
- package/dist/agent-protocol/acp/rpc.d.ts +107 -0
- package/dist/agent-protocol/acp/rpc.d.ts.map +1 -0
- package/dist/agent-protocol/acp/rpc.js +162 -0
- package/dist/agent-protocol/acp/rpc.js.map +1 -0
- package/dist/agent-protocol/acp/session-params.d.ts +55 -0
- package/dist/agent-protocol/acp/session-params.d.ts.map +1 -0
- package/dist/agent-protocol/acp/session-params.js +81 -0
- package/dist/agent-protocol/acp/session-params.js.map +1 -0
- package/dist/agent-protocol/acp/session.d.ts +101 -0
- package/dist/agent-protocol/acp/session.d.ts.map +1 -0
- package/dist/agent-protocol/acp/session.js +832 -0
- package/dist/agent-protocol/acp/session.js.map +1 -0
- package/dist/agent-protocol/acp/text-suppression.d.ts +73 -0
- package/dist/agent-protocol/acp/text-suppression.d.ts.map +1 -0
- package/dist/agent-protocol/acp/text-suppression.js +229 -0
- package/dist/agent-protocol/acp/text-suppression.js.map +1 -0
- package/dist/agent-protocol/acp/types.d.ts +27 -0
- package/dist/agent-protocol/acp/types.d.ts.map +1 -0
- package/dist/agent-protocol/acp/types.js +2 -0
- package/dist/agent-protocol/acp/types.js.map +1 -0
- package/dist/agent-protocol/acp/updates.d.ts +166 -0
- package/dist/agent-protocol/acp/updates.d.ts.map +1 -0
- package/dist/agent-protocol/acp/updates.js +268 -0
- package/dist/agent-protocol/acp/updates.js.map +1 -0
- package/dist/agent-protocol/core/index.d.ts +6 -0
- package/dist/agent-protocol/core/index.d.ts.map +1 -0
- package/dist/agent-protocol/core/index.js +6 -0
- package/dist/agent-protocol/core/index.js.map +1 -0
- package/dist/agent-protocol/core/json-line-stream.d.ts +42 -0
- package/dist/agent-protocol/core/json-line-stream.d.ts.map +1 -0
- package/dist/agent-protocol/core/json-line-stream.js +333 -0
- package/dist/agent-protocol/core/json-line-stream.js.map +1 -0
- package/dist/agent-protocol/index.d.ts +8 -0
- package/dist/agent-protocol/index.d.ts.map +1 -0
- package/dist/agent-protocol/index.js +8 -0
- package/dist/agent-protocol/index.js.map +1 -0
- package/dist/agent-protocol/pi-rpc/events.d.ts +26 -0
- package/dist/agent-protocol/pi-rpc/events.d.ts.map +1 -0
- package/dist/agent-protocol/pi-rpc/events.js +167 -0
- package/dist/agent-protocol/pi-rpc/events.js.map +1 -0
- package/dist/agent-protocol/pi-rpc/index.d.ts +11 -0
- package/dist/agent-protocol/pi-rpc/index.d.ts.map +1 -0
- package/dist/agent-protocol/pi-rpc/index.js +11 -0
- package/dist/agent-protocol/pi-rpc/index.js.map +1 -0
- package/dist/agent-protocol/pi-rpc/internal.d.ts +45 -0
- package/dist/agent-protocol/pi-rpc/internal.d.ts.map +1 -0
- package/dist/agent-protocol/pi-rpc/internal.js +41 -0
- package/dist/agent-protocol/pi-rpc/internal.js.map +1 -0
- package/dist/agent-protocol/pi-rpc/models.d.ts +21 -0
- package/dist/agent-protocol/pi-rpc/models.d.ts.map +1 -0
- package/dist/agent-protocol/pi-rpc/models.js +48 -0
- package/dist/agent-protocol/pi-rpc/models.js.map +1 -0
- package/dist/agent-protocol/pi-rpc/session.d.ts +106 -0
- package/dist/agent-protocol/pi-rpc/session.d.ts.map +1 -0
- package/dist/agent-protocol/pi-rpc/session.js +371 -0
- package/dist/agent-protocol/pi-rpc/session.js.map +1 -0
- package/dist/amr-model-cache.d.ts +40 -0
- package/dist/amr-model-cache.d.ts.map +1 -0
- package/dist/amr-model-cache.js +79 -0
- package/dist/amr-model-cache.js.map +1 -0
- package/dist/amr-profile-resolver.d.ts +21 -0
- package/dist/amr-profile-resolver.d.ts.map +1 -0
- package/dist/amr-profile-resolver.js +4 -0
- package/dist/amr-profile-resolver.js.map +1 -0
- package/dist/artifact-taxonomy.d.ts +27 -0
- package/dist/artifact-taxonomy.d.ts.map +1 -0
- package/dist/artifact-taxonomy.js +5 -0
- package/dist/artifact-taxonomy.js.map +1 -0
- package/dist/auth.d.ts +25 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +332 -0
- package/dist/auth.js.map +1 -0
- package/dist/capabilities.d.ts +9 -0
- package/dist/capabilities.d.ts.map +1 -0
- package/dist/capabilities.js +2 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/claude-stream.d.ts +37 -0
- package/dist/claude-stream.d.ts.map +1 -0
- package/dist/claude-stream.js +660 -0
- package/dist/claude-stream.js.map +1 -0
- package/dist/copilot-stream.d.ts +37 -0
- package/dist/copilot-stream.d.ts.map +1 -0
- package/dist/copilot-stream.js +136 -0
- package/dist/copilot-stream.js.map +1 -0
- package/dist/defs/aider.d.ts +13 -0
- package/dist/defs/aider.d.ts.map +1 -0
- package/dist/defs/aider.js +63 -0
- package/dist/defs/aider.js.map +1 -0
- package/dist/defs/amp.d.ts +12 -0
- package/dist/defs/amp.d.ts.map +1 -0
- package/dist/defs/amp.js +56 -0
- package/dist/defs/amp.js.map +1 -0
- package/dist/defs/amr.d.ts +37 -0
- package/dist/defs/amr.d.ts.map +1 -0
- package/dist/defs/amr.js +303 -0
- package/dist/defs/amr.js.map +1 -0
- package/dist/defs/antigravity.d.ts +25 -0
- package/dist/defs/antigravity.d.ts.map +1 -0
- package/dist/defs/antigravity.js +213 -0
- package/dist/defs/antigravity.js.map +1 -0
- package/dist/defs/claude.d.ts +30 -0
- package/dist/defs/claude.d.ts.map +1 -0
- package/dist/defs/claude.js +130 -0
- package/dist/defs/claude.js.map +1 -0
- package/dist/defs/codebuddy.d.ts +26 -0
- package/dist/defs/codebuddy.d.ts.map +1 -0
- package/dist/defs/codebuddy.js +124 -0
- package/dist/defs/codebuddy.js.map +1 -0
- package/dist/defs/codex.d.ts +30 -0
- package/dist/defs/codex.d.ts.map +1 -0
- package/dist/defs/codex.js +196 -0
- package/dist/defs/codex.js.map +1 -0
- package/dist/defs/copilot.d.ts +12 -0
- package/dist/defs/copilot.d.ts.map +1 -0
- package/dist/defs/copilot.js +88 -0
- package/dist/defs/copilot.js.map +1 -0
- package/dist/defs/cursor-agent.d.ts +27 -0
- package/dist/defs/cursor-agent.d.ts.map +1 -0
- package/dist/defs/cursor-agent.js +93 -0
- package/dist/defs/cursor-agent.js.map +1 -0
- package/dist/defs/deepseek.d.ts +12 -0
- package/dist/defs/deepseek.d.ts.map +1 -0
- package/dist/defs/deepseek.js +53 -0
- package/dist/defs/deepseek.js.map +1 -0
- package/dist/defs/devin.d.ts +12 -0
- package/dist/defs/devin.d.ts.map +1 -0
- package/dist/defs/devin.js +45 -0
- package/dist/defs/devin.js.map +1 -0
- package/dist/defs/grok-build.d.ts +26 -0
- package/dist/defs/grok-build.d.ts.map +1 -0
- package/dist/defs/grok-build.js +105 -0
- package/dist/defs/grok-build.js.map +1 -0
- package/dist/defs/hermes.d.ts +13 -0
- package/dist/defs/hermes.d.ts.map +1 -0
- package/dist/defs/hermes.js +51 -0
- package/dist/defs/hermes.js.map +1 -0
- package/dist/defs/index.d.ts +33 -0
- package/dist/defs/index.d.ts.map +1 -0
- package/dist/defs/index.js +33 -0
- package/dist/defs/index.js.map +1 -0
- package/dist/defs/kilo.d.ts +12 -0
- package/dist/defs/kilo.d.ts.map +1 -0
- package/dist/defs/kilo.js +20 -0
- package/dist/defs/kilo.js.map +1 -0
- package/dist/defs/kimi.d.ts +13 -0
- package/dist/defs/kimi.d.ts.map +1 -0
- package/dist/defs/kimi.js +26 -0
- package/dist/defs/kimi.js.map +1 -0
- package/dist/defs/kiro.d.ts +12 -0
- package/dist/defs/kiro.d.ts.map +1 -0
- package/dist/defs/kiro.js +20 -0
- package/dist/defs/kiro.js.map +1 -0
- package/dist/defs/mimo.d.ts +13 -0
- package/dist/defs/mimo.d.ts.map +1 -0
- package/dist/defs/mimo.js +26 -0
- package/dist/defs/mimo.js.map +1 -0
- package/dist/defs/opencode.d.ts +27 -0
- package/dist/defs/opencode.d.ts.map +1 -0
- package/dist/defs/opencode.js +89 -0
- package/dist/defs/opencode.js.map +1 -0
- package/dist/defs/pi.d.ts +18 -0
- package/dist/defs/pi.d.ts.map +1 -0
- package/dist/defs/pi.js +94 -0
- package/dist/defs/pi.js.map +1 -0
- package/dist/defs/qoder.d.ts +11 -0
- package/dist/defs/qoder.d.ts.map +1 -0
- package/dist/defs/qoder.js +50 -0
- package/dist/defs/qoder.js.map +1 -0
- package/dist/defs/qwen.d.ts +11 -0
- package/dist/defs/qwen.d.ts.map +1 -0
- package/dist/defs/qwen.js +28 -0
- package/dist/defs/qwen.js.map +1 -0
- package/dist/defs/reasonix.d.ts +20 -0
- package/dist/defs/reasonix.d.ts.map +1 -0
- package/dist/defs/reasonix.js +60 -0
- package/dist/defs/reasonix.js.map +1 -0
- package/dist/defs/shared.d.ts +23 -0
- package/dist/defs/shared.d.ts.map +1 -0
- package/dist/defs/shared.js +58 -0
- package/dist/defs/shared.js.map +1 -0
- package/dist/defs/trae-cli.d.ts +14 -0
- package/dist/defs/trae-cli.d.ts.map +1 -0
- package/dist/defs/trae-cli.js +22 -0
- package/dist/defs/trae-cli.js.map +1 -0
- package/dist/defs/vibe.d.ts +12 -0
- package/dist/defs/vibe.d.ts.map +1 -0
- package/dist/defs/vibe.js +20 -0
- package/dist/defs/vibe.js.map +1 -0
- package/dist/detection.d.ts +14 -0
- package/dist/detection.d.ts.map +1 -0
- package/dist/detection.js +266 -0
- package/dist/detection.js.map +1 -0
- package/dist/diagnostics.d.ts +8 -0
- package/dist/diagnostics.d.ts.map +1 -0
- package/dist/diagnostics.js +95 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/env.d.ts +19 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +95 -0
- package/dist/env.js.map +1 -0
- package/dist/executables.d.ts +24 -0
- package/dist/executables.d.ts.map +1 -0
- package/dist/executables.js +349 -0
- package/dist/executables.js.map +1 -0
- package/dist/index.d.ts +74 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +102 -0
- package/dist/index.js.map +1 -0
- package/dist/invocation.d.ts +6 -0
- package/dist/invocation.d.ts.map +1 -0
- package/dist/invocation.js +47 -0
- package/dist/invocation.js.map +1 -0
- package/dist/json-event-stream.d.ts +9 -0
- package/dist/json-event-stream.d.ts.map +1 -0
- package/dist/json-event-stream.js +856 -0
- package/dist/json-event-stream.js.map +1 -0
- package/dist/launch.d.ts +12 -0
- package/dist/launch.d.ts.map +1 -0
- package/dist/launch.js +221 -0
- package/dist/launch.js.map +1 -0
- package/dist/mcp.d.ts +44 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +12 -0
- package/dist/mcp.js.map +1 -0
- package/dist/metadata.d.ts +24 -0
- package/dist/metadata.d.ts.map +1 -0
- package/dist/metadata.js +100 -0
- package/dist/metadata.js.map +1 -0
- package/dist/mmd-routes.d.ts +12 -0
- package/dist/mmd-routes.d.ts.map +1 -0
- package/dist/mmd-routes.js +146 -0
- package/dist/mmd-routes.js.map +1 -0
- package/dist/model-registry.d.ts +120 -0
- package/dist/model-registry.d.ts.map +1 -0
- package/dist/model-registry.js +77 -0
- package/dist/model-registry.js.map +1 -0
- package/dist/models.d.ts +16 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +93 -0
- package/dist/models.js.map +1 -0
- package/dist/opencode-log.d.ts +16 -0
- package/dist/opencode-log.d.ts.map +1 -0
- package/dist/opencode-log.js +163 -0
- package/dist/opencode-log.js.map +1 -0
- package/dist/paths.d.ts +3 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +29 -0
- package/dist/paths.js.map +1 -0
- package/dist/pi-models.d.ts +13 -0
- package/dist/pi-models.d.ts.map +1 -0
- package/dist/pi-models.js +36 -0
- package/dist/pi-models.js.map +1 -0
- package/dist/prompt-augmenter.d.ts +60 -0
- package/dist/prompt-augmenter.d.ts.map +1 -0
- package/dist/prompt-augmenter.js +26 -0
- package/dist/prompt-augmenter.js.map +1 -0
- package/dist/prompt-budget.d.ts +20 -0
- package/dist/prompt-budget.d.ts.map +1 -0
- package/dist/prompt-budget.js +226 -0
- package/dist/prompt-budget.js.map +1 -0
- package/dist/prompt-file.d.ts +7 -0
- package/dist/prompt-file.d.ts.map +1 -0
- package/dist/prompt-file.js +27 -0
- package/dist/prompt-file.js.map +1 -0
- package/dist/providers/aihubmix.d.ts +99 -0
- package/dist/providers/aihubmix.d.ts.map +1 -0
- package/dist/providers/aihubmix.js +239 -0
- package/dist/providers/aihubmix.js.map +1 -0
- package/dist/providers/anthropic-messages.d.ts +116 -0
- package/dist/providers/anthropic-messages.d.ts.map +1 -0
- package/dist/providers/anthropic-messages.js +313 -0
- package/dist/providers/anthropic-messages.js.map +1 -0
- package/dist/providers/azure-chat.d.ts +99 -0
- package/dist/providers/azure-chat.d.ts.map +1 -0
- package/dist/providers/azure-chat.js +164 -0
- package/dist/providers/azure-chat.js.map +1 -0
- package/dist/providers/connection-guard.d.ts +67 -0
- package/dist/providers/connection-guard.d.ts.map +1 -0
- package/dist/providers/connection-guard.js +211 -0
- package/dist/providers/connection-guard.js.map +1 -0
- package/dist/providers/elevenlabs.d.ts +28 -0
- package/dist/providers/elevenlabs.d.ts.map +1 -0
- package/dist/providers/elevenlabs.js +138 -0
- package/dist/providers/elevenlabs.js.map +1 -0
- package/dist/providers/google-messages.d.ts +108 -0
- package/dist/providers/google-messages.d.ts.map +1 -0
- package/dist/providers/google-messages.js +284 -0
- package/dist/providers/google-messages.js.map +1 -0
- package/dist/providers/google.d.ts +20 -0
- package/dist/providers/google.d.ts.map +1 -0
- package/dist/providers/google.js +42 -0
- package/dist/providers/google.js.map +1 -0
- package/dist/providers/index.d.ts +39 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +39 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/model-catalog.d.ts +32 -0
- package/dist/providers/model-catalog.d.ts.map +1 -0
- package/dist/providers/model-catalog.js +394 -0
- package/dist/providers/model-catalog.js.map +1 -0
- package/dist/providers/oauth-callback-server.d.ts +35 -0
- package/dist/providers/oauth-callback-server.d.ts.map +1 -0
- package/dist/providers/oauth-callback-server.js +217 -0
- package/dist/providers/oauth-callback-server.js.map +1 -0
- package/dist/providers/oauth-credentials.d.ts +29 -0
- package/dist/providers/oauth-credentials.d.ts.map +1 -0
- package/dist/providers/oauth-credentials.js +70 -0
- package/dist/providers/oauth-credentials.js.map +1 -0
- package/dist/providers/oauth-provider.d.ts +95 -0
- package/dist/providers/oauth-provider.d.ts.map +1 -0
- package/dist/providers/oauth-provider.js +130 -0
- package/dist/providers/oauth-provider.js.map +1 -0
- package/dist/providers/oauth-tokens.d.ts +35 -0
- package/dist/providers/oauth-tokens.d.ts.map +1 -0
- package/dist/providers/oauth-tokens.js +136 -0
- package/dist/providers/oauth-tokens.js.map +1 -0
- package/dist/providers/ollama-chat.d.ts +106 -0
- package/dist/providers/ollama-chat.d.ts.map +1 -0
- package/dist/providers/ollama-chat.js +292 -0
- package/dist/providers/ollama-chat.js.map +1 -0
- package/dist/providers/openai-chat.d.ts +147 -0
- package/dist/providers/openai-chat.d.ts.map +1 -0
- package/dist/providers/openai-chat.js +302 -0
- package/dist/providers/openai-chat.js.map +1 -0
- package/dist/providers/pkce.d.ts +81 -0
- package/dist/providers/pkce.d.ts.map +1 -0
- package/dist/providers/pkce.js +176 -0
- package/dist/providers/pkce.js.map +1 -0
- package/dist/providers/sse-decode.d.ts +47 -0
- package/dist/providers/sse-decode.d.ts.map +1 -0
- package/dist/providers/sse-decode.js +109 -0
- package/dist/providers/sse-decode.js.map +1 -0
- package/dist/providers/token-params.d.ts +29 -0
- package/dist/providers/token-params.d.ts.map +1 -0
- package/dist/providers/token-params.js +41 -0
- package/dist/providers/token-params.js.map +1 -0
- package/dist/providers/turn-end-guard.d.ts +37 -0
- package/dist/providers/turn-end-guard.d.ts.map +1 -0
- package/dist/providers/turn-end-guard.js +42 -0
- package/dist/providers/turn-end-guard.js.map +1 -0
- package/dist/providers/types.d.ts +36 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/types.js +13 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/qoder-stream.d.ts +19 -0
- package/dist/qoder-stream.d.ts.map +1 -0
- package/dist/qoder-stream.js +167 -0
- package/dist/qoder-stream.js.map +1 -0
- package/dist/registry.d.ts +5 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +58 -0
- package/dist/registry.js.map +1 -0
- package/dist/resolution.d.ts +2 -0
- package/dist/resolution.d.ts.map +1 -0
- package/dist/resolution.js +19 -0
- package/dist/resolution.js.map +1 -0
- package/dist/role-marker-guard.d.ts +53 -0
- package/dist/role-marker-guard.d.ts.map +1 -0
- package/dist/role-marker-guard.js +280 -0
- package/dist/role-marker-guard.js.map +1 -0
- package/dist/telemetry-sink.d.ts +35 -0
- package/dist/telemetry-sink.d.ts.map +1 -0
- package/dist/telemetry-sink.js +5 -0
- package/dist/telemetry-sink.js.map +1 -0
- package/dist/terminal-launch.d.ts +11 -0
- package/dist/terminal-launch.d.ts.map +1 -0
- package/dist/terminal-launch.js +123 -0
- package/dist/terminal-launch.js.map +1 -0
- package/dist/types.d.ts +185 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +47 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module opencode-log
|
|
3
|
+
*
|
|
4
|
+
* OpenCode swallows provider failures in headless `run --format json` mode:
|
|
5
|
+
* on a 429 usage-limit (and similar), it marks the error retryable, retries
|
|
6
|
+
* silently, and emits NOTHING on stdout/stderr — so the caller only sees an
|
|
7
|
+
* inactivity-watchdog timeout with no reason. The real error is recorded
|
|
8
|
+
* only in OpenCode's own session log (`service=llm … error={…}`). This
|
|
9
|
+
* module recovers that signal so a chat UI can show "usage limit reached"
|
|
10
|
+
* instead of a bare timeout. OpenCode-specific by design.
|
|
11
|
+
*
|
|
12
|
+
* Ported verbatim from OD's `apps/daemon/src/runtimes/auth/opencode-log.ts`
|
|
13
|
+
* — no product coupling (it only reads OpenCode's own on-disk log format).
|
|
14
|
+
*/
|
|
15
|
+
import { readdirSync, readFileSync, statSync } from 'node:fs';
|
|
16
|
+
import path from 'node:path';
|
|
17
|
+
import { classifyAgentServiceFailure } from './auth.js';
|
|
18
|
+
// OpenCode resolves its data dir as `$XDG_DATA_HOME/opencode` (when set) or
|
|
19
|
+
// `$HOME/.local/share/opencode`, with session logs under `log/`. Mirror that
|
|
20
|
+
// so we read the same files the spawned CLI wrote. Null when neither var is
|
|
21
|
+
// set (we have no basis to guess a path).
|
|
22
|
+
export function resolveOpenCodeLogDir(env) {
|
|
23
|
+
const xdg = typeof env.XDG_DATA_HOME === 'string' ? env.XDG_DATA_HOME.trim() : '';
|
|
24
|
+
const home = typeof env.HOME === 'string' ? env.HOME.trim() : '';
|
|
25
|
+
const base = xdg || (home ? path.join(home, '.local', 'share') : '');
|
|
26
|
+
if (!base)
|
|
27
|
+
return null;
|
|
28
|
+
return path.join(base, 'opencode', 'log');
|
|
29
|
+
}
|
|
30
|
+
// Read the tail of OpenCode's most recent session log. Filenames are
|
|
31
|
+
// `<ISO-like-timestamp>.log`, so a lexicographic sort orders them by
|
|
32
|
+
// recency. `since` (when provided) binds the lookup to the current run: a
|
|
33
|
+
// file last written before the run started can only belong to an earlier
|
|
34
|
+
// session, so it is skipped rather than risk surfacing a stale provider
|
|
35
|
+
// error for this run. The 2 MB tail comfortably holds the final error frame
|
|
36
|
+
// even though OpenCode embeds the entire request body (system prompt + tool
|
|
37
|
+
// schemas) in each `service=llm` line. Synchronous on purpose: the only
|
|
38
|
+
// callers are a (non-async) run-close handler and an inactivity watchdog,
|
|
39
|
+
// once per failed OpenCode run. Returns null on any fs error (no dir yet,
|
|
40
|
+
// perms).
|
|
41
|
+
export function readLatestOpenCodeLogTail(logDir, options = {}) {
|
|
42
|
+
const { maxBytes = 2_000_000, since } = options;
|
|
43
|
+
let names;
|
|
44
|
+
try {
|
|
45
|
+
names = readdirSync(logDir).filter((name) => name.endsWith('.log'));
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
if (names.length === 0)
|
|
51
|
+
return null;
|
|
52
|
+
names.sort().reverse(); // newest filename first
|
|
53
|
+
for (const name of names) {
|
|
54
|
+
const full = path.join(logDir, name);
|
|
55
|
+
if (since != null) {
|
|
56
|
+
try {
|
|
57
|
+
if (statSync(full).mtimeMs < since)
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
const buf = readFileSync(full, 'utf8');
|
|
66
|
+
return buf.length > maxBytes ? buf.slice(-maxBytes) : buf;
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
// Only treat a `"message":"…"` value as the failure reason when it reads
|
|
75
|
+
// like a service error. The embedded request body uses `"content":` for
|
|
76
|
+
// prompt text, but tool schemas and user prompts could still contain a
|
|
77
|
+
// stray `"message"` key, so this keyword gate keeps unrelated payload text
|
|
78
|
+
// from masquerading as the error.
|
|
79
|
+
const SERVICE_ERROR_MESSAGE_RE = /usage limit|rate[ _-]?limit|quota|limit reached|insufficient|credit|balance|overloaded|unavailable|unauthor|authenticat|invalid[ _-]?(?:api[ _-]?)?key|api key|\/login|exhaust|too many requests/i;
|
|
80
|
+
function pickServiceErrorMessage(line) {
|
|
81
|
+
const re = /"message":"((?:[^"\\]|\\.)*)"/g;
|
|
82
|
+
let match;
|
|
83
|
+
while ((match = re.exec(line)) !== null) {
|
|
84
|
+
let value;
|
|
85
|
+
try {
|
|
86
|
+
value = JSON.parse(`"${match[1]}"`);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
value = match[1];
|
|
90
|
+
}
|
|
91
|
+
value = value.trim();
|
|
92
|
+
// Conservative by design (SEC-002 / CR-R2): a non-matching "message" value is never
|
|
93
|
+
// returned, even as a fallback. This line can embed the entire request body (system
|
|
94
|
+
// prompt + tool schemas — see the module doc), so a "first message seen" fallback would
|
|
95
|
+
// let unrelated payload content masquerade as the service-failure reason, defeating the
|
|
96
|
+
// anti-masquerade keyword gate this function exists to enforce. Independently recommended
|
|
97
|
+
// as the safe default by three separate reviews (code review, security, and a prior model
|
|
98
|
+
// session) — see ADS-memory/reports/{code-review,security}/*-backend-coverage-push-2026-07-20.md.
|
|
99
|
+
if (SERVICE_ERROR_MESSAGE_RE.test(value))
|
|
100
|
+
return value;
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
function codeFromStatus(statusCode) {
|
|
105
|
+
if (statusCode === 401 || statusCode === 403)
|
|
106
|
+
return 'AGENT_AUTH_REQUIRED';
|
|
107
|
+
if (statusCode === 429)
|
|
108
|
+
return 'RATE_LIMITED';
|
|
109
|
+
if (statusCode >= 500 && statusCode <= 599)
|
|
110
|
+
return 'UPSTREAM_UNAVAILABLE';
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
function defaultMessageForCode(code) {
|
|
114
|
+
switch (code) {
|
|
115
|
+
case 'AGENT_AUTH_REQUIRED':
|
|
116
|
+
return 'OpenCode could not authenticate with the model provider.';
|
|
117
|
+
case 'RATE_LIMITED':
|
|
118
|
+
return 'OpenCode hit a provider usage or rate limit.';
|
|
119
|
+
case 'UPSTREAM_UNAVAILABLE':
|
|
120
|
+
return "OpenCode's model provider is temporarily unavailable.";
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// Classify the latest `service=llm` provider error in an OpenCode log tail.
|
|
124
|
+
// We scope to that single line so the huge request body of *other* lines
|
|
125
|
+
// can't leak in, key the classification on the unambiguous HTTP `statusCode`
|
|
126
|
+
// first, and fall back to keyword matching the extracted message only.
|
|
127
|
+
export function extractOpenCodeServiceFailure(logTail) {
|
|
128
|
+
if (!logTail || !logTail.trim())
|
|
129
|
+
return null;
|
|
130
|
+
const lines = logTail.split(/\r?\n/);
|
|
131
|
+
let line = null;
|
|
132
|
+
for (let i = lines.length - 1; i >= 0; i -= 1) {
|
|
133
|
+
const candidate = lines[i];
|
|
134
|
+
if (candidate.includes('service=llm') && /\bERROR\b/.test(candidate) && candidate.includes('error=')) {
|
|
135
|
+
line = candidate;
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (!line)
|
|
140
|
+
return null;
|
|
141
|
+
const statusMatch = /"statusCode":\s*(\d{3})/.exec(line);
|
|
142
|
+
const statusCode = statusMatch ? Number(statusMatch[1]) : null;
|
|
143
|
+
const message = pickServiceErrorMessage(line);
|
|
144
|
+
let code = statusCode != null ? codeFromStatus(statusCode) : null;
|
|
145
|
+
if (!code && message)
|
|
146
|
+
code = classifyAgentServiceFailure(message);
|
|
147
|
+
if (!code)
|
|
148
|
+
return null;
|
|
149
|
+
return { code, message: message || defaultMessageForCode(code), statusCode };
|
|
150
|
+
}
|
|
151
|
+
// Convenience for a run-close handler / inactivity watchdog: resolve the
|
|
152
|
+
// log dir from the spawned agent's env, read the newest log tail (bound to
|
|
153
|
+
// the current run via `since`), and classify it.
|
|
154
|
+
export function readOpenCodeServiceFailure(env, options = {}) {
|
|
155
|
+
const logDir = resolveOpenCodeLogDir(env);
|
|
156
|
+
if (!logDir)
|
|
157
|
+
return null;
|
|
158
|
+
const tail = readLatestOpenCodeLogTail(logDir, options);
|
|
159
|
+
if (!tail)
|
|
160
|
+
return null;
|
|
161
|
+
return extractOpenCodeServiceFailure(tail);
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=opencode-log.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opencode-log.js","sourceRoot":"","sources":["../src/opencode-log.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,2BAA2B,EAAgC,MAAM,WAAW,CAAC;AAQtF,4EAA4E;AAC5E,6EAA6E;AAC7E,4EAA4E;AAC5E,0CAA0C;AAC1C,MAAM,UAAU,qBAAqB,CAAC,GAAuC;IAC3E,MAAM,GAAG,GAAG,OAAO,GAAG,CAAC,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAClF,MAAM,IAAI,GAAG,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CA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ED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMpD"}
|
package/dist/paths.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module paths
|
|
3
|
+
*
|
|
4
|
+
* Home-relative path expansion for configured env values and file paths.
|
|
5
|
+
* Ported verbatim from OD's `apps/daemon/src/runtimes/core/paths.ts` — no
|
|
6
|
+
* product coupling.
|
|
7
|
+
*/
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { homedir } from 'node:os';
|
|
10
|
+
export function expandConfiguredEnv(configuredEnv) {
|
|
11
|
+
const out = {};
|
|
12
|
+
if (!configuredEnv || typeof configuredEnv !== 'object')
|
|
13
|
+
return out;
|
|
14
|
+
for (const [key, value] of Object.entries(configuredEnv)) {
|
|
15
|
+
if (typeof value !== 'string')
|
|
16
|
+
continue;
|
|
17
|
+
out[key] = expandHomePath(value);
|
|
18
|
+
}
|
|
19
|
+
return out;
|
|
20
|
+
}
|
|
21
|
+
export function expandHomePath(value) {
|
|
22
|
+
if (value === '~')
|
|
23
|
+
return homedir();
|
|
24
|
+
if (value.startsWith('~/') || value.startsWith('~\\')) {
|
|
25
|
+
return path.join(homedir(), value.slice(2));
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,MAAM,UAAU,mBAAmB,CAAC,aAAsB;IACxD,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,IAAI,CAAC,aAAa,IAAI,OAAO,aAAa,KAAK,QAAQ;QAAE,OAAO,GAAG,CAAC;IACpE,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC;QACzD,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,SAAS;QACxC,GAAG,CAAC,GAAG,CAAC,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAa;IAC1C,IAAI,KAAK,KAAK,GAAG;QAAE,OAAO,OAAO,EAAE,CAAC;IACpC,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QACtD,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module pi-models
|
|
3
|
+
*
|
|
4
|
+
* Parses `pi --list-models`'s TSV table (read from stderr) into model
|
|
5
|
+
* options. Ported verbatim (pure string parsing, no transport) from OD's
|
|
6
|
+
* `apps/daemon/src/pi-rpc.ts#parsePiModels` — the surrounding file is the
|
|
7
|
+
* ~700-line pi-rpc stdio transport (out of this task's scope, same
|
|
8
|
+
* reasoning as `acp-model-probe.ts`), but this one function has no
|
|
9
|
+
* dependency on it.
|
|
10
|
+
*/
|
|
11
|
+
import type { RuntimeModelOption } from './types.js';
|
|
12
|
+
export declare function parsePiModels(stdout: unknown): RuntimeModelOption[] | null;
|
|
13
|
+
//# sourceMappingURL=pi-models.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi-models.d.ts","sourceRoot":"","sources":["../src/pi-models.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,wBAAgB,aAAa,CAAC,MAAM,EAAE,OAAO,GAAG,kBAAkB,EAAE,GAAG,IAAI,CAmC1E"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export function parsePiModels(stdout) {
|
|
2
|
+
const lines = String(stdout || '')
|
|
3
|
+
.split('\n')
|
|
4
|
+
.map((l) => l.trim())
|
|
5
|
+
.filter((l) => l.length > 0 && !l.startsWith('#'));
|
|
6
|
+
if (lines.length === 0)
|
|
7
|
+
return null;
|
|
8
|
+
const DEFAULT_MODEL_OPTION = { id: 'default', label: 'Default (CLI config)' };
|
|
9
|
+
// First line is the header; skip it.
|
|
10
|
+
const entries = [DEFAULT_MODEL_OPTION];
|
|
11
|
+
const seen = new Set(['default']);
|
|
12
|
+
for (let i = 1; i < lines.length; i++) {
|
|
13
|
+
// The loop bound (`i < lines.length`) guarantees `lines[i]` is always
|
|
14
|
+
// defined; the non-null assertion documents that runtime invariant
|
|
15
|
+
// instead of a `noUncheckedIndexedAccess`-driven guard that could never
|
|
16
|
+
// actually trigger (same treatment as this function's other port,
|
|
17
|
+
// `agent-protocol/pi-rpc/models.ts` — see source-map.md's "Barrel
|
|
18
|
+
// merge" section for why two copies of this function exist).
|
|
19
|
+
const line = lines[i];
|
|
20
|
+
const parts = line.split(/\s+/);
|
|
21
|
+
if (parts.length < 2)
|
|
22
|
+
continue;
|
|
23
|
+
// `parts.length >= 2` (just checked) guarantees both indices are
|
|
24
|
+
// defined; same non-null-assertion rationale as above.
|
|
25
|
+
const provider = parts[0];
|
|
26
|
+
const modelId = parts[1];
|
|
27
|
+
// Skip duplicates (some providers list the same model under multiple names).
|
|
28
|
+
const fullId = `${provider}/${modelId}`;
|
|
29
|
+
if (seen.has(fullId))
|
|
30
|
+
continue;
|
|
31
|
+
seen.add(fullId);
|
|
32
|
+
entries.push({ id: fullId, label: fullId });
|
|
33
|
+
}
|
|
34
|
+
return entries.length > 1 ? entries : null;
|
|
35
|
+
}
|
|
36
|
+
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O,GAAG,KAAK,CAAC,CAAC,CAAE,CAAC;QAC1B,6EAA6E;QAC7E,MAAM,MAAM,GAAG,GAAG,QAAQ,IAAI,OAAO,EAAE,CAAC;QACxC,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;YAAE,SAAS;QAC/B,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACjB,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module prompt-augmenter
|
|
3
|
+
*
|
|
4
|
+
* Port replacing OD's `runtimes/prompt/chat-prompt-inputs.ts` (design-system
|
|
5
|
+
* selection resolution — `resolveEffectiveDesignSystemSelection`,
|
|
6
|
+
* `designSystemIdFromPluginSnapshot`, `formatDesignFilesWorkspaceHint`,
|
|
7
|
+
* Codex image-generation prompt overrides, comment-attachment rendering,
|
|
8
|
+
* research-command-contract composition — all genuinely OD-product prompt
|
|
9
|
+
* content) and the workspace-context-kind half of OD's
|
|
10
|
+
* `runtimes/chat-run-context.ts` (not present on this branch as a separate
|
|
11
|
+
* file, but the same `'design-system'`-as-a-context-kind concept lives
|
|
12
|
+
* inline in `chat-prompt-inputs.ts`).
|
|
13
|
+
*
|
|
14
|
+
* None of that OD logic is ported — per the task charter, this file defines
|
|
15
|
+
* only the injection seam. The shape below is r1b §1's proposed
|
|
16
|
+
* `PromptAugmenter` signature, used as-is (it matched the real source: the
|
|
17
|
+
* engine composes a base prompt and a generic `RunContextSelection`, then
|
|
18
|
+
* calls out to the host for product-specific augmentation and an optional
|
|
19
|
+
* system-prompt overlay).
|
|
20
|
+
*/
|
|
21
|
+
/** A single item in the run's attached/selected workspace context. `kind` is host-defined — the engine treats it as an opaque string. */
|
|
22
|
+
export interface WorkspaceContextItem {
|
|
23
|
+
id: string;
|
|
24
|
+
kind: string;
|
|
25
|
+
label: string;
|
|
26
|
+
}
|
|
27
|
+
export interface RunContextSelection {
|
|
28
|
+
items: WorkspaceContextItem[];
|
|
29
|
+
}
|
|
30
|
+
export interface PromptAugmenter {
|
|
31
|
+
/**
|
|
32
|
+
* Which workspace-context `kind` strings this consumer recognizes (OD:
|
|
33
|
+
* design-system, design-files, live-artifact, …). The engine itself only
|
|
34
|
+
* knows generic kinds: file, folder, browser, terminal, project,
|
|
35
|
+
* local-code.
|
|
36
|
+
*/
|
|
37
|
+
contextKinds(): readonly string[];
|
|
38
|
+
/**
|
|
39
|
+
* Inject product context blocks (design-system selection, skills, brand,
|
|
40
|
+
* …) into the composed user request. The engine passes the base prompt +
|
|
41
|
+
* selection; the adapter returns the augmented text.
|
|
42
|
+
*/
|
|
43
|
+
augmentUserRequest(input: {
|
|
44
|
+
basePrompt: string;
|
|
45
|
+
selection: RunContextSelection;
|
|
46
|
+
agentId: string;
|
|
47
|
+
hasPriorAssistantTurn: boolean;
|
|
48
|
+
}): Promise<string> | string;
|
|
49
|
+
/**
|
|
50
|
+
* Optional system-prompt overlay. Product-specific discovery /
|
|
51
|
+
* question-form protocols live here, not in the engine.
|
|
52
|
+
*/
|
|
53
|
+
systemOverlay?(input: {
|
|
54
|
+
agentId: string;
|
|
55
|
+
turnIndex: number;
|
|
56
|
+
}): string | null;
|
|
57
|
+
}
|
|
58
|
+
/** Passes the base prompt through unchanged and adds no system overlay. */
|
|
59
|
+
export declare const noopPromptAugmenter: PromptAugmenter;
|
|
60
|
+
//# sourceMappingURL=prompt-augmenter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-augmenter.d.ts","sourceRoot":"","sources":["../src/prompt-augmenter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,yIAAyI;AACzI,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,oBAAoB,EAAE,CAAC;CAC/B;AAED,MAAM,WAAW,eAAe;IAC9B;;;;;OAKG;IACH,YAAY,IAAI,SAAS,MAAM,EAAE,CAAC;IAClC;;;;OAIG;IACH,kBAAkB,CAAC,KAAK,EAAE;QACxB,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,mBAAmB,CAAC;QAC/B,OAAO,EAAE,MAAM,CAAC;QAChB,qBAAqB,EAAE,OAAO,CAAC;KAChC,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;IAC7B;;;OAGG;IACH,aAAa,CAAC,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,GAAG,IAAI,CAAC;CAC9E;AAED,2EAA2E;AAC3E,eAAO,MAAM,mBAAmB,EAAE,eAGjC,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module prompt-augmenter
|
|
3
|
+
*
|
|
4
|
+
* Port replacing OD's `runtimes/prompt/chat-prompt-inputs.ts` (design-system
|
|
5
|
+
* selection resolution — `resolveEffectiveDesignSystemSelection`,
|
|
6
|
+
* `designSystemIdFromPluginSnapshot`, `formatDesignFilesWorkspaceHint`,
|
|
7
|
+
* Codex image-generation prompt overrides, comment-attachment rendering,
|
|
8
|
+
* research-command-contract composition — all genuinely OD-product prompt
|
|
9
|
+
* content) and the workspace-context-kind half of OD's
|
|
10
|
+
* `runtimes/chat-run-context.ts` (not present on this branch as a separate
|
|
11
|
+
* file, but the same `'design-system'`-as-a-context-kind concept lives
|
|
12
|
+
* inline in `chat-prompt-inputs.ts`).
|
|
13
|
+
*
|
|
14
|
+
* None of that OD logic is ported — per the task charter, this file defines
|
|
15
|
+
* only the injection seam. The shape below is r1b §1's proposed
|
|
16
|
+
* `PromptAugmenter` signature, used as-is (it matched the real source: the
|
|
17
|
+
* engine composes a base prompt and a generic `RunContextSelection`, then
|
|
18
|
+
* calls out to the host for product-specific augmentation and an optional
|
|
19
|
+
* system-prompt overlay).
|
|
20
|
+
*/
|
|
21
|
+
/** Passes the base prompt through unchanged and adds no system overlay. */
|
|
22
|
+
export const noopPromptAugmenter = {
|
|
23
|
+
contextKinds: () => ['file', 'folder', 'browser', 'terminal', 'project', 'local-code'],
|
|
24
|
+
augmentUserRequest: ({ basePrompt }) => basePrompt,
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=prompt-augmenter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-augmenter.js","sourceRoot":"","sources":["../src/prompt-augmenter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAuCH,2EAA2E;AAC3E,MAAM,CAAC,MAAM,mBAAmB,GAAoB;IAClD,YAAY,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,CAAC;IACtF,kBAAkB,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,UAAU;CACnD,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module prompt-budget
|
|
3
|
+
*
|
|
4
|
+
* Guards against a composed prompt exceeding an adapter's safe argv size
|
|
5
|
+
* (POSIX per-arg ceilings, and Windows' much tighter CreateProcess
|
|
6
|
+
* command-line cap, both before and after the specific quote-escaping a
|
|
7
|
+
* `.cmd`/`.bat` shim vs. a direct `.exe` spawn applies).
|
|
8
|
+
*
|
|
9
|
+
* Ported from OD's `apps/daemon/src/runtimes/prompt/prompt-budget.ts` with
|
|
10
|
+
* the copy stripped per the task charter: the origin's error messages said
|
|
11
|
+
* "Reduce the selected skills/design-system context…" (OD's own content
|
|
12
|
+
* catalog). Replaced with the generic "selected context" phrasing so the
|
|
13
|
+
* message doesn't assume a design-system-shaped host. Mechanics (byte
|
|
14
|
+
* budgets, Windows quote-doubling math) are unchanged. See `source-map.md`.
|
|
15
|
+
*/
|
|
16
|
+
import type { RuntimeAgentDef, RuntimePromptBudgetError } from './types.js';
|
|
17
|
+
export declare function checkPromptArgvBudget(def: RuntimeAgentDef | null | undefined, composed: unknown, platform?: NodeJS.Platform): RuntimePromptBudgetError | null;
|
|
18
|
+
export declare function checkWindowsCmdShimCommandLineBudget(def: RuntimeAgentDef | null | undefined, resolvedBin: unknown, args: unknown): RuntimePromptBudgetError | null;
|
|
19
|
+
export declare function checkWindowsDirectExeCommandLineBudget(def: RuntimeAgentDef | null | undefined, resolvedBin: unknown, args: unknown): RuntimePromptBudgetError | null;
|
|
20
|
+
//# sourceMappingURL=prompt-budget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-budget.d.ts","sourceRoot":"","sources":["../src/prompt-budget.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAiC5E,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,eAAe,GAAG,IAAI,GAAG,SAAS,EACvC,QAAQ,EAAE,OAAO,EACjB,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAC3C,wBAAwB,GAAG,IAAI,CAMjC;AA2FD,wBAAgB,oCAAoC,CAClD,GAAG,EAAE,eAAe,GAAG,IAAI,GAAG,SAAS,EACvC,WAAW,EAAE,OAAO,EACpB,IAAI,EAAE,OAAO,GACZ,wBAAwB,GAAG,IAAI,CAqBjC;AA+CD,wBAAgB,sCAAsC,CACpD,GAAG,EAAE,eAAe,GAAG,IAAI,GAAG,SAAS,EACvC,WAAW,EAAE,OAAO,EACpB,IAAI,EAAE,OAAO,GACZ,wBAAwB,GAAG,IAAI,CA0BjC"}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
function promptArgvBudgetMessage(def, bytes, limit) {
|
|
2
|
+
if (def.id === 'deepseek') {
|
|
3
|
+
return (`${def.name} currently accepts prompts only as a command-line argument, and this run's composed prompt exceeds the safe size (${bytes} > ${limit} bytes). ` +
|
|
4
|
+
'Reduce the selected context or conversation length, or use DeepSeek through an API/provider model connection for large contexts. Pick a stdin-capable adapter when the prompt must include large local context.');
|
|
5
|
+
}
|
|
6
|
+
return (`${def.name} requires the prompt as a command-line argument and this run's composed prompt exceeds the safe size (${bytes} > ${limit} bytes). ` +
|
|
7
|
+
'Reduce the selected context, shorten the conversation, or pick an adapter with stdin support.');
|
|
8
|
+
}
|
|
9
|
+
// `maxPromptArgBytes` is sized for Windows' ~32 KB CreateProcess
|
|
10
|
+
// command-line limit. On POSIX the per-arg ceiling is far higher — Linux's
|
|
11
|
+
// MAX_ARG_STRLEN is 128 KB and macOS's ARG_MAX is 256 KB (total argv+env)
|
|
12
|
+
// — and the *real* Windows command-line cap is guarded precisely
|
|
13
|
+
// post-buildArgs by checkWindowsCmdShim/DirectExeCommandLineBudget. So
|
|
14
|
+
// applying the conservative Windows byte budget unconditionally on
|
|
15
|
+
// macOS/Linux false-positives on normal-sized prompts with a confusing
|
|
16
|
+
// "prompt too long". On POSIX we keep a much larger guard — headroom
|
|
17
|
+
// under Linux's 128 KB per-arg ceiling — purely so a runaway prompt still
|
|
18
|
+
// fails fast with the actionable message instead of a generic spawn
|
|
19
|
+
// E2BIG.
|
|
20
|
+
const POSIX_ARGV_PROMPT_BUDGET = 100_000;
|
|
21
|
+
function resolveArgvPromptBudget(maxPromptArgBytes, platform) {
|
|
22
|
+
if (platform === 'win32')
|
|
23
|
+
return maxPromptArgBytes;
|
|
24
|
+
return Math.max(maxPromptArgBytes, POSIX_ARGV_PROMPT_BUDGET);
|
|
25
|
+
}
|
|
26
|
+
export function checkPromptArgvBudget(def, composed, platform = process.platform) {
|
|
27
|
+
if (!def || typeof def.maxPromptArgBytes !== 'number')
|
|
28
|
+
return null;
|
|
29
|
+
const bytes = Buffer.byteLength(typeof composed === 'string' ? composed : '', 'utf8');
|
|
30
|
+
const limit = resolveArgvPromptBudget(def.maxPromptArgBytes, platform);
|
|
31
|
+
if (bytes <= limit)
|
|
32
|
+
return null;
|
|
33
|
+
return { code: 'AGENT_PROMPT_TOO_LARGE', message: promptArgvBudgetMessage(def, bytes, limit), bytes, limit };
|
|
34
|
+
}
|
|
35
|
+
// Mirror of `@jini-ai/platform`'s internal `quoteWindowsCommandArg`, kept
|
|
36
|
+
// local so `checkWindowsCmdShimCommandLineBudget` can run on macOS/Linux
|
|
37
|
+
// against a fake `.cmd` path in tests without forking on `process.platform`.
|
|
38
|
+
// Must stay byte-for-byte identical to the platform copy — the helper's
|
|
39
|
+
// whole point is to compute the exact `cmd.exe /d /s /c "<inner>"` line
|
|
40
|
+
// the spawn path will produce on Windows. The `%` → `"^%"` substitution
|
|
41
|
+
// neutralizes cmd.exe's percent-expansion for prompts that ride argv
|
|
42
|
+
// (DeepSeek TUI today): `%name%` pairs would otherwise be expanded from
|
|
43
|
+
// the host environment before the child reads them, leaking secrets like
|
|
44
|
+
// `%DEEPSEEK_API_KEY%` whenever the prompt mentions an env-var name.
|
|
45
|
+
function quoteForWindowsCmdShim(value) {
|
|
46
|
+
const str = String(value ?? '');
|
|
47
|
+
if (!/[\s"&<>|^%]/.test(str))
|
|
48
|
+
return str;
|
|
49
|
+
const escaped = str.replace(/"/g, '""').replace(/%/g, '"^%"');
|
|
50
|
+
return `"${escaped}"`;
|
|
51
|
+
}
|
|
52
|
+
// Mirror of libuv's `quote_cmd_arg` (process-stdio.c), the exact rule Node
|
|
53
|
+
// uses on Windows when it composes a CreateProcess command line for a
|
|
54
|
+
// direct executable spawn (not a `.cmd` / `.bat` shim, which goes through
|
|
55
|
+
// `quoteForWindowsCmdShim` above). Each embedded `"` becomes `\"`, every
|
|
56
|
+
// backslash that ends up adjacent to a quote (or to the closing wrap
|
|
57
|
+
// quote) gets doubled, and an arg with whitespace or a quote is wrapped in
|
|
58
|
+
// outer `"..."`. Kept local so the budget check works on macOS/Linux test
|
|
59
|
+
// hosts against a fake `C:\…\foo.exe` path.
|
|
60
|
+
function quoteForWindowsDirectExe(value) {
|
|
61
|
+
const str = String(value ?? '');
|
|
62
|
+
// libuv emits a literal `""` for an empty argv entry so it survives
|
|
63
|
+
// CommandLineToArgvW round-tripping; mirror that.
|
|
64
|
+
if (str.length === 0)
|
|
65
|
+
return '""';
|
|
66
|
+
// Fast path: no whitespace and no quote — pass through unchanged. This
|
|
67
|
+
// matches libuv's `wcspbrk(source, L" \t\"")` early return.
|
|
68
|
+
if (!/[\s"]/.test(str))
|
|
69
|
+
return str;
|
|
70
|
+
// No quote, no backslash: simple wrap, no per-char escaping needed.
|
|
71
|
+
if (!/[\\"]/.test(str))
|
|
72
|
+
return `"${str}"`;
|
|
73
|
+
// Slow path: walk the string, counting consecutive backslashes so we
|
|
74
|
+
// can double them whenever they precede a `"` or the closing wrap
|
|
75
|
+
// quote. Following the documented Windows convention:
|
|
76
|
+
// - 2n backslashes + `"` → emit `\\` × 2n + `\"`
|
|
77
|
+
// - 2n+1 backslashes + `"` → emit `\\` × (2n+1) + `\"`
|
|
78
|
+
// - n backslashes not before `"` → emit `\\` × n unchanged
|
|
79
|
+
// - trailing backslashes (before the closing wrap quote) → doubled
|
|
80
|
+
let result = '"';
|
|
81
|
+
let backslashes = 0;
|
|
82
|
+
for (let i = 0; i < str.length; i++) {
|
|
83
|
+
const ch = str[i];
|
|
84
|
+
if (ch === '\\') {
|
|
85
|
+
backslashes++;
|
|
86
|
+
}
|
|
87
|
+
else if (ch === '"') {
|
|
88
|
+
result += '\\'.repeat(2 * backslashes + 1) + '"';
|
|
89
|
+
backslashes = 0;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
result += '\\'.repeat(backslashes) + ch;
|
|
93
|
+
backslashes = 0;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
result += '\\'.repeat(2 * backslashes) + '"';
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
// Windows' CreateProcess caps `lpCommandLine` at 32_767 chars. Going
|
|
100
|
+
// through a `.cmd` / `.bat` shim adds a `cmd.exe /d /s /c "<inner>"`
|
|
101
|
+
// wrapper, and `quoteForWindowsCmdShim` doubles every embedded `"` plus
|
|
102
|
+
// wraps any whitespace/special-char arg in outer quotes — so a prompt
|
|
103
|
+
// well under `maxPromptArgBytes` can still expand past the kernel cap
|
|
104
|
+
// once it's run through the shim. Leave headroom for any per-CLI flag the
|
|
105
|
+
// adapter might tack on at exec time and for cmd.exe's own framing.
|
|
106
|
+
const WINDOWS_CREATE_PROCESS_LIMIT = 32_767;
|
|
107
|
+
const WINDOWS_CREATE_PROCESS_HEADROOM = 256;
|
|
108
|
+
// Post-buildArgs guard for argv-bound adapters whose binary resolves to a
|
|
109
|
+
// Windows `.cmd` / `.bat` shim. Computes the exact command line shape
|
|
110
|
+
// `@jini-ai/platform`'s `createCommandInvocation` hands to `spawn` —
|
|
111
|
+
// `cmd.exe /d /s /c "<quoted command + quoted args>"` — and refuses the
|
|
112
|
+
// run when that line would exceed the CreateProcess limit (less a small
|
|
113
|
+
// headroom). Returns the same `AGENT_PROMPT_TOO_LARGE` shape as
|
|
114
|
+
// `checkPromptArgvBudget` so an error-response path doesn't have to
|
|
115
|
+
// special-case it.
|
|
116
|
+
//
|
|
117
|
+
// No-op when:
|
|
118
|
+
// - the adapter doesn't declare `maxPromptArgBytes` (stdin adapters
|
|
119
|
+
// never go through this path);
|
|
120
|
+
// - the resolved binary isn't a `.cmd` / `.bat` (POSIX hosts and direct
|
|
121
|
+
// `.exe` resolutions on Windows skip the cmd.exe wrap);
|
|
122
|
+
// - the assembled line fits comfortably under the kernel cap.
|
|
123
|
+
//
|
|
124
|
+
// Pure: takes `resolvedBin` explicitly so a test on macOS can pass a fake
|
|
125
|
+
// `C:\\…\\deepseek.cmd` path and exercise the same math the daemon would
|
|
126
|
+
// run on Windows.
|
|
127
|
+
export function checkWindowsCmdShimCommandLineBudget(def, resolvedBin, args) {
|
|
128
|
+
if (!def || typeof def.maxPromptArgBytes !== 'number')
|
|
129
|
+
return null;
|
|
130
|
+
if (typeof resolvedBin !== 'string' || !/\.(bat|cmd)$/i.test(resolvedBin))
|
|
131
|
+
return null;
|
|
132
|
+
const argList = Array.isArray(args) ? args : [];
|
|
133
|
+
const inner = [resolvedBin, ...argList].map(quoteForWindowsCmdShim).join(' ');
|
|
134
|
+
// `cmd.exe /d /s /c "<inner>"` — same shape `@jini-ai/platform`'s
|
|
135
|
+
// `createCommandInvocation` builds; the leading 'cmd.exe ' + '/d /s /c '
|
|
136
|
+
// framing plus the two outer quote chars rounds out the full command
|
|
137
|
+
// line.
|
|
138
|
+
const commandLineLength = 'cmd.exe /d /s /c '.length + inner.length + 2;
|
|
139
|
+
const safeLimit = WINDOWS_CREATE_PROCESS_LIMIT - WINDOWS_CREATE_PROCESS_HEADROOM;
|
|
140
|
+
if (commandLineLength <= safeLimit)
|
|
141
|
+
return null;
|
|
142
|
+
return {
|
|
143
|
+
code: 'AGENT_PROMPT_TOO_LARGE',
|
|
144
|
+
message: `${def.name} on Windows runs through a .cmd shim and this run's prompt would expand past the CreateProcess command-line limit ` +
|
|
145
|
+
`after cmd.exe quote-doubling (${commandLineLength} > ${safeLimit} chars). ` +
|
|
146
|
+
'Reduce quote-heavy content in the selected context, shorten the conversation, or pick an adapter with stdin support.',
|
|
147
|
+
commandLineLength,
|
|
148
|
+
limit: safeLimit,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
// Heuristic: does `resolvedBin` look like a Windows path? Used by the
|
|
152
|
+
// direct-exe guard so a test on a POSIX host can drive a fake
|
|
153
|
+
// `C:\…\foo.exe` path through the same math the daemon would run on
|
|
154
|
+
// Windows, while still skipping POSIX-shaped paths (which never go
|
|
155
|
+
// through CreateProcess).
|
|
156
|
+
//
|
|
157
|
+
// Takes `p: string`, not `unknown`: this function's only real call site
|
|
158
|
+
// (`checkWindowsDirectExeCommandLineBudget`, below) already runs
|
|
159
|
+
// `if (typeof resolvedBin !== 'string' || resolvedBin.length === 0) return
|
|
160
|
+
// null;` before ever calling in, so `p` is always a non-empty string here —
|
|
161
|
+
// a runtime `typeof`/`.length` guard was dead code for the one real caller.
|
|
162
|
+
// Narrowed the parameter type to remove the branch instead of padding a
|
|
163
|
+
// test around unreachable data.
|
|
164
|
+
function looksLikeWindowsPath(p) {
|
|
165
|
+
// Drive-letter (`C:\…`, `C:/…`) or UNC (`\\server\share\…`).
|
|
166
|
+
return /^[a-zA-Z]:[\\/]/.test(p) || p.startsWith('\\\\');
|
|
167
|
+
}
|
|
168
|
+
// Companion to `checkWindowsCmdShimCommandLineBudget` for argv-bound
|
|
169
|
+
// adapters whose binary resolves directly to a Windows executable. Node's
|
|
170
|
+
// `createCommandInvocation` does *not* wrap the call in
|
|
171
|
+
// `cmd.exe /d /s /c "<inner>"` for those — but Node/libuv still composes a
|
|
172
|
+
// CreateProcess `lpCommandLine` by walking each argv entry through
|
|
173
|
+
// `quote_cmd_arg`, which doubles backslashes adjacent to quotes and
|
|
174
|
+
// escapes every embedded `"` as `\"`. A quote-heavy prompt that fits under
|
|
175
|
+
// the raw `maxPromptArgBytes` budget can therefore still expand past the
|
|
176
|
+
// kernel's 32_767-char `lpCommandLine` cap on a direct `.exe` spawn,
|
|
177
|
+
// surfacing as a generic `spawn ENAMETOOLONG` instead of the
|
|
178
|
+
// adapter-named `AGENT_PROMPT_TOO_LARGE` the budget guard exists to emit.
|
|
179
|
+
// Returns the same error shape as the cmd-shim guard so an error-response
|
|
180
|
+
// path doesn't have to special-case it.
|
|
181
|
+
//
|
|
182
|
+
// No-op when:
|
|
183
|
+
// - the adapter doesn't declare `maxPromptArgBytes` (stdin adapters
|
|
184
|
+
// never go through this path);
|
|
185
|
+
// - the resolved binary is a `.cmd` / `.bat` shim — that's handled by
|
|
186
|
+
// `checkWindowsCmdShimCommandLineBudget` so we don't double-emit;
|
|
187
|
+
// - the resolved binary is not a Windows path (no CreateProcess
|
|
188
|
+
// command-line shape to budget);
|
|
189
|
+
// - the assembled command line fits under the safe limit.
|
|
190
|
+
//
|
|
191
|
+
// Pure: takes `resolvedBin` and `args` explicitly so a test on macOS can
|
|
192
|
+
// pass a fake `C:\…\deepseek.exe` and exercise the same math the daemon
|
|
193
|
+
// would run on Windows. The libuv quoting math lives in
|
|
194
|
+
// `quoteForWindowsDirectExe` above.
|
|
195
|
+
export function checkWindowsDirectExeCommandLineBudget(def, resolvedBin, args) {
|
|
196
|
+
if (!def || typeof def.maxPromptArgBytes !== 'number')
|
|
197
|
+
return null;
|
|
198
|
+
if (typeof resolvedBin !== 'string' || resolvedBin.length === 0)
|
|
199
|
+
return null;
|
|
200
|
+
// The cmd-shim guard owns `.bat` / `.cmd`; skip those here so a single
|
|
201
|
+
// oversized prompt doesn't trip both guards.
|
|
202
|
+
if (/\.(bat|cmd)$/i.test(resolvedBin))
|
|
203
|
+
return null;
|
|
204
|
+
// Only fire for Windows-shaped resolved binaries. On POSIX-shaped
|
|
205
|
+
// paths, `execvp` accepts each argv entry as a separate buffer —
|
|
206
|
+
// there's no command-line concatenation step that could expand past a
|
|
207
|
+
// kernel cap, so we have nothing to guard.
|
|
208
|
+
if (!looksLikeWindowsPath(resolvedBin))
|
|
209
|
+
return null;
|
|
210
|
+
const argList = Array.isArray(args) ? args : [];
|
|
211
|
+
// `[command, ...args].map(quote).join(' ')` is the exact shape libuv
|
|
212
|
+
// builds before handing it to CreateProcess.
|
|
213
|
+
const commandLineLength = [resolvedBin, ...argList].map(quoteForWindowsDirectExe).join(' ').length;
|
|
214
|
+
const safeLimit = WINDOWS_CREATE_PROCESS_LIMIT - WINDOWS_CREATE_PROCESS_HEADROOM;
|
|
215
|
+
if (commandLineLength <= safeLimit)
|
|
216
|
+
return null;
|
|
217
|
+
return {
|
|
218
|
+
code: 'AGENT_PROMPT_TOO_LARGE',
|
|
219
|
+
message: `${def.name} on Windows builds a CreateProcess command line and this run's prompt would expand past the limit ` +
|
|
220
|
+
`after libuv quote-escaping (${commandLineLength} > ${safeLimit} chars). ` +
|
|
221
|
+
'Reduce quote-heavy content in the selected context, shorten the conversation, or pick an adapter with stdin support.',
|
|
222
|
+
commandLineLength,
|
|
223
|
+
limit: safeLimit,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
//# sourceMappingURL=prompt-budget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-budget.js","sourceRoot":"","sources":["../src/prompt-budget.ts"],"names":[],"mappings":"AAiBA,SAAS,uBAAuB,CAAC,GAAoB,EAAE,KAAa,EAAE,KAAa;IACjF,IAAI,GAAG,CAAC,EAAE,KAAK,UAAU,EAAE,CAAC;QAC1B,OAAO,CACL,GAAG,GAAG,CAAC,IAAI,qHAAqH,KAAK,MAAM,KAAK,WAAW;YAC3J,iNAAiN,CAClN,CAAC;IACJ,CAAC;IACD,OAAO,CACL,GAAG,GAAG,CAAC,IAAI,yGAAyG,KAAK,MAAM,KAAK,WAAW;QAC/I,+FAA+F,CAChG,CAAC;AACJ,CAAC;AAED,iEAAiE;AACjE,2EAA2E;AAC3E,0EAA0E;AAC1E,iEAAiE;AACjE,uEAAuE;AACvE,mEAAmE;AACnE,uEAAuE;AACvE,qEAAqE;AACrE,0EAA0E;AAC1E,oEAAoE;AACpE,SAAS;AACT,MAAM,wBAAwB,GAAG,OAAO,CAAC;AAEzC,SAAS,uBAAuB,CAAC,iBAAyB,EAAE,QAAyB;IACnF,IAAI,QAAQ,KAAK,OAAO;QAAE,OAAO,iBAAiB,CAAC;IACnD,OAAO,IAAI,CAAC,GAAG,CAAC,iBAAiB,EAAE,wBAAwB,CAAC,CAAC;AAC/D,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,GAAuC,EACvC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