@inneranimalmedia/agentsam-sdk 2.6.1 → 2.6.3
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/AGENTSAM.md +45 -1
- package/README.md +80 -0
- package/apps/README.md +34 -0
- package/apps/cad-creator/README.md +728 -0
- package/apps/cad-creator/shared/cad/package.json +19 -0
- package/apps/cad-creator/shared/cad/src/domain/operations.ts +7 -0
- package/apps/cad-creator/shared/cad/src/domain/project-contract.d.ts +3 -0
- package/apps/cad-creator/shared/cad/src/domain/project-contract.js +75 -0
- package/apps/cad-creator/shared/cad/src/domain/project-tools.d.ts +1 -0
- package/apps/cad-creator/shared/cad/src/domain/project-tools.js +24 -0
- package/apps/cad-creator/shared/cad/src/domain/validation.ts +191 -0
- package/apps/cad-creator/shared/cad/src/index.ts +4 -0
- package/apps/cad-creator/shared/cad/src/robotics/types.ts +232 -0
- package/apps/cad-creator/shared/cad/src/types.ts +507 -0
- package/apps/cad-creator/shared/cad/tsconfig.json +14 -0
- package/docs/AUTH_IDENTITY_CONTRACT.md +25 -27
- package/docs/AUTORAG.md +58 -0
- package/docs/BRAND_INTELLIGENCE.md +30 -0
- package/docs/CLI_SHELL.md +4 -2
- package/docs/CMS_CONTEXTUAL_COMPOSER.md +38 -0
- package/docs/MERKLE.md +4 -0
- package/docs/PROJECT_CONFIG.md +3 -0
- package/docs/REPOSITORY_KNOWLEDGE.md +2 -0
- package/docs/SDK_WORKER.md +4 -3
- package/docs/THEME_REFINERY.md +120 -0
- package/docs/architecture/PROVIDER-TOOLS-AND-COMPACTION.md +60 -0
- package/docs/architecture/STORAGE.md +87 -0
- package/docs/cad-project-tools.md +69 -0
- package/docs/cms-scaffolding-pattern-reference.md +73 -0
- package/docs/plans/AGENTSAM-INTERACTIVE-UI-REQUIREMENTS-codex-tui-20260919.md +113 -0
- package/docs/plans/AGENTSAM-INTERACTIVE-UI-REQUIREMENTS.md +85 -0
- package/docs/plans/AGENTSAM-MCP-CLIENT-2026-09-19.md +181 -0
- package/docs/plans/ASBD-PORTABLE-WORKGRAPH-UI-DEFERRED.md +34 -0
- package/docs/plans/ASTRA-BRIEF-2026-09-18.md +258 -0
- package/docs/plans/MULTI-AGENT-SPRINTS-2026-09-19.md +373 -0
- package/docs/plans/NEXT-AGENT-HANDOFF.md +167 -0
- package/docs/plans/RECONCILIATION-2026-09-19.md +178 -0
- package/docs/plugins.md +43 -0
- package/docs/tools/README.md +57 -0
- package/docs/tools/agent-and-orchestration.md +49 -0
- package/docs/tools/browser-and-research.md +46 -0
- package/docs/tools/cloudflare-platform.md +32 -0
- package/docs/tools/cms.md +25 -0
- package/docs/tools/communications.md +41 -0
- package/docs/tools/database-and-storage.md +62 -0
- package/docs/tools/design-and-media.md +64 -0
- package/docs/tools/filesystem-and-code.md +55 -0
- package/docs/tools/github.md +56 -0
- package/docs/tools/integrations-and-misc.md +16 -0
- package/docs/tools/memory.md +21 -0
- package/docs/tools/terminal-and-execution.md +29 -0
- package/docs/tools/tickets-and-platform.md +30 -0
- package/migrations/d1/0001_agentsam_plugin_runtime.sql +177 -0
- package/migrations/d1/0002_agentsam_ticket_ownership.sql +8 -0
- package/migrations/d1/0002_dynamic_model_policies.sql +23 -0
- package/migrations/d1/0003_expand_tool_handler_families.sql +18 -0
- package/migrations/d1/0004_project_aware_retrieval_lanes.sql +24 -0
- package/migrations/d1/0005_portable_knowledge_identity.sql +104 -0
- package/migrations/d1/0006_repair_ops_trail_account_scope.sql +14 -0
- package/migrations/d1/0007_repair_ops_trail_agent_run_account.sql +13 -0
- package/migrations/d1/0008_backfill_knowledge_run_legacy_tenant.sql +14 -0
- package/migrations/d1/0009_normalize_cloudflare_plugin_installations.sql +137 -0
- package/migrations/runtime/0001_cli_runtime.sql +67 -0
- package/migrations/runtime/0002_project_sessions.sql +15 -0
- package/migrations/runtime/0003_provider_continuations.sql +8 -0
- package/package.json +92 -12
- package/packages/agentsam-brand/README.md +21 -0
- package/packages/agentsam-brand/package.json +22 -0
- package/packages/agentsam-brand/src/contract.js +59 -0
- package/packages/agentsam-brand/src/extract.js +126 -0
- package/packages/agentsam-brand/src/goap-actions.js +73 -0
- package/packages/agentsam-brand/src/index.js +48 -0
- package/packages/agentsam-brand/src/plan.js +115 -0
- package/packages/agentsam-brand/src/resolve.js +139 -0
- package/packages/agentsam-brand/src/scan.js +250 -0
- package/packages/agentsam-brand/test/brand-scan.test.mjs +106 -0
- package/packages/agentsam-contracts/README.md +23 -0
- package/packages/agentsam-contracts/package.json +32 -0
- package/packages/agentsam-contracts/src/adapter.ts +25 -0
- package/packages/agentsam-contracts/src/agent.ts +35 -0
- package/packages/agentsam-contracts/src/artifacts.ts +33 -0
- package/packages/agentsam-contracts/src/authority.ts +29 -0
- package/packages/agentsam-contracts/src/context.ts +16 -0
- package/packages/agentsam-contracts/src/errors.ts +46 -0
- package/packages/agentsam-contracts/src/events.ts +47 -0
- package/packages/agentsam-contracts/src/execution.ts +50 -0
- package/packages/agentsam-contracts/src/hooks.ts +40 -0
- package/packages/agentsam-contracts/src/identity.ts +16 -0
- package/packages/agentsam-contracts/src/index.ts +14 -0
- package/packages/agentsam-contracts/src/models.ts +9 -0
- package/packages/agentsam-contracts/src/providers.ts +33 -0
- package/packages/agentsam-contracts/src/repository.ts +64 -0
- package/packages/agentsam-contracts/src/tools.ts +98 -0
- package/packages/agentsam-contracts/test/contracts.test.mjs +16 -0
- package/packages/agentsam-contracts/test/errors-catalog.test.mjs +25 -0
- package/packages/agentsam-contracts/test/repository.test.mjs +18 -0
- package/packages/agentsam-contracts/tsconfig.json +12 -0
- package/packages/agentsam-errors/package.json +17 -0
- package/packages/agentsam-errors/src/adapters/anthropic.js +15 -0
- package/packages/agentsam-errors/src/adapters/cad.js +109 -0
- package/packages/agentsam-errors/src/adapters/cloudflare.js +21 -0
- package/packages/agentsam-errors/src/adapters/cursor.js +4 -0
- package/packages/agentsam-errors/src/adapters/device.js +38 -0
- package/packages/agentsam-errors/src/adapters/docker.js +28 -0
- package/packages/agentsam-errors/src/adapters/gcp.js +14 -0
- package/packages/agentsam-errors/src/adapters/github.js +22 -0
- package/packages/agentsam-errors/src/adapters/google.js +17 -0
- package/packages/agentsam-errors/src/adapters/index.js +55 -0
- package/packages/agentsam-errors/src/adapters/internal.js +40 -0
- package/packages/agentsam-errors/src/adapters/oauth.js +24 -0
- package/packages/agentsam-errors/src/adapters/openai.js +17 -0
- package/packages/agentsam-errors/src/adapters/process.js +35 -0
- package/packages/agentsam-errors/src/adapters/provider.js +114 -0
- package/packages/agentsam-errors/src/envelope.js +186 -0
- package/packages/agentsam-errors/src/error.js +24 -0
- package/packages/agentsam-errors/src/fingerprint.js +35 -0
- package/packages/agentsam-errors/src/index.js +10 -0
- package/packages/agentsam-errors/src/normalize.js +30 -0
- package/packages/agentsam-errors/src/redaction.js +52 -0
- package/packages/agentsam-errors/src/render.js +16 -0
- package/packages/agentsam-errors/src/retry.js +10 -0
- package/packages/agentsam-errors/src/transport.js +52 -0
- package/packages/agentsam-errors/src/vocabulary.js +320 -0
- package/packages/agentsam-errors/test/envelope.test.mjs +70 -0
- package/packages/agentsam-errors/test/providers.test.mjs +99 -0
- package/packages/agentsam-errors/test/redaction.test.mjs +21 -0
- package/packages/agentsam-errors/test/runtime-cad-device.test.mjs +76 -0
- package/packages/agentsam-errors/test/transport.test.mjs +46 -0
- package/packages/agentsam-knowledge/package.json +15 -0
- package/packages/agentsam-knowledge/src/autorag/index.js +64 -0
- package/packages/agentsam-knowledge/src/backends/index.js +26 -0
- package/packages/agentsam-knowledge/src/index.js +3 -0
- package/packages/agentsam-knowledge/src/providers/index.js +95 -0
- package/packages/agentsam-knowledge/test/autorag.test.mjs +42 -0
- package/packages/agentsam-nav/README.md +40 -0
- package/packages/agentsam-nav/dist/Nav.d.ts +43 -0
- package/packages/agentsam-nav/dist/NavCollapsible.d.ts +10 -0
- package/packages/agentsam-nav/dist/NavContent.d.ts +2 -0
- package/packages/agentsam-nav/dist/NavFooter.d.ts +2 -0
- package/packages/agentsam-nav/dist/NavGroup.d.ts +3 -0
- package/packages/agentsam-nav/dist/NavHeader.d.ts +2 -0
- package/packages/agentsam-nav/dist/NavMenu.d.ts +22 -0
- package/packages/agentsam-nav/dist/NavProvider.d.ts +35 -0
- package/packages/agentsam-nav/dist/NavTrigger.d.ts +2 -0
- package/packages/agentsam-nav/dist/Surfaces.d.ts +41 -0
- package/packages/agentsam-nav/dist/browser.d.ts +11 -0
- package/packages/agentsam-nav/dist/browser.global.js +132 -0
- package/packages/agentsam-nav/dist/browser.js +613 -0
- package/packages/agentsam-nav/dist/contracts.d.ts +76 -0
- package/packages/agentsam-nav/dist/index.d.ts +11 -0
- package/packages/agentsam-nav/dist/index.js +614 -0
- package/packages/agentsam-nav/dist/legacy.css +83 -0
- package/packages/agentsam-nav/dist/shell.css +113 -0
- package/packages/agentsam-nav/dist/theme.css +113 -0
- package/packages/agentsam-nav/dist/utils.d.ts +1 -0
- package/packages/agentsam-nav/package.json +43 -0
- package/packages/agentsam-queue-control/README.md +107 -0
- package/packages/agentsam-queue-control/package.json +31 -0
- package/packages/agentsam-queue-control/schemas/job-envelope.schema.json +56 -0
- package/packages/agentsam-queue-control/src/adapters/cloudflare.js +152 -0
- package/packages/agentsam-queue-control/src/adapters/memory.js +38 -0
- package/packages/agentsam-queue-control/src/contracts.js +130 -0
- package/packages/agentsam-queue-control/src/control-plane.js +141 -0
- package/packages/agentsam-queue-control/src/dispatch.js +43 -0
- package/packages/agentsam-queue-control/src/index.js +7 -0
- package/packages/agentsam-queue-control/src/policy.js +88 -0
- package/packages/agentsam-queue-control/src/topology.js +66 -0
- package/packages/agentsam-queue-control/test/queue-control.test.mjs +100 -0
- package/packages/agentsam-repository/src/goap.js +718 -0
- package/packages/agentsam-repository/src/goap.js.bak-20260922011251 +670 -0
- package/packages/agentsam-repository/src/index.js +5 -0
- package/packages/agentsam-repository/src/merkle/cloudflare-persistence.js +2 -2
- package/packages/agentsam-repository/src/tickets.js +184 -0
- package/packages/agentsam-repository/src/work-tracking.js +199 -0
- package/packages/agentsam-repository/src/workspace-state.js +176 -0
- package/packages/agentsam-repository/test/goap-tickets-workspace-state.test.mjs +152 -0
- package/packages/connectors/cloudflare/src/index.js +297 -15
- package/packages/connectors/cloudflare/src/owner.js +43 -40
- package/packages/connectors/cloudflare/src/routes.js +167 -26
- package/packages/connectors/cloudflare/tests/connector.test.mjs +112 -2
- package/packages/heuristic-theme/README.md +11 -0
- package/packages/heuristic-theme/package.json +25 -0
- package/packages/heuristic-theme/src/index.js +2 -0
- package/packages/heuristic-theme/src/registry.js +36 -0
- package/packages/heuristic-theme/src/theme.js +41 -0
- package/packages/heuristic-theme/test/theme.test.mjs +26 -0
- package/packages/identity/.agentsam/features/oauth-login-portal/agentsam.feature.json +64 -0
- package/packages/identity/.agentsam/features/oauth-login-portal/providers.json +96 -0
- package/packages/identity/.agentsam/features/oauth-login-portal/resources.json +47 -0
- package/packages/identity/.agentsam/features/oauth-login-portal/routes.json +74 -0
- package/packages/identity/.agentsam/features/oauth-login-portal/ui.json +35 -0
- package/packages/identity/package.json +4 -3
- package/packages/identity/src/adapters/cloudflare-d1/ids.js +4 -0
- package/packages/identity/src/adapters/cloudflare-d1/index.js +39 -1
- package/packages/identity/src/contracts/auth-config.js +23 -40
- package/packages/identity/src/contracts/provider.js +3 -2
- package/packages/identity/src/frontend/auth-portal/pages/login.html +7 -0
- package/packages/identity/src/index.js +2 -0
- package/packages/identity/src/oauth/credentials.js +13 -0
- package/packages/identity/src/oauth/iam-platform.js +5 -5
- package/packages/identity/src/providers/cloudflare/index.js +19 -0
- package/packages/identity/src/providers/cloudflare/mapper.js +21 -0
- package/packages/identity/src/providers/cloudflare/oauth.js +48 -0
- package/packages/identity/src/providers/cloudflare/profile.js +28 -0
- package/packages/identity/src/providers/index.js +18 -2
- package/packages/identity/src/server/identity-service.js +13 -3
- package/packages/identity/src/server/worker-router.js +63 -8
- package/packages/identity/tests/auth-config.test.mjs +14 -23
- package/packages/identity/tests/identity-service.test.mjs +15 -0
- package/packages/providers/completeful/README.md +38 -0
- package/packages/providers/completeful/package.json +29 -0
- package/packages/providers/completeful/src/client.js +162 -0
- package/packages/providers/completeful/src/events.js +49 -0
- package/packages/providers/completeful/src/index.js +22 -0
- package/packages/providers/completeful/src/tools.js +579 -0
- package/packages/providers/completeful/src/webhooks.js +55 -0
- package/packages/providers/completeful/test/provider.test.mjs +196 -0
- package/packages/theme-church-site/README.md +10 -0
- package/packages/theme-church-site/package.json +30 -0
- package/packages/theme-church-site/src/harvest.json +14 -0
- package/packages/theme-church-site/src/index.js +84 -0
- package/packages/theme-church-site/test/theme.test.mjs +19 -0
- package/packages/theme-companions-site/README.md +10 -0
- package/packages/theme-companions-site/package.json +30 -0
- package/packages/theme-companions-site/src/harvest.json +12 -0
- package/packages/theme-companions-site/src/index.js +82 -0
- package/packages/theme-companions-site/test/theme.test.mjs +19 -0
- package/packages/theme-floors-site/README.md +10 -0
- package/packages/theme-floors-site/package.json +30 -0
- package/packages/theme-floors-site/src/harvest.json +14 -0
- package/packages/theme-floors-site/src/index.js +82 -0
- package/packages/theme-floors-site/test/theme.test.mjs +19 -0
- package/packages/theme-fuelnfree-site/README.md +10 -0
- package/packages/theme-fuelnfree-site/package.json +30 -0
- package/packages/theme-fuelnfree-site/src/harvest.json +13 -0
- package/packages/theme-fuelnfree-site/src/index.js +81 -0
- package/packages/theme-fuelnfree-site/test/theme.test.mjs +19 -0
- package/packages/theme-handyman-site/README.md +10 -0
- package/packages/theme-handyman-site/package.json +30 -0
- package/packages/theme-handyman-site/src/harvest.json +10 -0
- package/packages/theme-handyman-site/src/index.js +83 -0
- package/packages/theme-handyman-site/test/theme.test.mjs +19 -0
- package/packages/theme-insurance-site/README.md +10 -0
- package/packages/theme-insurance-site/package.json +30 -0
- package/packages/theme-insurance-site/src/harvest.json +10 -0
- package/packages/theme-insurance-site/src/index.js +83 -0
- package/packages/theme-insurance-site/test/theme.test.mjs +19 -0
- package/packages/theme-shinshu-site/README.md +10 -0
- package/packages/theme-shinshu-site/package.json +30 -0
- package/packages/theme-shinshu-site/src/harvest.json +12 -0
- package/packages/theme-shinshu-site/src/index.js +83 -0
- package/packages/theme-shinshu-site/test/theme.test.mjs +19 -0
- package/packages/work-graph/README.md +49 -0
- package/packages/work-graph/package.json +19 -0
- package/packages/work-graph/prototype/README.md +32 -0
- package/packages/work-graph/prototype/data/demo-workgraph.js +47 -0
- package/packages/work-graph/prototype/renderers/timeline-model.js +21 -0
- package/packages/work-graph/prototype/renderers/workgraph-runtime.js +38 -0
- package/packages/work-graph/prototype-gnantt.html +655 -0
- package/packages/work-graph/src/adapters/business/projects.js +23 -0
- package/packages/work-graph/src/adapters/engineering/git.js +22 -0
- package/packages/work-graph/src/adapters/engineering/mcp.js +22 -0
- package/packages/work-graph/src/index.js +76 -0
- package/packages/work-graph/src/renderers/gantt-model.js +11 -0
- package/packages/work-graph/src/renderers/timeline.js +16 -0
- package/packages/work-graph/test/work-graph.test.mjs +37 -0
- package/protocol/README.md +12 -0
- package/protocol/capabilities/cloudflare-cpu-audit-input.schema.json +30 -6
- package/protocol/capabilities/cloudflare-cpu-profile-input.schema.json +18 -4
- package/protocol/capabilities/cloudflare-wrangler-native-input.schema.json +59 -10
- package/protocol/capabilities/knowledge-search-input.schema.json +35 -0
- package/protocol/capabilities/manifest.json +163 -1
- package/protocol/capabilities/repository-audit-input.schema.json +39 -6
- package/protocol/capabilities/repository-snapshot-input.schema.json +15 -3
- package/protocol/capabilities/terminal-exec-input.schema.json +55 -0
- package/protocol/commerce/catalog.v1.json +50 -0
- package/protocol/errors/error-catalog.json +164 -0
- package/protocol/errors/error-envelope.schema.json +544 -0
- package/protocol/features/README.md +57 -0
- package/protocol/features/agentsam.feature.v1.schema.json +290 -0
- package/protocol/features/catalog.json +65 -0
- package/protocol/features/examples/provider-resend.feature.json +17 -0
- package/protocol/go/agentsam-go-runtime.v1.json +17 -0
- package/protocol/knowledge/LIFECYCLE.md +140 -0
- package/protocol/knowledge/README.md +4 -0
- package/protocol/presets/catalog.json +128 -19
- package/protocol/rpc/v1/errors.proto +24 -0
- package/protocol/theme-refinery/d1-reconciliation.md +48 -0
- package/protocol/theme-refinery/product-metadata.schema.json +27 -0
- package/protocol/theme-refinery/receipts/products-registry-batch-20260924.json +318 -0
- package/protocol/theme-refinery/receipts/theme-harvest-20260924.json +472 -0
- package/protocol/theme-refinery/reconciliation-receipt.schema.json +83 -0
- package/services/cad/server.py +249 -2
- package/src/agent/capability-adapter.js +15 -5
- package/src/agent/index.js +2 -1
- package/src/agent/model-turn.js +51 -0
- package/src/agent/responses-runner.js +304 -38
- package/src/capabilities/index.js +1 -0
- package/src/capabilities/terminal-exec.js +78 -0
- package/src/cli.js +129 -31
- package/src/cloudflare/index.js +6 -0
- package/src/cloudflare/runtime-status.js +393 -0
- package/src/cloudflare/wrangler.js +17 -1
- package/src/commands/account-auth.js +1 -1
- package/src/commands/app.js +106 -0
- package/src/commands/autorag.js +77 -0
- package/src/commands/brand.js +293 -0
- package/src/commands/cad.js +1 -0
- package/src/commands/connections.js +126 -29
- package/src/commands/context-economics.js +8 -0
- package/src/commands/db.js +7 -0
- package/src/commands/deploy.js +2 -2
- package/src/commands/env.js +5 -4
- package/src/commands/eval.js +209 -14
- package/src/commands/go.js +365 -0
- package/src/commands/goap.js +176 -0
- package/src/commands/identity-init.js +27 -3
- package/src/commands/identity-protocol.js +195 -0
- package/src/commands/knowledge.js +64 -5
- package/src/commands/mcp.js +341 -0
- package/src/commands/merkle-persist.js +3 -1
- package/src/commands/merkle.js +18 -3
- package/src/commands/models.js +109 -23
- package/src/commands/plugins.js +175 -0
- package/src/commands/preferences.js +28 -8
- package/src/commands/product.js +53 -10
- package/src/commands/providers.js +389 -0
- package/src/commands/resume.js +9 -5
- package/src/commands/runtime-status.js +154 -0
- package/src/commands/shell.js +469 -54
- package/src/commands/status.js +82 -7
- package/src/commands/tunnel.js +228 -195
- package/src/commands/whoami.js +115 -22
- package/src/context/budget.js +6 -0
- package/src/context/index.js +2 -1
- package/src/context/project-card.js +75 -0
- package/src/errors/contract.js +34 -211
- package/src/errors/diagnostic.js +95 -50
- package/src/errors/index.js +6 -13
- package/src/eval/index.js +6 -0
- package/src/eval/live.js +439 -0
- package/src/features/resolve.js +242 -0
- package/src/go/build.js +108 -0
- package/src/go/cloudflare.js +207 -0
- package/src/go/contract.js +139 -0
- package/src/go/discover.js +96 -0
- package/src/go/index.js +13 -0
- package/src/go/receipts.js +77 -0
- package/src/go/registry.js +223 -0
- package/src/go/verify.js +31 -0
- package/src/index.js +100 -1
- package/src/knowledge/config.js +13 -5
- package/src/knowledge/engine.js +23 -8
- package/src/knowledge/index.js +1 -0
- package/src/knowledge/lane-registry.js +46 -0
- package/src/knowledge/providers/gemini.js +48 -8
- package/src/knowledge/service/client.js +13 -1
- package/src/knowledge/service/grpc-codec.js +156 -53
- package/src/knowledge/service/job-engine.js +133 -11
- package/src/knowledge/service/job-worker.js +34 -5
- package/src/knowledge/service/server.js +10 -1
- package/src/knowledge/store-discovery.js +77 -0
- package/src/lib/account-session.js +100 -25
- package/src/lib/agent-instructions.js +3 -0
- package/src/lib/auth.js +318 -51
- package/src/lib/cad/blender.js +42 -3
- package/src/lib/cad/d1-project-store.js +43 -0
- package/src/lib/cad/discovery.js +616 -0
- package/src/lib/cad/docker-executor.js +352 -0
- package/src/lib/cad/freecad.js +253 -0
- package/src/lib/cad/index.js +40 -0
- package/src/lib/cad/openscad.js +198 -0
- package/src/lib/cad/project-cli.d.ts +2 -0
- package/src/lib/cad/project-cli.js +21 -0
- package/src/lib/cad/project-contract.d.ts +3 -0
- package/src/lib/cad/project-contract.js +1 -0
- package/src/lib/cad/project-recipe.js +30 -0
- package/src/lib/cad/project-runtime.d.ts +2 -0
- package/src/lib/cad/project-runtime.js +53 -0
- package/src/lib/cad/project-store.js +25 -0
- package/src/lib/cad/project-workflows.js +31 -0
- package/src/lib/cad-docker.js +21 -2
- package/src/lib/cli-preferences.js +17 -2
- package/src/lib/core-client.js +97 -33
- package/src/lib/deploy/local-studio.js +6 -5
- package/src/lib/detect-context.js +14 -16
- package/src/lib/dockerize.js +3 -0
- package/src/lib/execution-approvals.js +1 -0
- package/src/lib/identity-scaffold.js +4 -1
- package/src/lib/knowledge-docker.js +9 -1
- package/src/lib/local-sessions.js +124 -34
- package/src/lib/local-status.js +35 -14
- package/src/lib/project-config.js +9 -0
- package/src/lib/provider-credentials.js +233 -55
- package/src/lib/scaffold/resolve-cloudflare-account.js +37 -0
- package/src/lib/scaffold/wizards/cms.js +2 -8
- package/src/lib/scaffold/wizards/worker-api.js +2 -8
- package/src/lib/slash-commands.js +10 -2
- package/src/local/migrations.js +109 -1
- package/src/local/runtime-store.js +31 -5
- package/src/local/sqlite.js +36 -1
- package/src/mcp/authority.js +348 -0
- package/src/mcp/client-adapters.js +431 -0
- package/src/mcp/client.js +172 -0
- package/src/mcp/index.js +47 -0
- package/src/mcp/telemetry.js +103 -0
- package/src/models/catalog.js +329 -51
- package/src/models/discovery.js +59 -4
- package/src/models/index.js +2 -0
- package/src/models/inventory-core.js +182 -0
- package/src/models/policy.js +20 -0
- package/src/plugins/cloudflare.js +103 -0
- package/src/plugins/completeful.js +69 -0
- package/src/plugins/contracts.js +86 -0
- package/src/plugins/index.js +11 -0
- package/src/plugins/registry.js +207 -0
- package/src/plugins/resource-scope.js +45 -0
- package/src/plugins/runtime.js +118 -0
- package/src/plugins/vectorize.js +31 -0
- package/src/progression/engine.js +171 -0
- package/src/progression/index.js +1 -0
- package/src/providers/cloudflare-chat.js +1 -1
- package/src/providers/gemini-generate-content.js +2 -1
- package/src/providers/openai-responses.js +45 -16
- package/src/providers/tool-schema.js +85 -0
- package/src/repository/index.js +29 -0
- package/src/rpc/generated/errors_pb.js +961 -1
- package/src/security/local-vault.js +415 -0
- package/src/security/process.js +20 -4
- package/src/status/actions.js +192 -0
- package/src/tools/hydrate.js +5 -1
- package/src/tools/index.js +7 -0
- package/src/tools/redact.js +64 -0
- package/src/tools/registry.js +83 -0
- package/src/tools/runtime.js +257 -0
- package/src/tools/search.js +21 -8
- package/src/ui/ansi.js +117 -3
- package/src/ui/cli/activity.js +76 -7
- package/src/ui/cli/footer.js +110 -9
- package/src/ui/cli/help.js +14 -5
- package/src/ui/wireframes.js +166 -0
- package/test/account-session.test.mjs +76 -11
- package/test/apps-scaffold-contract.test.mjs +58 -0
- package/test/capabilities.test.mjs +1 -1
- package/test/cli/eval-live.test.mjs +219 -0
- package/test/cli/go.test.mjs +71 -0
- package/test/cli/local-vault-and-provider-setup.test.mjs +268 -0
- package/test/cli/mcp-client.test.mjs +245 -0
- package/test/cli/runtime-ui.test.mjs +69 -2
- package/test/cli/status-actions.test.mjs +88 -0
- package/test/cli/wireframes-go-registry.test.mjs +54 -0
- package/test/cloudflare-connector.test.mjs +3 -6
- package/test/cloudflare-runtime.test.mjs +8 -1
- package/test/context.test.mjs +15 -0
- package/test/error-diagnostics.test.mjs +9 -0
- package/test/fixtures/cad/courtyard-house.json +208 -0
- package/test/go/cloudflare-probe.test.mjs +53 -0
- package/test/integration/app-command.test.mjs +55 -0
- package/test/integration/cad-discovery.test.mjs +158 -0
- package/test/integration/cad-docker-executor.test.mjs +249 -0
- package/test/integration/cad-execution.test.mjs +184 -0
- package/test/integration/cad-project-app.test.mjs +31 -0
- package/test/integration/cad-project-d1.test.mjs +25 -0
- package/test/integration/cad-project-native.test.mjs +24 -0
- package/test/integration/cad-project-workflow.test.mjs +9 -0
- package/test/integration/cad-project.test.mjs +82 -0
- package/test/integration/cli-help.test.mjs +4 -0
- package/test/integration/cms-site-tenancy-contract.test.mjs +256 -0
- package/test/integration/core-client.integration.test.mjs +55 -0
- package/test/integration/error-runtime-rpc.test.mjs +71 -0
- package/test/integration/features-resolve.test.mjs +128 -0
- package/test/integration/install-script.test.mjs +107 -0
- package/test/integration/inventory-core.test.mjs +53 -0
- package/test/integration/plugins-cloudflare.integration.test.mjs +28 -0
- package/test/integration/provider-env-cli.test.mjs +1 -1
- package/test/integration/runtime-migrations.test.mjs +6 -1
- package/test/integration/runtime-status.integration.test.mjs +211 -0
- package/test/integration/scaffold-cloudflare.test.mjs +46 -0
- package/test/integration/storage-architecture.test.mjs +154 -0
- package/test/integration/store-discovery.test.mjs +44 -0
- package/test/integration/terminal-exec.integration.test.mjs +86 -0
- package/test/integration/tool-runtime.test.mjs +124 -0
- package/test/integration/tool-schema.test.mjs +59 -0
- package/test/knowledge-service.test.mjs +4 -0
- package/test/local-sessions.test.mjs +11 -2
- package/test/local-studio-deploy.test.mjs +1 -1
- package/test/model-catalog.test.mjs +28 -1
- package/test/models.test.mjs +159 -5
- package/test/openai-responses.test.mjs +60 -0
- package/test/provider-credentials.test.mjs +15 -5
- package/test/responses-runner.test.mjs +321 -6
- package/test/sdk-worker-contract.test.mjs +5 -1
- package/test/shell.test.mjs +149 -4
- package/test/smoke.mjs +4 -3
- package/test/tools-search.test.mjs +33 -0
- package/test/unit/website-assets-bindings.test.mjs +60 -0
- package/test/whoami-resume.test.mjs +87 -7
- package/examples/gorilla-shell/README.md +0 -15
- package/src/lib/gorilla-template.js +0 -54
- package/src/lib/prompt-byok.js +0 -57
- package/src/lib/save-sdk-token.js +0 -19
- package/templates/gorilla-shell/App.tsx +0 -639
- package/templates/gorilla-shell/README.md +0 -34
- package/templates/gorilla-shell/index.html +0 -15
- package/templates/gorilla-shell/main.jsx +0 -9
- package/templates/gorilla-shell/package.json +0 -19
- package/templates/gorilla-shell/vite.config.js +0 -21
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import {
|
|
4
|
+
AGENTSAM_MCP_PLUGIN_MANIFEST,
|
|
5
|
+
INNERANIMALMEDIA_CLOUDFLARE_OAUTH_PLUGIN_MANIFEST,
|
|
6
|
+
} from '../../src/plugins/index.js';
|
|
7
|
+
|
|
8
|
+
test('Cloudflare OAuth installations have distinct client and callback contracts', () => {
|
|
9
|
+
assert.equal(AGENTSAM_MCP_PLUGIN_MANIFEST.plugin_key, 'agentsam-mcp');
|
|
10
|
+
assert.equal(AGENTSAM_MCP_PLUGIN_MANIFEST.auth_type, 'oauth');
|
|
11
|
+
assert.equal(AGENTSAM_MCP_PLUGIN_MANIFEST.oauth_connect_url, '/api/connections/cloudflare/start');
|
|
12
|
+
assert.equal(
|
|
13
|
+
AGENTSAM_MCP_PLUGIN_MANIFEST.config.callback_url,
|
|
14
|
+
'https://agentsam.inneranimalmedia.com/api/connections/cloudflare/callback',
|
|
15
|
+
);
|
|
16
|
+
assert.equal(AGENTSAM_MCP_PLUGIN_MANIFEST.config.token_auth_method, 'none_pkce');
|
|
17
|
+
|
|
18
|
+
assert.equal(INNERANIMALMEDIA_CLOUDFLARE_OAUTH_PLUGIN_MANIFEST.plugin_key, 'inneranimalmedia-cf-oauth');
|
|
19
|
+
assert.equal(INNERANIMALMEDIA_CLOUDFLARE_OAUTH_PLUGIN_MANIFEST.auth_type, 'oauth_via_iam');
|
|
20
|
+
assert.equal(
|
|
21
|
+
INNERANIMALMEDIA_CLOUDFLARE_OAUTH_PLUGIN_MANIFEST.oauth_connect_url,
|
|
22
|
+
'https://inneranimalmedia.com/api/oauth/cloudflare/start',
|
|
23
|
+
);
|
|
24
|
+
assert.equal(
|
|
25
|
+
INNERANIMALMEDIA_CLOUDFLARE_OAUTH_PLUGIN_MANIFEST.config.callback_url,
|
|
26
|
+
'https://inneranimalmedia.com/api/oauth/cloudflare/callback',
|
|
27
|
+
);
|
|
28
|
+
});
|
|
@@ -29,7 +29,7 @@ test('Cloudflare env init backfills exactly one Wrangler account without printin
|
|
|
29
29
|
spawnSyncImpl: () => ({ status: 0, stdout: JSON.stringify({ accounts: [{ id: '11111111111111111111111111111111', name: 'Example' }] }), stderr: '' }),
|
|
30
30
|
});
|
|
31
31
|
const profile = fs.readFileSync(path.join(home, '.agentsam', 'env.d', 'cloudflare.env'), 'utf8');
|
|
32
|
-
assert.match(profile, /
|
|
32
|
+
assert.match(profile, /CLOUDFLARE_ACCOUNT_ID="11111111111111111111111111111111"/);
|
|
33
33
|
assert.match(profile, /CLOUDFLARE_API_TOKEN=""/);
|
|
34
34
|
assert.match(output, /account detected\/configured/);
|
|
35
35
|
assert.doesNotMatch(output, /CLOUDFLARE_API_TOKEN=.*[^ ]/);
|
|
@@ -6,13 +6,17 @@ import test from 'node:test';
|
|
|
6
6
|
import { createLocalSqliteDatabase } from '../../src/local/sqlite.js';
|
|
7
7
|
import { applyRuntimeMigrations } from '../../src/local/migrations.js';
|
|
8
8
|
|
|
9
|
+
const repoRoot = path.resolve(new URL('../..', import.meta.url).pathname);
|
|
10
|
+
|
|
9
11
|
test('portable runtime migration installs AgentSam CLI state tables idempotently', async (t) => {
|
|
10
12
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agentsam-runtime-migration-'));
|
|
11
13
|
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
12
14
|
const db = await createLocalSqliteDatabase(path.join(root, 'agentsam.sqlite'));
|
|
13
15
|
try {
|
|
14
16
|
const first = await applyRuntimeMigrations(db);
|
|
15
|
-
|
|
17
|
+
const migrationCount = fs.readdirSync(path.join(repoRoot, 'migrations', 'runtime'))
|
|
18
|
+
.filter((name) => /^\d+.*\.sql$/i.test(name)).length;
|
|
19
|
+
assert.equal(first.applied, migrationCount);
|
|
16
20
|
|
|
17
21
|
const tables = await db.prepare(
|
|
18
22
|
"SELECT name FROM sqlite_master WHERE type='table' AND name LIKE 'agentsam_%' ORDER BY name"
|
|
@@ -25,6 +29,7 @@ test('portable runtime migration installs AgentSam CLI state tables idempotently
|
|
|
25
29
|
'agentsam_context_digest',
|
|
26
30
|
'agentsam_cron_runs',
|
|
27
31
|
'agentsam_plans',
|
|
32
|
+
'agentsam_project_sessions',
|
|
28
33
|
'agentsam_schema_migrations',
|
|
29
34
|
'agentsam_todo',
|
|
30
35
|
]) assert.equal(names.has(name), true, name);
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import test from 'node:test';
|
|
4
|
+
import {
|
|
5
|
+
collectCloudflareDeploymentStatus,
|
|
6
|
+
readCloudflareDeploymentContract,
|
|
7
|
+
parseWranglerToml,
|
|
8
|
+
resolveProjectD1Database,
|
|
9
|
+
} from '../../src/cloudflare/runtime-status.js';
|
|
10
|
+
import { collectRuntimeStatus } from '../../src/commands/runtime-status.js';
|
|
11
|
+
import { readProjectConfig } from '../../src/lib/project-config.js';
|
|
12
|
+
import { runStatus } from '../../src/commands/status.js';
|
|
13
|
+
import { renderRuntimeStatus } from '../../src/ui/ansi.js';
|
|
14
|
+
|
|
15
|
+
const root = path.resolve(new URL('../..', import.meta.url).pathname);
|
|
16
|
+
|
|
17
|
+
test('checked-in Cloudflare deployment contract resolves the real Worker and portable bindings', () => {
|
|
18
|
+
const contract = readCloudflareDeploymentContract(root, readProjectConfig(root));
|
|
19
|
+
assert.equal(contract.worker_name, 'agentsam-sdk');
|
|
20
|
+
assert.equal(contract.config, 'apps/local-studio/backend/wrangler.jsonc');
|
|
21
|
+
assert.deepEqual(contract.bindings.map((row) => row.name), [
|
|
22
|
+
'AGENTSAM_WAI', 'ASSETS', 'DB', 'EXECOS', 'HYPERDRIVE', 'IAM_CLIENT_ID',
|
|
23
|
+
'IAM_OAUTH_ISSUER', 'PTY_SERVICE', 'WEBSITE_ASSETS',
|
|
24
|
+
]);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('Cloudflare runtime status compares the active deployed version to the checked-in binding contract', async () => {
|
|
28
|
+
const projectConfig = readProjectConfig(root);
|
|
29
|
+
const contract = readCloudflareDeploymentContract(root, projectConfig);
|
|
30
|
+
const liveBindings = contract.bindings.map((row) => ({ name: row.name, type: row.type }));
|
|
31
|
+
liveBindings.push({ name: 'OPENAI_API_KEY', type: 'secret_text' });
|
|
32
|
+
const calls = [];
|
|
33
|
+
const result = await collectCloudflareDeploymentStatus({
|
|
34
|
+
root,
|
|
35
|
+
projectConfig,
|
|
36
|
+
runWrangler: async (command, input) => {
|
|
37
|
+
calls.push({ command, input });
|
|
38
|
+
if (command === 'whoami') return { data: { loggedIn: true } };
|
|
39
|
+
if (command === 'deployments.list') return { data: [{ id: 'dep_1', created_on: '2026-09-18T12:00:00Z', versions: [{ version_id: 'ver_1', percentage: 100 }] }] };
|
|
40
|
+
if (command === 'versions.list') return { data: [{ id: 'ver_1', metadata: { created_on: '2026-09-18T12:00:00Z' } }] };
|
|
41
|
+
if (command === 'versions.view') return { data: { id: 'ver_1', number: 37, metadata: { created_on: '2026-09-18T12:00:00Z', source: 'wrangler' }, resources: { bindings: liveBindings } } };
|
|
42
|
+
throw new Error(`unexpected:${command}`);
|
|
43
|
+
},
|
|
44
|
+
fetchImpl: async () => ({ ok: true, status: 200, async json() { return { ok: true, app: 'agentsam-sdk' }; } }),
|
|
45
|
+
});
|
|
46
|
+
assert.equal(result.connected, true);
|
|
47
|
+
assert.equal(result.bindings.match, true);
|
|
48
|
+
assert.equal(result.version.number, 37);
|
|
49
|
+
assert.equal(result.health.ok, true);
|
|
50
|
+
assert.equal(calls.find((row) => row.command === 'versions.view').input.version_id, 'ver_1');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('unified status is ready only when account, model, terminal, deployment and health are real', async () => {
|
|
54
|
+
const local = {
|
|
55
|
+
root, project: 'agentsam-sdk', configured: true, git: { branch: 'main', revision: 'abc123', dirty: false },
|
|
56
|
+
pty: { online: false, url: 'http://127.0.0.1:3099/health' }, api: { online: false }, db: { ready: true, tables: [] },
|
|
57
|
+
};
|
|
58
|
+
const status = await collectRuntimeStatus({
|
|
59
|
+
cwd: root,
|
|
60
|
+
collectLocal: async () => local,
|
|
61
|
+
collectIdentity: async () => ({ authenticated: true, active_auth: { kind: 'browser_oauth' }, identity: { account_id: 'acct_1' }, api_key: {} }),
|
|
62
|
+
collectModels: async () => ({ providers: [{ id: 'openai', configured: true }], providerModels: { openai: [{ provider_model_id: 'gpt-test' }] }, local: { online: false, models: [] } }),
|
|
63
|
+
collectTerminal: async () => ({ connected: true, instances: [{ id: 'inst_1' }], connections: [{ id: 'conn_1', active: true, default: true, health: 'online' }], error: null }),
|
|
64
|
+
collectCloudflare: async () => ({ configured: true, connected: true, worker_name: 'agentsam-sdk', bindings: { match: true, live: [] }, health: { ok: true, status: 200 } }),
|
|
65
|
+
});
|
|
66
|
+
assert.equal(status.ready, true);
|
|
67
|
+
assert.equal(status.local_ready, true);
|
|
68
|
+
assert.equal(status.state_storage.actor_runtime, 'none');
|
|
69
|
+
assert.deepEqual(status.checks, { account: true, models: true, terminal: true, cloudflare: true });
|
|
70
|
+
assert.equal(status.model_summary.verified_provider_models, 1);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('fresh local project can start before SQLite has been initialized', async () => {
|
|
74
|
+
const status = await collectRuntimeStatus({
|
|
75
|
+
cwd: root,
|
|
76
|
+
collectLocal: async () => ({ root, project: 'agentsam-sdk', configured: false, git: null, pty: { online: false }, api: {}, db: { exists: false, ready: false } }),
|
|
77
|
+
collectIdentity: async () => ({ authenticated: false, active_auth: {}, api_key: {} }),
|
|
78
|
+
collectModels: async () => ({ providers: [], providerModels: {}, local: { online: false, models: [] } }),
|
|
79
|
+
collectCloudflare: async () => ({ configured: false, bindings: { live: [] } }),
|
|
80
|
+
});
|
|
81
|
+
assert.equal(status.local_ready, true);
|
|
82
|
+
assert.equal(status.state_storage.migrated, false);
|
|
83
|
+
assert.equal(status.state_storage.runtime, 'sqlite');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('unified status consumes the CLI-authorized terminal inventory returned by IAM context', async () => {
|
|
87
|
+
let legacyTerminalCalls = 0;
|
|
88
|
+
const status = await collectRuntimeStatus({
|
|
89
|
+
cwd: root,
|
|
90
|
+
collectLocal: async () => ({ root, project: 'agentsam-sdk', configured: true, git: null, pty: { online: false }, api: {}, db: {} }),
|
|
91
|
+
collectIdentity: async () => ({
|
|
92
|
+
authenticated: true,
|
|
93
|
+
active_auth: { kind: 'browser_oauth' },
|
|
94
|
+
api_key: {},
|
|
95
|
+
terminal: {
|
|
96
|
+
available: true,
|
|
97
|
+
instances: [{ id: 'inst_1', kind: 'local_device' }],
|
|
98
|
+
connections: [{ id: 'conn_1', instance_id: 'inst_1', is_active: true, is_default: true, health_status: 'online' }],
|
|
99
|
+
},
|
|
100
|
+
}),
|
|
101
|
+
collectModels: async () => ({ providers: [], providerModels: { openai: [{ provider_model_id: 'gpt-test' }] }, local: { online: false, models: [] } }),
|
|
102
|
+
collectTerminal: async () => { legacyTerminalCalls += 1; return { connected: false, instances: [], connections: [] }; },
|
|
103
|
+
collectCloudflare: async () => ({ configured: false }),
|
|
104
|
+
});
|
|
105
|
+
assert.equal(legacyTerminalCalls, 0);
|
|
106
|
+
assert.equal(status.terminal.active_connection_count, 1);
|
|
107
|
+
assert.equal(status.checks.terminal, true);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test('status command supports machine-readable injected runtime status', async () => {
|
|
111
|
+
const expected = { schema_version: 'agentsam-runtime-status-v1', ready: true };
|
|
112
|
+
let output = '';
|
|
113
|
+
const result = await runStatus(['--json'], { collectRuntime: async () => expected, write(value) { output += value; } });
|
|
114
|
+
assert.equal(result, expected);
|
|
115
|
+
const parsed = JSON.parse(output);
|
|
116
|
+
assert.equal(parsed.schema_version, expected.schema_version);
|
|
117
|
+
assert.equal(parsed.ready, expected.ready);
|
|
118
|
+
assert.ok(parsed.next?.actions?.length > 0);
|
|
119
|
+
assert.ok(parsed.next?.headline);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('renderRuntimeStatus explicitly displays DB and other resource bindings', () => {
|
|
123
|
+
const status = {
|
|
124
|
+
local: { project: 'agentsam-sdk', root: '/path/to/project' },
|
|
125
|
+
ready: true,
|
|
126
|
+
local_ready: true,
|
|
127
|
+
checks: { account: true, models: true, terminal: true, cloudflare: true },
|
|
128
|
+
cloudflare: {
|
|
129
|
+
configured: true,
|
|
130
|
+
worker_name: 'agentsam-sdk',
|
|
131
|
+
version: { number: 43 },
|
|
132
|
+
bindings: {
|
|
133
|
+
match: true,
|
|
134
|
+
live: [
|
|
135
|
+
{ name: 'DB', type: 'd1', database_name: 'inneranimalmedia-business' },
|
|
136
|
+
{ name: 'WEBSITE_ASSETS', type: 'r2_bucket', bucket_name: 'agentsam-os-blueprint-content' },
|
|
137
|
+
{ name: 'AGENTSAM_WAI', type: 'ai' },
|
|
138
|
+
{ name: 'IAM_CLIENT_ID', type: 'plain_text' },
|
|
139
|
+
{ name: 'OPENAI_API_KEY', type: 'secret_text' },
|
|
140
|
+
],
|
|
141
|
+
declared: [
|
|
142
|
+
{ name: 'DB', type: 'd1', database_name: 'inneranimalmedia-business' },
|
|
143
|
+
{ name: 'WEBSITE_ASSETS', type: 'r2_bucket', bucket_name: 'agentsam-os-blueprint-content' },
|
|
144
|
+
{ name: 'AGENTSAM_WAI', type: 'ai' },
|
|
145
|
+
],
|
|
146
|
+
resources: [
|
|
147
|
+
{ name: 'DB', type: 'd1', database_name: 'inneranimalmedia-business' },
|
|
148
|
+
{ name: 'WEBSITE_ASSETS', type: 'r2_bucket', bucket_name: 'agentsam-os-blueprint-content' },
|
|
149
|
+
{ name: 'AGENTSAM_WAI', type: 'ai' },
|
|
150
|
+
],
|
|
151
|
+
runtime_variables: [{ name: 'IAM_CLIENT_ID', type: 'plain_text' }],
|
|
152
|
+
runtime_secrets: [{ name: 'OPENAI_API_KEY', type: 'secret_text' }],
|
|
153
|
+
missing: [],
|
|
154
|
+
},
|
|
155
|
+
health: { ok: true, status: 200 },
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
const stripAnsi = (text) => String(text || '').replace(/\x1B\[[0-9;]*[a-zA-Z]/g, '');
|
|
160
|
+
const rendered = stripAnsi(renderRuntimeStatus(status));
|
|
161
|
+
assert.match(rendered, /bindings\s+.*5 live/);
|
|
162
|
+
assert.match(rendered, /• DB · d1 \(inneranimalmedia-business\)/);
|
|
163
|
+
assert.match(rendered, /• WEBSITE_ASSETS · r2 \(agentsam-os-blueprint-content\)/);
|
|
164
|
+
assert.match(rendered, /• AGENTSAM_WAI · ai/);
|
|
165
|
+
assert.match(rendered, /1 vars · 1 secrets/);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test('parseWranglerToml parses worker name, d1 databases, r2, hyperdrive, and vars', () => {
|
|
169
|
+
const sample = `
|
|
170
|
+
name = "my-sample-worker"
|
|
171
|
+
main = "src/index.js"
|
|
172
|
+
|
|
173
|
+
[vars]
|
|
174
|
+
ENVIRONMENT = "production"
|
|
175
|
+
PORT = 8080
|
|
176
|
+
|
|
177
|
+
[[d1_databases]]
|
|
178
|
+
binding = "DB"
|
|
179
|
+
database_name = "sample-production-db"
|
|
180
|
+
database_id = "d1-uuid-123"
|
|
181
|
+
|
|
182
|
+
[[r2_buckets]]
|
|
183
|
+
binding = "UPLOADS"
|
|
184
|
+
bucket_name = "sample-bucket"
|
|
185
|
+
|
|
186
|
+
[[hyperdrive]]
|
|
187
|
+
binding = "HYPERDRIVE"
|
|
188
|
+
id = "hd-uuid-456"
|
|
189
|
+
|
|
190
|
+
[ai]
|
|
191
|
+
binding = "AI"
|
|
192
|
+
`;
|
|
193
|
+
|
|
194
|
+
const parsed = parseWranglerToml(sample);
|
|
195
|
+
assert.equal(parsed.name, 'my-sample-worker');
|
|
196
|
+
assert.equal(parsed.vars.ENVIRONMENT, 'production');
|
|
197
|
+
assert.equal(parsed.vars.PORT, 8080);
|
|
198
|
+
assert.equal(parsed.d1_databases.length, 1);
|
|
199
|
+
assert.equal(parsed.d1_databases[0].binding, 'DB');
|
|
200
|
+
assert.equal(parsed.d1_databases[0].database_name, 'sample-production-db');
|
|
201
|
+
assert.equal(parsed.r2_buckets.length, 1);
|
|
202
|
+
assert.equal(parsed.r2_buckets[0].binding, 'UPLOADS');
|
|
203
|
+
assert.equal(parsed.hyperdrive.length, 1);
|
|
204
|
+
assert.equal(parsed.hyperdrive[0].binding, 'HYPERDRIVE');
|
|
205
|
+
assert.equal(parsed.ai.binding, 'AI');
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test('resolveProjectD1Database discovers project DB binding from checked-in config', () => {
|
|
209
|
+
const resolved = resolveProjectD1Database(root);
|
|
210
|
+
assert.equal(resolved, 'inneranimalmedia-business');
|
|
211
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import { detectCloudflareAccounts } from '../../src/commands/env.js';
|
|
4
|
+
import { resolveCloudflareAccountId } from '../../src/lib/scaffold/resolve-cloudflare-account.js';
|
|
5
|
+
import { workerApiTemplates } from '../../src/lib/scaffold/templates/worker-api/index.js';
|
|
6
|
+
|
|
7
|
+
test('Cloudflare account detection accepts Wrangler JSON without exposing credentials', () => {
|
|
8
|
+
const result = detectCloudflareAccounts({
|
|
9
|
+
env: {},
|
|
10
|
+
spawnSyncImpl: () => ({ status: 0, stdout: JSON.stringify({ accounts: [{ id: 'a'.repeat(32), name: 'Example' }] }) }),
|
|
11
|
+
});
|
|
12
|
+
assert.deepEqual(result.accounts, [{ id: 'a'.repeat(32), name: 'Example' }]);
|
|
13
|
+
assert.equal(result.source, 'wrangler');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('scaffold reuses a single detected Cloudflare account without prompting', async () => {
|
|
17
|
+
const notes = [];
|
|
18
|
+
const id = await resolveCloudflareAccountId({
|
|
19
|
+
detectAccounts: () => ({ accounts: [{ id: 'a'.repeat(32), name: 'Example' }] }),
|
|
20
|
+
text: () => { throw new Error('unexpected text prompt'); },
|
|
21
|
+
select: () => { throw new Error('unexpected selection prompt'); },
|
|
22
|
+
isCancel: () => false,
|
|
23
|
+
cancel: () => {},
|
|
24
|
+
note: (message) => notes.push(message),
|
|
25
|
+
pc: { cyan: (value) => value },
|
|
26
|
+
});
|
|
27
|
+
assert.equal(id, 'a'.repeat(32));
|
|
28
|
+
assert.match(notes[0], /Detected Cloudflare account: Example/);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('worker API scaffold emits the selected database contract', () => {
|
|
32
|
+
const input = { projectName: 'example', routes: ['health', 'users', 'content'], cfAccountId: 'a'.repeat(32) };
|
|
33
|
+
const d1 = workerApiTemplates({ ...input, dbKind: 'd1' });
|
|
34
|
+
const hyperdrive = workerApiTemplates({ ...input, dbKind: 'hyperdrive' });
|
|
35
|
+
|
|
36
|
+
assert.match(d1['wrangler.toml'], /\[\[d1_databases\]\]/);
|
|
37
|
+
assert.doesNotMatch(d1['wrangler.toml'], /\[\[hyperdrive\]\]/);
|
|
38
|
+
assert.match(d1['src/routes/users.js'], /env\.DB\.prepare/);
|
|
39
|
+
assert.match(d1['migrations/001_init.sql'], /unixepoch\(\)/);
|
|
40
|
+
|
|
41
|
+
assert.match(hyperdrive['wrangler.toml'], /\[\[hyperdrive\]\]/);
|
|
42
|
+
assert.doesNotMatch(hyperdrive['wrangler.toml'], /\[\[d1_databases\]\]/);
|
|
43
|
+
assert.match(hyperdrive['src/routes/users.js'], /env\.HYPERDRIVE\.connectionString/);
|
|
44
|
+
assert.match(hyperdrive['migrations/001_init.sql'], /TIMESTAMPTZ/);
|
|
45
|
+
assert.match(hyperdrive['package.json'], /"postgres"/);
|
|
46
|
+
});
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { spawnSync } from 'node:child_process';
|
|
6
|
+
import test from 'node:test';
|
|
7
|
+
import { dispatchShellLine } from '../../src/commands/shell.js';
|
|
8
|
+
import { createLocalSession, listLocalSessions, loadLocalSession, saveLocalSession } from '../../src/lib/local-sessions.js';
|
|
9
|
+
import { createLocalSqliteDatabaseSync } from '../../src/local/sqlite.js';
|
|
10
|
+
import { applyRuntimeMigrationsSync } from '../../src/local/migrations.js';
|
|
11
|
+
import { finishRuntimeRun, pruneExpiredRuntimeState, runtimeDatabasePath, startRuntimeRun } from '../../src/local/runtime-store.js';
|
|
12
|
+
|
|
13
|
+
const repoRoot = path.resolve(new URL('../..', import.meta.url).pathname);
|
|
14
|
+
|
|
15
|
+
function fixture(t) {
|
|
16
|
+
const base = fs.mkdtempSync(path.join(os.tmpdir(), 'agentsam-storage-'));
|
|
17
|
+
t.after(() => fs.rmSync(base, { recursive: true, force: true }));
|
|
18
|
+
const home = path.join(base, 'home');
|
|
19
|
+
const projectA = path.join(base, 'project-a');
|
|
20
|
+
const projectB = path.join(base, 'project-b');
|
|
21
|
+
for (const root of [projectA, projectB]) {
|
|
22
|
+
fs.mkdirSync(path.join(root, '.agentsam'), { recursive: true });
|
|
23
|
+
fs.writeFileSync(path.join(root, '.agentsam', 'config.json'), '{"schema_version":2}\n');
|
|
24
|
+
}
|
|
25
|
+
fs.mkdirSync(home);
|
|
26
|
+
return { base, home, projectA, projectB };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
test('S1: a local shell boots and migrates SQLite without cloud configuration', (t) => {
|
|
30
|
+
const { home, projectA } = fixture(t);
|
|
31
|
+
const env = { ...process.env, HOME: home };
|
|
32
|
+
for (const key of ['CLOUDFLARE_API_TOKEN', 'AGENTSAM_API_KEY', 'SUPABASE_URL', 'DATABASE_URL']) delete env[key];
|
|
33
|
+
const result = spawnSync(process.execPath, [path.join(repoRoot, 'src/cli.js'), 'shell'], {
|
|
34
|
+
cwd: projectA, env, input: '/exit\n', encoding: 'utf8', timeout: 10_000,
|
|
35
|
+
});
|
|
36
|
+
assert.equal(result.status, 0, result.stderr);
|
|
37
|
+
assert.match(result.stdout, /Interactive shell ready/);
|
|
38
|
+
assert.equal(fs.existsSync(runtimeDatabasePath(projectA)), true);
|
|
39
|
+
assert.equal(fs.existsSync(path.join(home, '.agentsam', 'sessions')), false);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('S2-S4: cwd and model changes preserve project state; repository switch selects a new authority', async (t) => {
|
|
43
|
+
const { home, projectA, projectB } = fixture(t);
|
|
44
|
+
const child = path.join(projectA, 'src', 'agent');
|
|
45
|
+
fs.mkdirSync(child, { recursive: true });
|
|
46
|
+
assert.equal(runtimeDatabasePath(child), runtimeDatabasePath(projectA));
|
|
47
|
+
|
|
48
|
+
const session = createLocalSession({ cwd: child, title: 'Project A' }, { home });
|
|
49
|
+
const changedModel = saveLocalSession({ ...session, model_key: 'gemini:example' }, { home });
|
|
50
|
+
assert.equal(changedModel.id, session.id);
|
|
51
|
+
assert.equal(changedModel.project_root, projectA);
|
|
52
|
+
assert.equal(loadLocalSession(session.id, { home, cwd: projectA }).model_key, 'gemini:example');
|
|
53
|
+
assert.equal(loadLocalSession(session.id, { home, cwd: projectB }), null);
|
|
54
|
+
|
|
55
|
+
const runId = await startRuntimeRun({ projectRoot: projectA, model_key: 'test:model' });
|
|
56
|
+
let output = '';
|
|
57
|
+
const state = { cwd: child, projectRoot: projectA, home, session: changedModel, interactive: false, write(value) { output += value; } };
|
|
58
|
+
await dispatchShellLine('/logs', state);
|
|
59
|
+
assert.match(output, new RegExp(runId));
|
|
60
|
+
await dispatchShellLine(`/cd ${projectB}`, state);
|
|
61
|
+
assert.equal(state.cwd, projectB);
|
|
62
|
+
assert.equal(state.projectRoot, projectB);
|
|
63
|
+
assert.notEqual(state.session.id, session.id);
|
|
64
|
+
assert.equal(listLocalSessions({ home, cwd: projectA })[0].id, session.id);
|
|
65
|
+
assert.equal(listLocalSessions({ home, cwd: projectB })[0].id, state.session.id);
|
|
66
|
+
assert.equal(fs.existsSync(path.join(child, '.agentsam', 'data', 'agentsam.sqlite')), false);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('S5: expiry cleanup removes transient digests and retains completed run receipts', async (t) => {
|
|
70
|
+
const { projectA } = fixture(t);
|
|
71
|
+
const runId = await startRuntimeRun({ cwd: projectA, model_key: 'test:model' });
|
|
72
|
+
await finishRuntimeRun({ cwd: projectA, id: runId, status: 'completed' });
|
|
73
|
+
const db = createLocalSqliteDatabaseSync(runtimeDatabasePath(projectA));
|
|
74
|
+
db.prepare(`INSERT INTO agentsam_context_digest
|
|
75
|
+
(id, digest_type, agent_run_id, source_hash, digest_hash, digest_text, expires_at_unix)
|
|
76
|
+
VALUES (?, 'session', ?, 'source', 'digest', 'expired', 1)`).run('ctx_expired', runId);
|
|
77
|
+
db.prepare('INSERT INTO agentsam_compaction_events (id, agent_run_id, expires_at_epoch) VALUES (?, ?, 1)').run('cmp_expired', runId);
|
|
78
|
+
db.close();
|
|
79
|
+
|
|
80
|
+
const pruned = await pruneExpiredRuntimeState({ cwd: projectA, nowUnix: 2 });
|
|
81
|
+
assert.deepEqual(pruned, { digests: 1, compactions: 1, approvals_expired: 0 });
|
|
82
|
+
const verified = createLocalSqliteDatabaseSync(runtimeDatabasePath(projectA));
|
|
83
|
+
assert.equal(verified.prepare('SELECT status FROM agentsam_agent_run WHERE id = ?').get(runId).status, 'completed');
|
|
84
|
+
assert.equal(verified.prepare('SELECT COUNT(*) AS n FROM agentsam_context_digest').get().n, 0);
|
|
85
|
+
verified.close();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('S6-S7: connected Worker bindings do not move sessions or store credential values', (t) => {
|
|
89
|
+
const { home, projectA } = fixture(t);
|
|
90
|
+
const workerConfig = fs.readFileSync(path.join(repoRoot, 'apps/local-studio/backend/wrangler.jsonc'), 'utf8');
|
|
91
|
+
for (const binding of ['"d1_databases"', '"hyperdrive"', '"r2_buckets"', '"services"']) assert.match(workerConfig, new RegExp(binding));
|
|
92
|
+
assert.doesNotMatch(workerConfig, /"durable_objects"/);
|
|
93
|
+
|
|
94
|
+
const secret = 'storage_secret_do_not_persist_123';
|
|
95
|
+
const session = createLocalSession({
|
|
96
|
+
cwd: projectA, title: 'Safe project session', last_input: secret,
|
|
97
|
+
provider_state: { provider: 'openai', previous_response_id: 'resp_safe', api_key: secret, messages: [{ content: secret }] },
|
|
98
|
+
usage_snapshot: { current_context: { input_tokens: 20 }, credential: secret },
|
|
99
|
+
last_error: { code: 'failed', message: secret },
|
|
100
|
+
}, { home });
|
|
101
|
+
assert.equal(session.storage.runtime, 'sqlite');
|
|
102
|
+
assert.equal(session.storage.remote, null);
|
|
103
|
+
assert.equal(session.storage.capabilities.remote_shared_state, false);
|
|
104
|
+
assert.equal(session.storage.capabilities.distributed_actor_semantics, false);
|
|
105
|
+
assert.equal(session.last_input, null);
|
|
106
|
+
assert.equal(session.provider_state.api_key, undefined);
|
|
107
|
+
assert.doesNotMatch(fs.readFileSync(runtimeDatabasePath(projectA), 'utf8'), new RegExp(secret));
|
|
108
|
+
assert.equal(fs.statSync(runtimeDatabasePath(projectA)).mode & 0o777, 0o600);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('S8: canonical migrations upgrade an older runtime database for project sessions', (t) => {
|
|
112
|
+
const { base, home, projectA } = fixture(t);
|
|
113
|
+
const oldMigrations = path.join(base, 'old-migrations');
|
|
114
|
+
fs.mkdirSync(oldMigrations);
|
|
115
|
+
fs.copyFileSync(path.join(repoRoot, 'migrations/runtime/0001_cli_runtime.sql'), path.join(oldMigrations, '0001_cli_runtime.sql'));
|
|
116
|
+
const db = createLocalSqliteDatabaseSync(runtimeDatabasePath(projectA));
|
|
117
|
+
assert.equal(applyRuntimeMigrationsSync(db, { migrationsDir: oldMigrations }).applied, 1);
|
|
118
|
+
assert.equal(db.prepare("SELECT name FROM sqlite_master WHERE name = 'agentsam_project_sessions'").get(), undefined);
|
|
119
|
+
db.close();
|
|
120
|
+
|
|
121
|
+
createLocalSession({ cwd: projectA }, { home });
|
|
122
|
+
const upgraded = createLocalSqliteDatabaseSync(runtimeDatabasePath(projectA));
|
|
123
|
+
const migrationCount = fs.readdirSync(path.join(repoRoot, 'migrations', 'runtime'))
|
|
124
|
+
.filter((name) => /^\d+.*\.sql$/i.test(name)).length;
|
|
125
|
+
assert.equal(upgraded.prepare("SELECT COUNT(*) AS n FROM agentsam_schema_migrations").get().n, migrationCount);
|
|
126
|
+
assert.ok(upgraded.prepare("SELECT name FROM sqlite_master WHERE name = 'agentsam_project_sessions'").get());
|
|
127
|
+
upgraded.close();
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test('legacy home-level JSON sessions import only into their matching project SQLite', (t) => {
|
|
131
|
+
const { home, projectA, projectB } = fixture(t);
|
|
132
|
+
const id = 'asess_00000000-0000-4000-8000-000000000099';
|
|
133
|
+
const legacyDir = path.join(home, '.agentsam', 'sessions');
|
|
134
|
+
fs.mkdirSync(legacyDir, { recursive: true });
|
|
135
|
+
const filename = path.join(legacyDir, `${id}.json`);
|
|
136
|
+
fs.writeFileSync(filename, JSON.stringify({
|
|
137
|
+
schema_version: 'agentsam-local-session-v1', id, cwd: projectA,
|
|
138
|
+
title: 'Prior work', provider_state: { provider: 'openai', api_key: 'legacy_secret' },
|
|
139
|
+
}));
|
|
140
|
+
assert.equal(loadLocalSession(id, { home, cwd: projectB }), null);
|
|
141
|
+
assert.equal(fs.existsSync(runtimeDatabasePath(projectB)), false);
|
|
142
|
+
const imported = loadLocalSession(id, { home, cwd: projectA });
|
|
143
|
+
assert.equal(imported.project_root, projectA);
|
|
144
|
+
assert.equal(imported.provider_state.api_key, undefined);
|
|
145
|
+
assert.equal(fs.existsSync(filename), true);
|
|
146
|
+
assert.doesNotMatch(fs.readFileSync(runtimeDatabasePath(projectA), 'utf8'), /legacy_secret/);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('S9: default runtime has no Durable Object binding or dependency', () => {
|
|
150
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(repoRoot, 'package.json'), 'utf8'));
|
|
151
|
+
assert.equal(Object.keys(pkg.dependencies || {}).some((name) => /durable.?object/i.test(name)), false);
|
|
152
|
+
const shell = fs.readFileSync(path.join(repoRoot, 'src/commands/shell.js'), 'utf8');
|
|
153
|
+
assert.doesNotMatch(shell, /\bDurableObject\b|\bdurable_objects\b|\bidFromName\s*\(/);
|
|
154
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { discoverProjectStores, selectKnowledgeStore } from '../../src/knowledge/store-discovery.js';
|
|
7
|
+
import { initRepository, readConfig } from '../../src/knowledge/config.js';
|
|
8
|
+
import { dispatchShellLine } from '../../src/commands/shell.js';
|
|
9
|
+
|
|
10
|
+
test('store discovery reads JSONC bindings without leaking credentials or selecting application storage', async () => {
|
|
11
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agentsam-store-discovery-'));
|
|
12
|
+
fs.writeFileSync(path.join(root, 'package.json'), '{"name":"stores"}');
|
|
13
|
+
fs.writeFileSync(path.join(root, 'wrangler.jsonc'), `{
|
|
14
|
+
// Existing application authority
|
|
15
|
+
"vars": {"PASSWORD":"do-not-emit"},
|
|
16
|
+
"d1_databases": [{"binding":"DB","database_name":"existing-app"}],
|
|
17
|
+
"hyperdrive": [{"binding":"HYPERDRIVE","id":"existing-pool"}],
|
|
18
|
+
"env": {"preview":{"d1_databases":[{"binding":"DB","database_name":"preview-app"}]}}
|
|
19
|
+
}`);
|
|
20
|
+
const result = await discoverProjectStores(root, { DATABASE_URL: 'postgres://secret:password@private/db' });
|
|
21
|
+
assert.equal(result.candidates.find(c => c.driver === 'd1').name, 'existing-app');
|
|
22
|
+
assert.equal(result.candidates.find(c => c.environment === 'preview').name, 'preview-app');
|
|
23
|
+
assert.ok(result.candidates.filter(c => c.role === 'application').every(c => c.selectable === false));
|
|
24
|
+
assert.equal(result.candidates.find(c => c.driver === 'postgres').connection_env, 'DATABASE_URL');
|
|
25
|
+
assert.doesNotMatch(JSON.stringify(result), /password|secret|do-not-emit/);
|
|
26
|
+
assert.equal(fs.existsSync(path.join(root, '.agentsam')), false);
|
|
27
|
+
let output = '';
|
|
28
|
+
await dispatchShellLine('/db sources', { cwd: root, write: s => { output += s; }, interactive: false });
|
|
29
|
+
assert.match(output, /existing-app/);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('knowledge selection edits existing portable config without overwriting scope or moving runtime data', () => {
|
|
33
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agentsam-store-selection-'));
|
|
34
|
+
fs.writeFileSync(path.join(root, 'package.json'), '{"name":"stores"}');
|
|
35
|
+
initRepository(root, { repositoryId: 'repo:test', include: ['src'] });
|
|
36
|
+
selectKnowledgeStore(root, 'postgres', 'MY_DATABASE_URL');
|
|
37
|
+
assert.deepEqual(readConfig(root).scope.include, ['src']);
|
|
38
|
+
assert.equal(readConfig(root).storage.connection_env, 'MY_DATABASE_URL');
|
|
39
|
+
assert.equal(fs.existsSync(path.join(root, '.agentsam/data/agentsam.sqlite')), false);
|
|
40
|
+
assert.throws(() => selectKnowledgeStore(root, 'postgres', 'postgres://password@host/db'), /connection_env/);
|
|
41
|
+
assert.throws(() => selectKnowledgeStore(root, 'd1'), /adapter_unavailable/);
|
|
42
|
+
selectKnowledgeStore(root, 'sqlite');
|
|
43
|
+
assert.deepEqual(readConfig(root).storage, { driver: 'sqlite' });
|
|
44
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import test from 'node:test';
|
|
6
|
+
import { terminalExec } from '../../src/capabilities/terminal-exec.js';
|
|
7
|
+
import { createCapabilityAdapter } from '../../src/agent/capability-adapter.js';
|
|
8
|
+
import { toolApprovalKey } from '../../src/lib/execution-approvals.js';
|
|
9
|
+
|
|
10
|
+
function root(t) {
|
|
11
|
+
const value = fs.mkdtempSync(path.join(os.tmpdir(), 'agentsam-terminal-exec-'));
|
|
12
|
+
t.after(() => fs.rmSync(value, { recursive: true, force: true }));
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
test('terminal.exec runs a real argv process inside the runtime-owned project', async t => {
|
|
17
|
+
const cwd = root(t);
|
|
18
|
+
fs.mkdirSync(path.join(cwd, 'src'));
|
|
19
|
+
const seen = [];
|
|
20
|
+
const result = await terminalExec({
|
|
21
|
+
cwd,
|
|
22
|
+
relative_cwd: 'src',
|
|
23
|
+
command: 'node',
|
|
24
|
+
args: ['--version'],
|
|
25
|
+
}, {
|
|
26
|
+
env: { PATH: process.env.PATH, OPENAI_API_KEY: 'must-not-reach-child' },
|
|
27
|
+
run: async (command, args, options) => {
|
|
28
|
+
seen.push({ command, args, options });
|
|
29
|
+
return { code: 0, signal: null, stdout: 'v24.0.0\n', stderr: '' };
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
assert.equal(result.ok, true);
|
|
33
|
+
assert.equal(result.cwd, path.join(cwd, 'src'));
|
|
34
|
+
assert.equal(seen[0].options.env.OPENAI_API_KEY, undefined);
|
|
35
|
+
assert.equal(seen[0].options.env.PATH, process.env.PATH);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('terminal.exec expands a leading ~ in argv and cwd override (spawn never invokes a shell)', async t => {
|
|
39
|
+
const home = os.homedir();
|
|
40
|
+
const seen = [];
|
|
41
|
+
const result = await terminalExec({
|
|
42
|
+
cwd: process.cwd(),
|
|
43
|
+
command: 'git',
|
|
44
|
+
args: ['-C', '~/agentsam-sdk', 'status'],
|
|
45
|
+
}, {
|
|
46
|
+
env: { PATH: process.env.PATH },
|
|
47
|
+
run: async (command, args, options) => {
|
|
48
|
+
seen.push({ command, args, options });
|
|
49
|
+
return { code: 0, signal: null, stdout: '', stderr: '' };
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
assert.equal(result.ok, true);
|
|
53
|
+
assert.equal(seen[0].args[1], path.join(home, 'agentsam-sdk'));
|
|
54
|
+
assert.equal(seen[0].args[1].startsWith('~'), false);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('terminal.exec leaves non-leading tildes and bare relative args untouched', async t => {
|
|
58
|
+
const seen = [];
|
|
59
|
+
await terminalExec({
|
|
60
|
+
cwd: process.cwd(),
|
|
61
|
+
command: 'echo',
|
|
62
|
+
args: ['user~name', 'plain-arg'],
|
|
63
|
+
}, {
|
|
64
|
+
env: { PATH: process.env.PATH },
|
|
65
|
+
run: async (command, args, options) => {
|
|
66
|
+
seen.push({ command, args, options });
|
|
67
|
+
return { code: 0, signal: null, stdout: '', stderr: '' };
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
assert.deepEqual(seen[0].args, ['user~name', 'plain-arg']);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('terminal.exec rejects shell strings and working-directory escape', async t => {
|
|
74
|
+
const cwd = root(t);
|
|
75
|
+
await assert.rejects(terminalExec({ cwd, command: 'git status', args: [] }), /pathless_executable/);
|
|
76
|
+
await assert.rejects(terminalExec({ cwd, relative_cwd: '..', command: 'git', args: ['status'] }), /outside_project/);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('terminal.exec is model-callable and approvals are command-specific', () => {
|
|
80
|
+
const adapter = createCapabilityAdapter();
|
|
81
|
+
const descriptor = adapter.toolDescriptors().find((row) => row.name === 'terminal.exec');
|
|
82
|
+
assert.ok(descriptor);
|
|
83
|
+
assert.equal(descriptor.risk, 'write');
|
|
84
|
+
assert.equal(toolApprovalKey('terminal.exec', { command: 'git' }), 'terminal.exec:git');
|
|
85
|
+
assert.equal(toolApprovalKey('terminal.exec', { command: 'npm' }), 'terminal.exec:npm');
|
|
86
|
+
});
|