@armadra/agent 0.0.0-stage → 0.2.1
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/CHANGELOG.md +22 -0
- package/LICENSE +21 -0
- package/README.md +426 -2
- package/dist/agent/agent.d.ts +56 -0
- package/dist/agent/agent.js +129 -0
- package/dist/agent/loop.d.ts +51 -0
- package/dist/agent/loop.js +158 -0
- package/dist/agent/queue.d.ts +25 -0
- package/dist/agent/queue.js +55 -0
- package/dist/agent/retry.d.ts +22 -0
- package/dist/agent/retry.js +92 -0
- package/dist/agent/schema.d.ts +27 -0
- package/dist/agent/schema.js +186 -0
- package/dist/agent/session-cache.d.ts +100 -0
- package/dist/agent/session-cache.js +511 -0
- package/dist/agent/session-compaction.d.ts +49 -0
- package/dist/agent/session-compaction.js +251 -0
- package/dist/agent/session-core.d.ts +103 -0
- package/dist/agent/session-core.js +7 -0
- package/dist/agent/session-run.d.ts +55 -0
- package/dist/agent/session-run.js +246 -0
- package/dist/agent/session-state.d.ts +39 -0
- package/dist/agent/session-state.js +118 -0
- package/dist/agent/session-subagent.d.ts +54 -0
- package/dist/agent/session-subagent.js +157 -0
- package/dist/agent/session-sync.d.ts +20 -0
- package/dist/agent/session-sync.js +104 -0
- package/dist/agent/session-tools.d.ts +24 -0
- package/dist/agent/session-tools.js +277 -0
- package/dist/agent/session.d.ts +117 -0
- package/dist/agent/session.js +484 -0
- package/dist/agent/system-prompt.d.ts +49 -0
- package/dist/agent/system-prompt.js +121 -0
- package/dist/agent/tool-runner.d.ts +64 -0
- package/dist/agent/tool-runner.js +309 -0
- package/dist/agent/transform.d.ts +26 -0
- package/dist/agent/transform.js +171 -0
- package/dist/agent/types.d.ts +378 -0
- package/dist/agent/types.js +21 -0
- package/dist/ai/apis/anthropic-messages.d.ts +26 -0
- package/dist/ai/apis/anthropic-messages.js +214 -0
- package/dist/ai/apis/anthropic-request.d.ts +42 -0
- package/dist/ai/apis/anthropic-request.js +282 -0
- package/dist/ai/apis/api.d.ts +28 -0
- package/dist/ai/apis/api.js +102 -0
- package/dist/ai/apis/cache-params.d.ts +48 -0
- package/dist/ai/apis/cache-params.js +163 -0
- package/dist/ai/apis/google-generative-ai.d.ts +32 -0
- package/dist/ai/apis/google-generative-ai.js +249 -0
- package/dist/ai/apis/google-request.d.ts +40 -0
- package/dist/ai/apis/google-request.js +255 -0
- package/dist/ai/apis/openai-compat.d.ts +35 -0
- package/dist/ai/apis/openai-compat.js +142 -0
- package/dist/ai/apis/openai-completions.d.ts +28 -0
- package/dist/ai/apis/openai-completions.js +246 -0
- package/dist/ai/apis/openai-request.d.ts +35 -0
- package/dist/ai/apis/openai-request.js +303 -0
- package/dist/ai/apis/openai-responses-request.d.ts +52 -0
- package/dist/ai/apis/openai-responses-request.js +266 -0
- package/dist/ai/apis/openai-responses.d.ts +28 -0
- package/dist/ai/apis/openai-responses.js +303 -0
- package/dist/ai/apis/shared.d.ts +56 -0
- package/dist/ai/apis/shared.js +179 -0
- package/dist/ai/cache/economics.d.ts +24 -0
- package/dist/ai/cache/economics.js +69 -0
- package/dist/ai/cache/fingerprint.d.ts +17 -0
- package/dist/ai/cache/fingerprint.js +39 -0
- package/dist/ai/cache/miss.d.ts +49 -0
- package/dist/ai/cache/miss.js +96 -0
- package/dist/ai/cache/reporting.d.ts +39 -0
- package/dist/ai/cache/reporting.js +102 -0
- package/dist/ai/cache/types.d.ts +94 -0
- package/dist/ai/cache/types.js +19 -0
- package/dist/ai/cache/warmer.d.ts +94 -0
- package/dist/ai/cache/warmer.js +224 -0
- package/dist/ai/context.d.ts +35 -0
- package/dist/ai/context.js +114 -0
- package/dist/ai/cost.d.ts +21 -0
- package/dist/ai/cost.js +60 -0
- package/dist/ai/event-stream.d.ts +33 -0
- package/dist/ai/event-stream.js +101 -0
- package/dist/ai/fake/fake-provider.d.ts +68 -0
- package/dist/ai/fake/fake-provider.js +278 -0
- package/dist/ai/fake/fake-script.d.ts +69 -0
- package/dist/ai/fake/fake-script.js +142 -0
- package/dist/ai/http.d.ts +54 -0
- package/dist/ai/http.js +212 -0
- package/dist/ai/json-partial.d.ts +17 -0
- package/dist/ai/json-partial.js +243 -0
- package/dist/ai/overflow.d.ts +22 -0
- package/dist/ai/overflow.js +61 -0
- package/dist/ai/providers/auth.d.ts +71 -0
- package/dist/ai/providers/auth.js +202 -0
- package/dist/ai/providers/builtin.d.ts +23 -0
- package/dist/ai/providers/builtin.js +148 -0
- package/dist/ai/providers/catalog-data.d.ts +5 -0
- package/dist/ai/providers/catalog-data.js +19 -0
- package/dist/ai/providers/catalog.d.ts +28 -0
- package/dist/ai/providers/catalog.js +166 -0
- package/dist/ai/providers/registry.d.ts +83 -0
- package/dist/ai/providers/registry.js +305 -0
- package/dist/ai/sse.d.ts +32 -0
- package/dist/ai/sse.js +140 -0
- package/dist/ai/thinking.d.ts +42 -0
- package/dist/ai/thinking.js +101 -0
- package/dist/ai/types.d.ts +428 -0
- package/dist/ai/types.js +19 -0
- package/dist/bundle/ama-sandbox.cjs +324 -0
- package/dist/bundle/ama.cjs +25770 -0
- package/dist/bundle.d.ts +9 -0
- package/dist/bundle.js +15 -0
- package/dist/cli/args.d.ts +82 -0
- package/dist/cli/args.js +381 -0
- package/dist/cli/bootstrap.d.ts +18 -0
- package/dist/cli/bootstrap.js +398 -0
- package/dist/cli/compose-providers.d.ts +37 -0
- package/dist/cli/compose-providers.js +104 -0
- package/dist/cli/compose-session.d.ts +69 -0
- package/dist/cli/compose-session.js +370 -0
- package/dist/cli/compose-store.d.ts +24 -0
- package/dist/cli/compose-store.js +125 -0
- package/dist/cli/compose.d.ts +106 -0
- package/dist/cli/compose.js +206 -0
- package/dist/cli/default-model.d.ts +16 -0
- package/dist/cli/default-model.js +24 -0
- package/dist/cli/deps.d.ts +205 -0
- package/dist/cli/deps.js +12 -0
- package/dist/cli/exit-codes.d.ts +29 -0
- package/dist/cli/exit-codes.js +40 -0
- package/dist/cli/main.d.ts +26 -0
- package/dist/cli/main.js +165 -0
- package/dist/cli/runtime.d.ts +90 -0
- package/dist/cli/runtime.js +8 -0
- package/dist/cli/startup-screen.d.ts +15 -0
- package/dist/cli/startup-screen.js +56 -0
- package/dist/cli/startup-steps.d.ts +35 -0
- package/dist/cli/startup-steps.js +197 -0
- package/dist/cli/subcommands/auth.d.ts +12 -0
- package/dist/cli/subcommands/auth.js +91 -0
- package/dist/cli/subcommands/config.d.ts +44 -0
- package/dist/cli/subcommands/config.js +201 -0
- package/dist/cli/subcommands/context.d.ts +21 -0
- package/dist/cli/subcommands/context.js +41 -0
- package/dist/cli/subcommands/doctor.d.ts +11 -0
- package/dist/cli/subcommands/doctor.js +246 -0
- package/dist/cli/subcommands/models-cache-probe.d.ts +34 -0
- package/dist/cli/subcommands/models-cache-probe.js +190 -0
- package/dist/cli/subcommands/models-discover.d.ts +40 -0
- package/dist/cli/subcommands/models-discover.js +204 -0
- package/dist/cli/subcommands/models.d.ts +40 -0
- package/dist/cli/subcommands/models.js +144 -0
- package/dist/cli/subcommands/sessions.d.ts +11 -0
- package/dist/cli/subcommands/sessions.js +100 -0
- package/dist/codemode/capability.d.ts +37 -0
- package/dist/codemode/capability.js +55 -0
- package/dist/codemode/declarations.d.ts +44 -0
- package/dist/codemode/declarations.js +111 -0
- package/dist/codemode/host-side.d.ts +59 -0
- package/dist/codemode/host-side.js +253 -0
- package/dist/codemode/modes.d.ts +23 -0
- package/dist/codemode/modes.js +40 -0
- package/dist/codemode/protocol.d.ts +91 -0
- package/dist/codemode/protocol.js +114 -0
- package/dist/codemode/sandbox-entry.d.ts +25 -0
- package/dist/codemode/sandbox-entry.js +323 -0
- package/dist/codemode/store.d.ts +26 -0
- package/dist/codemode/store.js +53 -0
- package/dist/codemode/tool.d.ts +105 -0
- package/dist/codemode/tool.js +283 -0
- package/dist/compaction/branch-summary.d.ts +30 -0
- package/dist/compaction/branch-summary.js +79 -0
- package/dist/compaction/breaker.d.ts +32 -0
- package/dist/compaction/breaker.js +65 -0
- package/dist/compaction/cut-point.d.ts +23 -0
- package/dist/compaction/cut-point.js +70 -0
- package/dist/compaction/estimate.d.ts +30 -0
- package/dist/compaction/estimate.js +114 -0
- package/dist/compaction/prune-tier.d.ts +31 -0
- package/dist/compaction/prune-tier.js +83 -0
- package/dist/compaction/serialize.d.ts +20 -0
- package/dist/compaction/serialize.js +115 -0
- package/dist/compaction/summarize-tier.d.ts +111 -0
- package/dist/compaction/summarize-tier.js +305 -0
- package/dist/config/auth-file.d.ts +39 -0
- package/dist/config/auth-file.js +92 -0
- package/dist/config/context-files.d.ts +30 -0
- package/dist/config/context-files.js +77 -0
- package/dist/config/load.d.ts +45 -0
- package/dist/config/load.js +97 -0
- package/dist/config/merge.d.ts +73 -0
- package/dist/config/merge.js +248 -0
- package/dist/config/paths.d.ts +38 -0
- package/dist/config/paths.js +108 -0
- package/dist/config/profile.d.ts +27 -0
- package/dist/config/profile.js +65 -0
- package/dist/config/schema.d.ts +34 -0
- package/dist/config/schema.js +413 -0
- package/dist/config/trust.d.ts +42 -0
- package/dist/config/trust.js +122 -0
- package/dist/config/types.d.ts +172 -0
- package/dist/config/types.js +27 -0
- package/dist/config/write.d.ts +10 -0
- package/dist/config/write.js +25 -0
- package/dist/errors.d.ts +28 -0
- package/dist/errors.js +30 -0
- package/dist/hooks/config.d.ts +49 -0
- package/dist/hooks/config.js +102 -0
- package/dist/hooks/dispatcher.d.ts +41 -0
- package/dist/hooks/dispatcher.js +104 -0
- package/dist/hooks/matcher.d.ts +22 -0
- package/dist/hooks/matcher.js +108 -0
- package/dist/hooks/protocol.d.ts +33 -0
- package/dist/hooks/protocol.js +240 -0
- package/dist/hooks/runner.d.ts +30 -0
- package/dist/hooks/runner.js +143 -0
- package/dist/hooks/types.d.ts +147 -0
- package/dist/hooks/types.js +20 -0
- package/dist/host/api-impl.d.ts +75 -0
- package/dist/host/api-impl.js +173 -0
- package/dist/host/loader.d.ts +31 -0
- package/dist/host/loader.js +147 -0
- package/dist/host/types.d.ts +169 -0
- package/dist/host/types.js +14 -0
- package/dist/host.d.ts +5 -0
- package/dist/host.js +4 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.js +28 -0
- package/dist/modes/commands-core.d.ts +44 -0
- package/dist/modes/commands-core.js +171 -0
- package/dist/modes/interactive/approval-dialog.d.ts +48 -0
- package/dist/modes/interactive/approval-dialog.js +202 -0
- package/dist/modes/interactive/commands.d.ts +41 -0
- package/dist/modes/interactive/commands.js +202 -0
- package/dist/modes/interactive/completion.d.ts +53 -0
- package/dist/modes/interactive/completion.js +157 -0
- package/dist/modes/interactive/interactive-mode.d.ts +46 -0
- package/dist/modes/interactive/interactive-mode.js +487 -0
- package/dist/modes/interactive/key-dispatch.d.ts +29 -0
- package/dist/modes/interactive/key-dispatch.js +107 -0
- package/dist/modes/interactive/line/line-editor.d.ts +50 -0
- package/dist/modes/interactive/line/line-editor.js +232 -0
- package/dist/modes/interactive/line/line-mode.d.ts +20 -0
- package/dist/modes/interactive/line/line-mode.js +216 -0
- package/dist/modes/interactive/line/line-render.d.ts +35 -0
- package/dist/modes/interactive/line/line-render.js +171 -0
- package/dist/modes/interactive/line/paste-state.d.ts +26 -0
- package/dist/modes/interactive/line/paste-state.js +72 -0
- package/dist/modes/interactive/message-view.d.ts +77 -0
- package/dist/modes/interactive/message-view.js +269 -0
- package/dist/modes/interactive/pickers.d.ts +42 -0
- package/dist/modes/interactive/pickers.js +115 -0
- package/dist/modes/interactive/startup-ui.d.ts +28 -0
- package/dist/modes/interactive/startup-ui.js +238 -0
- package/dist/modes/interactive/status-bar.d.ts +48 -0
- package/dist/modes/interactive/status-bar.js +139 -0
- package/dist/modes/interactive/tool-view.d.ts +95 -0
- package/dist/modes/interactive/tool-view.js +344 -0
- package/dist/modes/print/json-event.d.ts +15 -0
- package/dist/modes/print/json-event.js +39 -0
- package/dist/modes/print/print-mode.d.ts +15 -0
- package/dist/modes/print/print-mode.js +96 -0
- package/dist/modes/rpc/commands.d.ts +40 -0
- package/dist/modes/rpc/commands.js +258 -0
- package/dist/modes/rpc/jsonl.d.ts +16 -0
- package/dist/modes/rpc/jsonl.js +55 -0
- package/dist/modes/rpc/rpc-mode.d.ts +22 -0
- package/dist/modes/rpc/rpc-mode.js +153 -0
- package/dist/modes/session-report.d.ts +55 -0
- package/dist/modes/session-report.js +278 -0
- package/dist/modes/shared.d.ts +13 -0
- package/dist/modes/shared.js +52 -0
- package/dist/modes/startup-ui-text.d.ts +16 -0
- package/dist/modes/startup-ui-text.js +103 -0
- package/dist/permissions/broker.d.ts +47 -0
- package/dist/permissions/broker.js +107 -0
- package/dist/permissions/dangerous.d.ts +47 -0
- package/dist/permissions/dangerous.js +370 -0
- package/dist/permissions/pipeline.d.ts +51 -0
- package/dist/permissions/pipeline.js +181 -0
- package/dist/permissions/preview.d.ts +43 -0
- package/dist/permissions/preview.js +463 -0
- package/dist/permissions/rules.d.ts +58 -0
- package/dist/permissions/rules.js +249 -0
- package/dist/permissions/types.d.ts +100 -0
- package/dist/permissions/types.js +18 -0
- package/dist/rpc.d.ts +171 -0
- package/dist/rpc.js +13 -0
- package/dist/sdk.d.ts +98 -0
- package/dist/sdk.js +195 -0
- package/dist/session/manager.d.ts +70 -0
- package/dist/session/manager.js +278 -0
- package/dist/session/migrate.d.ts +19 -0
- package/dist/session/migrate.js +53 -0
- package/dist/session/projection.d.ts +50 -0
- package/dist/session/projection.js +180 -0
- package/dist/session/store.d.ts +47 -0
- package/dist/session/store.js +210 -0
- package/dist/session/tree.d.ts +21 -0
- package/dist/session/tree.js +88 -0
- package/dist/session/types.d.ts +199 -0
- package/dist/session/types.js +18 -0
- package/dist/skills/discover.d.ts +60 -0
- package/dist/skills/discover.js +160 -0
- package/dist/skills/expand.d.ts +35 -0
- package/dist/skills/expand.js +46 -0
- package/dist/skills/frontmatter.d.ts +27 -0
- package/dist/skills/frontmatter.js +157 -0
- package/dist/skills/index-prompt.d.ts +13 -0
- package/dist/skills/index-prompt.js +42 -0
- package/dist/skills/templates.d.ts +52 -0
- package/dist/skills/templates.js +177 -0
- package/dist/tools/bash.d.ts +49 -0
- package/dist/tools/bash.js +222 -0
- package/dist/tools/edit-fuzzy.d.ts +36 -0
- package/dist/tools/edit-fuzzy.js +129 -0
- package/dist/tools/edit.d.ts +38 -0
- package/dist/tools/edit.js +241 -0
- package/dist/tools/file-mutex.d.ts +8 -0
- package/dist/tools/file-mutex.js +29 -0
- package/dist/tools/glob.d.ts +44 -0
- package/dist/tools/glob.js +217 -0
- package/dist/tools/grep.d.ts +39 -0
- package/dist/tools/grep.js +179 -0
- package/dist/tools/ignore.d.ts +40 -0
- package/dist/tools/ignore.js +174 -0
- package/dist/tools/ls.d.ts +21 -0
- package/dist/tools/ls.js +96 -0
- package/dist/tools/output-accumulator.d.ts +48 -0
- package/dist/tools/output-accumulator.js +106 -0
- package/dist/tools/paths.d.ts +20 -0
- package/dist/tools/paths.js +58 -0
- package/dist/tools/presets.d.ts +71 -0
- package/dist/tools/presets.js +128 -0
- package/dist/tools/process-tree.d.ts +35 -0
- package/dist/tools/process-tree.js +125 -0
- package/dist/tools/read.d.ts +28 -0
- package/dist/tools/read.js +181 -0
- package/dist/tools/registry.d.ts +43 -0
- package/dist/tools/registry.js +106 -0
- package/dist/tools/shell.d.ts +38 -0
- package/dist/tools/shell.js +91 -0
- package/dist/tools/task.d.ts +29 -0
- package/dist/tools/task.js +107 -0
- package/dist/tools/todo.d.ts +28 -0
- package/dist/tools/todo.js +107 -0
- package/dist/tools/truncate.d.ts +44 -0
- package/dist/tools/truncate.js +175 -0
- package/dist/tools/types.d.ts +135 -0
- package/dist/tools/types.js +19 -0
- package/dist/tools/write.d.ts +20 -0
- package/dist/tools/write.js +84 -0
- package/dist/tui/ansi.d.ts +29 -0
- package/dist/tui/ansi.js +420 -0
- package/dist/tui/component.d.ts +38 -0
- package/dist/tui/component.js +13 -0
- package/dist/tui/components/box.d.ts +26 -0
- package/dist/tui/components/box.js +65 -0
- package/dist/tui/components/container.d.ts +14 -0
- package/dist/tui/components/container.js +39 -0
- package/dist/tui/components/editor-buffer.d.ts +67 -0
- package/dist/tui/components/editor-buffer.js +300 -0
- package/dist/tui/components/editor-paste.d.ts +29 -0
- package/dist/tui/components/editor-paste.js +64 -0
- package/dist/tui/components/editor.d.ts +114 -0
- package/dist/tui/components/editor.js +530 -0
- package/dist/tui/components/key-value.d.ts +29 -0
- package/dist/tui/components/key-value.js +48 -0
- package/dist/tui/components/loader.d.ts +35 -0
- package/dist/tui/components/loader.js +71 -0
- package/dist/tui/components/markdown.d.ts +90 -0
- package/dist/tui/components/markdown.js +462 -0
- package/dist/tui/components/meter.d.ts +29 -0
- package/dist/tui/components/meter.js +47 -0
- package/dist/tui/components/overlay.d.ts +24 -0
- package/dist/tui/components/overlay.js +52 -0
- package/dist/tui/components/select-list.d.ts +57 -0
- package/dist/tui/components/select-list.js +179 -0
- package/dist/tui/components/spacer.d.ts +11 -0
- package/dist/tui/components/spacer.js +16 -0
- package/dist/tui/components/text.d.ts +30 -0
- package/dist/tui/components/text.js +65 -0
- package/dist/tui/keybindings.d.ts +66 -0
- package/dist/tui/keybindings.js +120 -0
- package/dist/tui/keys.d.ts +38 -0
- package/dist/tui/keys.js +275 -0
- package/dist/tui/stdin-buffer.d.ts +41 -0
- package/dist/tui/stdin-buffer.js +206 -0
- package/dist/tui/terminal.d.ts +79 -0
- package/dist/tui/terminal.js +153 -0
- package/dist/tui/theme.d.ts +31 -0
- package/dist/tui/theme.js +199 -0
- package/dist/tui/tui.d.ts +103 -0
- package/dist/tui/tui.js +363 -0
- package/dist/tui/vt-screen.d.ts +46 -0
- package/dist/tui/vt-screen.js +251 -0
- package/dist/tui.d.ts +30 -0
- package/dist/tui.js +31 -0
- package/dist/version.d.ts +8 -0
- package/dist/version.js +24 -0
- package/docs/codemode.md +102 -0
- package/docs/hooks.md +196 -0
- package/docs/host-api.md +161 -0
- package/docs/providers.md +316 -0
- package/docs/rpc.md +253 -0
- package/docs/session-format.md +119 -0
- package/docs/tui.md +168 -0
- package/package.json +101 -4
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/codemode/sandbox-entry.ts
|
|
21
|
+
var sandbox_entry_exports = {};
|
|
22
|
+
__export(sandbox_entry_exports, {
|
|
23
|
+
MAX_CONCURRENT: () => MAX_CONCURRENT,
|
|
24
|
+
MAX_STORE_TOTAL_CHARS: () => MAX_STORE_TOTAL_CHARS,
|
|
25
|
+
MAX_STORE_VALUE_CHARS: () => MAX_STORE_VALUE_CHARS,
|
|
26
|
+
describeError: () => describeError
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(sandbox_entry_exports);
|
|
29
|
+
var import_node_vm = require("node:vm");
|
|
30
|
+
var MAX_CONCURRENT = 8;
|
|
31
|
+
var MAX_STORE_VALUE_CHARS = 262144;
|
|
32
|
+
var MAX_STORE_TOTAL_CHARS = 1048576;
|
|
33
|
+
var SCRIPT_FILENAME = "codemode-script.js";
|
|
34
|
+
var BOOTSTRAP = String.raw`(function (host, config) {
|
|
35
|
+
"use strict";
|
|
36
|
+
const MAX = config.maxConcurrent;
|
|
37
|
+
const stringify = JSON.stringify;
|
|
38
|
+
const parse = JSON.parse;
|
|
39
|
+
const pending = new Map();
|
|
40
|
+
const waiting = [];
|
|
41
|
+
let nextId = 0;
|
|
42
|
+
let active = 0;
|
|
43
|
+
let closed = false;
|
|
44
|
+
const decls = parse(config.tools);
|
|
45
|
+
const declByName = new Map();
|
|
46
|
+
const callName = new Map();
|
|
47
|
+
for (const decl of decls) {
|
|
48
|
+
declByName.set(decl.name, decl.declaration);
|
|
49
|
+
callName.set(decl.name.replace(/[^A-Za-z0-9_$]/g, "_"), decl.name);
|
|
50
|
+
}
|
|
51
|
+
const names = Object.freeze(decls.map((d) => d.name));
|
|
52
|
+
|
|
53
|
+
function format(value) {
|
|
54
|
+
if (typeof value === "string") return value;
|
|
55
|
+
if (value === undefined) return "undefined";
|
|
56
|
+
if (value instanceof Error) return value.name + ": " + value.message;
|
|
57
|
+
try {
|
|
58
|
+
const json = stringify(value, null, 2);
|
|
59
|
+
return json === undefined ? String(value) : json;
|
|
60
|
+
} catch (error) {
|
|
61
|
+
return String(value);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function text(...values) {
|
|
65
|
+
host("output", values.map(format).join(" "));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function callTool(name, input) {
|
|
69
|
+
if (closed) return Promise.reject(new Error("The script has already finished"));
|
|
70
|
+
let payload;
|
|
71
|
+
try {
|
|
72
|
+
payload = stringify({ name: name, input: input === undefined ? {} : input });
|
|
73
|
+
} catch (error) {
|
|
74
|
+
return Promise.reject(new Error("tools." + name + ": arguments must be JSON-serializable"));
|
|
75
|
+
}
|
|
76
|
+
return new Promise((resolve, reject) => {
|
|
77
|
+
const start = () => {
|
|
78
|
+
if (closed) return reject(new Error("The script has already finished"));
|
|
79
|
+
const id = ++nextId;
|
|
80
|
+
active++;
|
|
81
|
+
pending.set(id, { resolve: resolve, reject: reject });
|
|
82
|
+
host("tool_call", stringify(id) + "\n" + payload);
|
|
83
|
+
};
|
|
84
|
+
if (active < MAX) start();
|
|
85
|
+
else waiting.push(start);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function deliver(id, ok, json) {
|
|
90
|
+
const entry = pending.get(id);
|
|
91
|
+
if (entry === undefined) return;
|
|
92
|
+
pending.delete(id);
|
|
93
|
+
active--;
|
|
94
|
+
const next = waiting.shift();
|
|
95
|
+
if (next !== undefined) next();
|
|
96
|
+
if (ok) entry.resolve(json === undefined ? undefined : parse(json));
|
|
97
|
+
else entry.reject(new Error(json));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const toolsTarget = Object.create(null);
|
|
101
|
+
const tools = new Proxy(toolsTarget, {
|
|
102
|
+
get(target, prop) {
|
|
103
|
+
if (typeof prop !== "string" || prop === "then") return undefined;
|
|
104
|
+
const real = callName.get(prop);
|
|
105
|
+
if (real !== undefined) return (args) => callTool(real, args);
|
|
106
|
+
if (prop === "codemode") {
|
|
107
|
+
return () => Promise.reject(new Error("codemode cannot be called from a codemode script"));
|
|
108
|
+
}
|
|
109
|
+
return () =>
|
|
110
|
+
Promise.reject(new Error("Unknown tool " + prop + ". Callable tools: " + names.join(", ")));
|
|
111
|
+
},
|
|
112
|
+
has(target, prop) {
|
|
113
|
+
return typeof prop === "string" && callName.has(prop);
|
|
114
|
+
},
|
|
115
|
+
ownKeys() {
|
|
116
|
+
return [...callName.keys()];
|
|
117
|
+
},
|
|
118
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
119
|
+
if (typeof prop !== "string" || !callName.has(prop)) return undefined;
|
|
120
|
+
return { configurable: true, enumerable: true, writable: false, value: tools[prop] };
|
|
121
|
+
},
|
|
122
|
+
set() {
|
|
123
|
+
return false;
|
|
124
|
+
},
|
|
125
|
+
defineProperty() {
|
|
126
|
+
return false;
|
|
127
|
+
},
|
|
128
|
+
deleteProperty() {
|
|
129
|
+
return false;
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
const storeMap = new Map(Object.entries(parse(config.store)).map(([k, v]) => [k, stringify(v)]));
|
|
134
|
+
let storeChanged = false;
|
|
135
|
+
function store(key, value) {
|
|
136
|
+
if (typeof key !== "string" || key === "") throw new TypeError("store(key, value): key must be a non-empty string");
|
|
137
|
+
if (value === undefined) {
|
|
138
|
+
storeChanged = storeMap.delete(key) || storeChanged;
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
let json;
|
|
142
|
+
try {
|
|
143
|
+
json = stringify(value);
|
|
144
|
+
} catch (error) {
|
|
145
|
+
throw new TypeError("store(" + stringify(key) + "): value must be JSON-serializable");
|
|
146
|
+
}
|
|
147
|
+
if (json === undefined) throw new TypeError("store(" + stringify(key) + "): value must be JSON-serializable");
|
|
148
|
+
if (json.length > config.maxValueChars) {
|
|
149
|
+
throw new RangeError("store(" + stringify(key) + "): value is " + json.length + " characters of JSON (limit " + config.maxValueChars + ")");
|
|
150
|
+
}
|
|
151
|
+
let total = json.length;
|
|
152
|
+
for (const [k, v] of storeMap) if (k !== key) total += v.length;
|
|
153
|
+
if (total > config.maxTotalChars) {
|
|
154
|
+
throw new RangeError("store(" + stringify(key) + "): store would hold " + total + " characters of JSON (limit " + config.maxTotalChars + ")");
|
|
155
|
+
}
|
|
156
|
+
storeMap.set(key, json);
|
|
157
|
+
storeChanged = true;
|
|
158
|
+
}
|
|
159
|
+
function load(key) {
|
|
160
|
+
const json = storeMap.get(key);
|
|
161
|
+
return json === undefined ? undefined : parse(json);
|
|
162
|
+
}
|
|
163
|
+
function describeTool(name) {
|
|
164
|
+
return declByName.get(callName.get(name) ?? name);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const consoleObject = Object.freeze({
|
|
168
|
+
log: text, info: text, warn: text, error: text, debug: text,
|
|
169
|
+
});
|
|
170
|
+
const globals = {
|
|
171
|
+
tools: tools,
|
|
172
|
+
text: (value) => text(value),
|
|
173
|
+
console: consoleObject,
|
|
174
|
+
store: store,
|
|
175
|
+
load: load,
|
|
176
|
+
ALL_TOOLS: names,
|
|
177
|
+
describeTool: describeTool,
|
|
178
|
+
};
|
|
179
|
+
for (const [key, value] of Object.entries(globals)) {
|
|
180
|
+
Object.defineProperty(globalThis, key, { value: value, writable: false, enumerable: false, configurable: false });
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function finish() {
|
|
184
|
+
closed = true;
|
|
185
|
+
waiting.length = 0;
|
|
186
|
+
for (const entry of pending.values()) entry.reject(new Error("The script has finished"));
|
|
187
|
+
pending.clear();
|
|
188
|
+
if (!storeChanged) return undefined;
|
|
189
|
+
const out = {};
|
|
190
|
+
for (const [k, v] of storeMap) out[k] = parse(v);
|
|
191
|
+
return stringify(out);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
async function run(main) {
|
|
195
|
+
const value = await main;
|
|
196
|
+
if (value !== undefined) text(value);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return { deliver: deliver, finish: finish, run: run };
|
|
200
|
+
})`;
|
|
201
|
+
function send(message) {
|
|
202
|
+
process.stdout.write(
|
|
203
|
+
`${JSON.stringify(message).replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029")}
|
|
204
|
+
`
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
function describeError(error) {
|
|
208
|
+
if (typeof error !== "object" || error === null) return String(error);
|
|
209
|
+
const e = error;
|
|
210
|
+
const base = typeof e.message === "string" ? `${typeof e.name === "string" ? e.name : "Error"}: ${e.message}` : String(error);
|
|
211
|
+
const stack = typeof e.stack === "string" ? e.stack : "";
|
|
212
|
+
const at = new RegExp(`${SCRIPT_FILENAME.replace(".", "\\.")}:(\\d+)(?::(\\d+))?`).exec(stack);
|
|
213
|
+
return at === null ? base : `${base} (line ${at[1]})`;
|
|
214
|
+
}
|
|
215
|
+
var started = false;
|
|
216
|
+
var finished = false;
|
|
217
|
+
var bridge;
|
|
218
|
+
var startedAt = 0;
|
|
219
|
+
function done(ok, error) {
|
|
220
|
+
if (finished) return;
|
|
221
|
+
finished = true;
|
|
222
|
+
if (bridge !== void 0) {
|
|
223
|
+
const snapshot = bridge.finish();
|
|
224
|
+
if (ok && snapshot !== void 0) {
|
|
225
|
+
send({ type: "store", entries: JSON.parse(snapshot) });
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
const message = { type: "done", ok, elapsedMs: Date.now() - startedAt };
|
|
229
|
+
if (error !== void 0) message.error = error;
|
|
230
|
+
send(message);
|
|
231
|
+
process.stdout.write("", () => process.exit(0));
|
|
232
|
+
}
|
|
233
|
+
function host(kind, payload) {
|
|
234
|
+
if (finished) return;
|
|
235
|
+
if (kind === "output") {
|
|
236
|
+
send({ type: "output", text: payload });
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (kind === "tool_call") {
|
|
240
|
+
const newline = payload.indexOf("\n");
|
|
241
|
+
const id = Number(payload.slice(0, newline));
|
|
242
|
+
const call = JSON.parse(payload.slice(newline + 1));
|
|
243
|
+
send({ type: "tool_call", id, name: call.name, input: call.input });
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
function start(run) {
|
|
247
|
+
started = true;
|
|
248
|
+
startedAt = Date.now();
|
|
249
|
+
const context = (0, import_node_vm.createContext)(/* @__PURE__ */ Object.create(null), {
|
|
250
|
+
name: "codemode",
|
|
251
|
+
codeGeneration: { strings: false, wasm: false }
|
|
252
|
+
});
|
|
253
|
+
const config = {
|
|
254
|
+
maxConcurrent: MAX_CONCURRENT,
|
|
255
|
+
maxValueChars: MAX_STORE_VALUE_CHARS,
|
|
256
|
+
maxTotalChars: MAX_STORE_TOTAL_CHARS,
|
|
257
|
+
tools: JSON.stringify(run.tools),
|
|
258
|
+
store: JSON.stringify(run.store ?? {})
|
|
259
|
+
};
|
|
260
|
+
let main2;
|
|
261
|
+
try {
|
|
262
|
+
const factory = new import_node_vm.Script(BOOTSTRAP, { filename: "codemode-bootstrap.js" }).runInContext(
|
|
263
|
+
context
|
|
264
|
+
);
|
|
265
|
+
bridge = factory(host, config);
|
|
266
|
+
main2 = new import_node_vm.Script(`(async () => {
|
|
267
|
+
${run.script}
|
|
268
|
+
})()`, {
|
|
269
|
+
filename: SCRIPT_FILENAME,
|
|
270
|
+
lineOffset: -1
|
|
271
|
+
}).runInContext(context);
|
|
272
|
+
} catch (error) {
|
|
273
|
+
done(false, describeError(error));
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
bridge.run(main2).then(
|
|
277
|
+
() => done(true),
|
|
278
|
+
(error) => done(false, describeError(error))
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
function handle(line) {
|
|
282
|
+
let message;
|
|
283
|
+
try {
|
|
284
|
+
message = JSON.parse(line);
|
|
285
|
+
} catch {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
if (message.type === "run") {
|
|
289
|
+
if (!started) start(message);
|
|
290
|
+
} else if (message.type === "tool_result") {
|
|
291
|
+
if (message.ok) {
|
|
292
|
+
const json = message.value === void 0 ? void 0 : JSON.stringify(message.value);
|
|
293
|
+
bridge?.deliver(message.id, true, json);
|
|
294
|
+
} else bridge?.deliver(message.id, false, message.error);
|
|
295
|
+
} else if (message.type === "abort") {
|
|
296
|
+
done(false, "Script aborted");
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
function main() {
|
|
300
|
+
process.on("unhandledRejection", () => {
|
|
301
|
+
});
|
|
302
|
+
process.on("uncaughtException", (error) => done(false, describeError(error)));
|
|
303
|
+
let buffer = "";
|
|
304
|
+
process.stdin.setEncoding("utf8");
|
|
305
|
+
process.stdin.on("data", (chunk) => {
|
|
306
|
+
buffer += chunk;
|
|
307
|
+
const lines = buffer.split("\n");
|
|
308
|
+
buffer = lines.pop() ?? "";
|
|
309
|
+
for (const line of lines) if (line.trim() !== "") handle(line);
|
|
310
|
+
});
|
|
311
|
+
process.stdin.on("end", () => {
|
|
312
|
+
if (buffer.trim() !== "") handle(buffer);
|
|
313
|
+
buffer = "";
|
|
314
|
+
done(false, "Script aborted: parent closed the channel");
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
if (process.argv.includes("--ama-codemode-sandbox")) main();
|
|
318
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
319
|
+
0 && (module.exports = {
|
|
320
|
+
MAX_CONCURRENT,
|
|
321
|
+
MAX_STORE_TOTAL_CHARS,
|
|
322
|
+
MAX_STORE_VALUE_CHARS,
|
|
323
|
+
describeError
|
|
324
|
+
});
|