@inneranimalmedia/agentsam-sdk 2.4.1 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (233) hide show
  1. package/AGENTSAM.md +55 -0
  2. package/README.md +17 -12
  3. package/bin/agentsam +2 -0
  4. package/docs/AGENTSAM_ASTRA_OPENAI_INTEGRATION.md +1363 -0
  5. package/docs/AGENTSAM_WORKBENCH.md +30 -0
  6. package/docs/AUTH_IDENTITY_CONTRACT.md +52 -0
  7. package/docs/CAPABILITIES.md +5 -3
  8. package/docs/CLI_SHELL.md +167 -80
  9. package/docs/CMS_STUDIO.md +101 -0
  10. package/docs/CONTEXT.md +170 -0
  11. package/docs/LOCAL_OLLAMA.md +58 -0
  12. package/docs/MERKLE.md +19 -19
  13. package/docs/PORTABLE_CONTEXT.md +4 -3
  14. package/docs/PROJECT_CONFIG.md +72 -0
  15. package/docs/RELEASES.md +35 -2
  16. package/docs/REPOSITORY_INTELLIGENCE.md +1 -1
  17. package/docs/REPOSITORY_KNOWLEDGE.md +114 -0
  18. package/docs/SDK_WORKER.md +86 -0
  19. package/docs/SECURITY.md +59 -22
  20. package/docs/client-cms-editor.md +15 -0
  21. package/docs/local-studio/WORKMODE_DONOR_NOTES.md +485 -0
  22. package/package.json +35 -10
  23. package/packages/connectors/cloudflare/package.json +10 -0
  24. package/packages/connectors/cloudflare/src/index.js +127 -0
  25. package/packages/connectors/cloudflare/src/owner.js +76 -0
  26. package/packages/connectors/cloudflare/src/routes.js +223 -0
  27. package/packages/connectors/cloudflare/src/vault.js +80 -0
  28. package/packages/connectors/cloudflare/tests/connector.test.mjs +44 -0
  29. package/packages/identity/package.json +10 -1
  30. package/packages/identity/src/contracts/auth-config.js +109 -0
  31. package/packages/identity/src/index.js +1 -0
  32. package/packages/identity/src/oauth/README.md +2 -2
  33. package/packages/identity/src/oauth/credentials.js +11 -4
  34. package/packages/identity/src/oauth/iam-platform.js +3 -3
  35. package/packages/identity/src/providers/iam/index.js +7 -7
  36. package/packages/identity/src/providers/iam/oauth.js +6 -4
  37. package/packages/identity/src/providers/iam/profile.js +5 -5
  38. package/packages/identity/tests/auth-config.test.mjs +61 -0
  39. package/packages/identity/tests/oauth-credentials.test.mjs +13 -2
  40. package/protocol/FILEMETA_V1.md +95 -0
  41. package/protocol/INSPECT_VIEWS_V1.md +40 -0
  42. package/protocol/MERKLE_PERSISTENCE_V1.md +50 -0
  43. package/protocol/MERKLE_V1.md +3 -1
  44. package/protocol/README.md +1 -0
  45. package/protocol/capabilities/cloudflare-cpu-audit-input.schema.json +19 -0
  46. package/protocol/capabilities/cloudflare-cpu-profile-input.schema.json +13 -0
  47. package/protocol/capabilities/cloudflare-wrangler-native-input.schema.json +19 -0
  48. package/protocol/capabilities/manifest.json +79 -3
  49. package/protocol/capabilities/repository-snapshot.schema.json +1 -0
  50. package/protocol/context/context-budget.schema.json +36 -0
  51. package/protocol/context/context-item.schema.json +19 -0
  52. package/protocol/context/resolved-context-pack.schema.json +47 -0
  53. package/protocol/context/result-policy.schema.json +17 -0
  54. package/protocol/knowledge/context-pack.schema.json +33 -0
  55. package/protocol/knowledge/retrieval-query.schema.json +68 -13
  56. package/protocol/models/README.md +373 -0
  57. package/protocol/models/model-inventory-v2.schema.json +212 -0
  58. package/python/README.md +15 -7
  59. package/python/agentsam_sdk/cli.py +0 -21
  60. package/python/agentsam_sdk/tui/README.md +17 -12
  61. package/python/agentsam_sdk/tui/bootstrap.py +2 -2
  62. package/python/agentsam_sdk/tui/demo.py +25 -10
  63. package/python/agentsam_sdk/tui/onboarding.py +208 -0
  64. package/python/tests/test_tui_cli.py +7 -6
  65. package/skills/README.md +21 -0
  66. package/skills/agentsam-app-fundamentals/SKILL.md +165 -0
  67. package/skills/agentsam-app-fundamentals/references/graphs-contracts-ast-merkle.md +89 -0
  68. package/skills/agentsam-app-fundamentals/references/trust-credentials-and-destinations.md +99 -0
  69. package/skills/agentsam-cloudflare-workers/SKILL.md +53 -0
  70. package/skills/agentsam-cloudflare-workers/references/cpu-profiling.md +16 -0
  71. package/skills/agentsam-cloudflare-workers/references/errors-and-observability.md +29 -0
  72. package/skills/agentsam-cloudflare-workers/references/wrangler-native-map.md +28 -0
  73. package/skills/agentsam-jr-dev/SKILL.md +232 -0
  74. package/skills/agentsam-jr-dev/references/real-application-logic.md +156 -0
  75. package/skills/agentsam-jr-dev/references/web-application-fundamentals.md +240 -0
  76. package/skills/agentsam-progression-guard/SKILL.md +197 -0
  77. package/skills/agentsam-progression-guard/references/checkpoint-chain.md +111 -0
  78. package/skills/agentsam-progression-guard/references/hooks-operational-io.md +96 -0
  79. package/skills/catalog.json +71 -0
  80. package/src/agent/capability-adapter.js +25 -13
  81. package/src/agent/index.js +1 -0
  82. package/src/agent/responses-runner.js +325 -0
  83. package/src/capabilities/index.js +7 -0
  84. package/src/capabilities/repository-snapshot-view.js +238 -0
  85. package/src/capabilities/repository-snapshot.js +28 -14
  86. package/src/cli.js +198 -76
  87. package/src/cloudflare/cpu-profile.js +115 -0
  88. package/src/cloudflare/index.js +14 -0
  89. package/src/cloudflare/wrangler.js +132 -0
  90. package/src/commands/account-auth.js +47 -0
  91. package/src/commands/cloudflare.js +58 -0
  92. package/src/commands/connections.js +93 -0
  93. package/src/commands/context-economics.js +114 -0
  94. package/src/commands/context.js +14 -2
  95. package/src/commands/db.js +4 -7
  96. package/src/commands/deploy.js +54 -32
  97. package/src/commands/eval.js +63 -0
  98. package/src/commands/interactive.js +18 -0
  99. package/src/commands/knowledge.js +27 -4
  100. package/src/commands/merkle-persist.js +118 -0
  101. package/src/commands/merkle.js +32 -17
  102. package/src/commands/models.js +152 -0
  103. package/src/commands/ollama.js +259 -0
  104. package/src/commands/preferences.js +144 -0
  105. package/src/commands/product.js +86 -16
  106. package/src/commands/resume.js +67 -0
  107. package/src/commands/security.js +8 -6
  108. package/src/commands/shell.js +405 -100
  109. package/src/commands/skills.js +66 -0
  110. package/src/commands/start-local.js +1 -1
  111. package/src/commands/tunnel.js +5 -4
  112. package/src/commands/whoami.js +86 -0
  113. package/src/context/budget.js +120 -0
  114. package/src/context/compact.js +28 -0
  115. package/src/context/index.js +7 -0
  116. package/src/context/rehydrate.js +35 -0
  117. package/src/context/resolve.js +116 -0
  118. package/src/context/result-policy.js +66 -0
  119. package/src/errors/diagnostic.js +160 -0
  120. package/src/errors/index.js +9 -0
  121. package/src/eval/context.js +191 -0
  122. package/src/eval/index.js +1 -0
  123. package/src/index.js +70 -0
  124. package/src/indexing/execution-boundary.js +144 -0
  125. package/src/indexing/index.js +8 -0
  126. package/src/indexing/provider.js +41 -0
  127. package/src/knowledge/config.js +2 -2
  128. package/src/knowledge/context-pack.js +12 -1
  129. package/src/knowledge/contracts.js +9 -4
  130. package/src/knowledge/engine.js +7 -3
  131. package/src/knowledge/service/server.js +1 -1
  132. package/src/lib/account-session.js +98 -0
  133. package/src/lib/agent-instructions.js +73 -0
  134. package/src/lib/auth.js +4 -0
  135. package/src/lib/bridge-client.js +7 -5
  136. package/src/lib/cli-preferences.js +78 -0
  137. package/src/lib/core-client.js +8 -8
  138. package/src/lib/deploy/git-guard.js +69 -0
  139. package/src/lib/deploy/health.js +57 -0
  140. package/src/lib/deploy/local-studio.js +283 -0
  141. package/src/lib/deploy/secret-scan.js +65 -0
  142. package/src/lib/deploy-receipt/index.js +5 -2
  143. package/src/lib/detect-context.js +6 -5
  144. package/src/lib/execution-approvals.js +59 -0
  145. package/src/lib/identity-scaffold.js +1 -1
  146. package/src/lib/local-scaffold.js +35 -33
  147. package/src/lib/local-sessions.js +127 -0
  148. package/src/lib/local-status.js +9 -17
  149. package/src/lib/merkle/cloudflare-persistence.js +321 -0
  150. package/src/lib/merkle/filemeta.js +43 -0
  151. package/src/lib/merkle/git-ignore.js +24 -0
  152. package/src/lib/merkle/hash.js +1 -0
  153. package/src/lib/merkle/index.js +22 -0
  154. package/src/lib/merkle/persistence.js +72 -0
  155. package/src/lib/merkle/semantic.js +359 -0
  156. package/src/lib/merkle/snapshot.js +9 -3
  157. package/src/lib/merkle/tree.js +11 -6
  158. package/src/lib/project-config.js +227 -0
  159. package/src/lib/project-rules.js +68 -0
  160. package/src/lib/provider-credentials.js +83 -0
  161. package/src/lib/save-sdk-token.js +1 -1
  162. package/src/lib/scaffold/templates/worker-api/index.js +101 -20
  163. package/src/lib/scaffold/wizards/worker-api.js +27 -11
  164. package/src/lib/slash-commands.js +22 -15
  165. package/src/lib/tools.js +11 -5
  166. package/src/models/catalog.js +135 -0
  167. package/src/models/index.js +7 -0
  168. package/src/providers/index.js +5 -0
  169. package/src/providers/openai-responses.js +275 -0
  170. package/src/security/index.js +1 -0
  171. package/src/security/inventory.js +4 -1
  172. package/src/security/process.js +35 -9
  173. package/src/security/render.js +27 -5
  174. package/src/security/scan.js +24 -9
  175. package/src/security/trust-boundary.js +24 -0
  176. package/src/skills/index.js +64 -0
  177. package/src/telemetry/contracts.js +203 -0
  178. package/src/telemetry/events.js +48 -0
  179. package/src/telemetry/index.js +8 -0
  180. package/src/tools/hydrate.js +35 -0
  181. package/src/tools/index.js +2 -0
  182. package/src/tools/search.js +70 -0
  183. package/src/ui/ansi.js +1 -1
  184. package/src/ui/boot.js +54 -0
  185. package/src/ui/merkle/render.js +1 -0
  186. package/src/ui/runtime-activity.js +192 -0
  187. package/src/ui/theme.js +19 -18
  188. package/test/account-session.test.mjs +36 -0
  189. package/test/app-building-skills.test.mjs +61 -0
  190. package/test/apps-scaffold-contract.test.mjs +56 -0
  191. package/test/capabilities.test.mjs +53 -4
  192. package/test/cli-preferences.test.mjs +46 -0
  193. package/test/cloudflare-connector.test.mjs +96 -0
  194. package/test/cloudflare-runtime.test.mjs +75 -0
  195. package/test/context.test.mjs +144 -0
  196. package/test/deploy-health-scan.test.mjs +67 -0
  197. package/test/error-diagnostics.test.mjs +59 -0
  198. package/test/eval-context.test.mjs +37 -0
  199. package/test/execution-approvals.test.mjs +27 -0
  200. package/test/indexing-provider.test.mjs +29 -0
  201. package/test/jr-dev-skill.test.mjs +26 -0
  202. package/test/knowledge-context-pack.test.mjs +19 -0
  203. package/test/knowledge.test.mjs +1 -1
  204. package/test/local-sessions.test.mjs +42 -0
  205. package/test/local-studio-deploy.test.mjs +83 -0
  206. package/test/merkle-persistence.test.mjs +91 -0
  207. package/test/merkle.test.mjs +77 -3
  208. package/test/model-catalog.test.mjs +43 -0
  209. package/test/models.test.mjs +51 -0
  210. package/test/npm10-lock.test.mjs +29 -0
  211. package/test/ollama.test.mjs +94 -0
  212. package/test/openai-responses.test.mjs +95 -0
  213. package/test/project-config.test.mjs +81 -0
  214. package/test/project-rules.test.mjs +44 -0
  215. package/test/provider-credentials.test.mjs +52 -0
  216. package/test/rehydrate.test.mjs +25 -0
  217. package/test/release-hygiene.test.mjs +34 -0
  218. package/test/repository-snapshot-view.test.mjs +112 -0
  219. package/test/responses-runner.test.mjs +148 -0
  220. package/test/runtime-activity.test.mjs +98 -0
  221. package/test/sdk-worker-contract.test.mjs +68 -0
  222. package/test/security.test.mjs +46 -0
  223. package/test/shell.test.mjs +55 -21
  224. package/test/skills.test.mjs +22 -0
  225. package/test/smoke.mjs +5 -2
  226. package/test/telemetry.test.mjs +79 -0
  227. package/test/theme-portability.test.mjs +14 -0
  228. package/test/tools-search.test.mjs +40 -0
  229. package/test/whoami-resume.test.mjs +56 -0
  230. package/examples/agentsam-tui-ansi.mjs +0 -149
  231. package/src/commands/tui.js +0 -120
  232. package/src/ui/splash-xterm.js +0 -290
  233. package/src/ui/splash.js +0 -426
@@ -0,0 +1,34 @@
1
+ import assert from 'node:assert/strict';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import test from 'node:test';
5
+
6
+ const root = path.resolve(import.meta.dirname, '..');
7
+ const read = (rel) => fs.readFileSync(path.join(root, rel), 'utf8');
8
+
9
+ test('2.6 release metadata and public terminal vocabulary are aligned', () => {
10
+ const pkg = JSON.parse(read('package.json'));
11
+ const manifest = read('agentsam.yaml');
12
+ const readme = read('README.md');
13
+
14
+ assert.equal(pkg.version, '2.6.0');
15
+ assert.match(manifest, /target_version: "2.6.0"/);
16
+ assert.match(manifest, /state: release_candidate/);
17
+ assert.match(manifest, /current_latest: "2.5.0"/);
18
+ assert.doesNotMatch(manifest, /^\s*- tui\s*$/m);
19
+ assert.doesNotMatch(readme, /agentsam tui|CLI\/TUI/);
20
+ });
21
+
22
+ test('dead branded splash paths are gone and UI preview stays dev-only', () => {
23
+ for (const rel of ['src/ui/splash.js', 'src/ui/splash-xterm.js', 'src/commands/tui.js']) {
24
+ assert.equal(fs.existsSync(path.join(root, rel)), false, `${rel} should not ship`);
25
+ }
26
+ for (const rel of ['scripts/internal/ui-preview-runner.mjs', 'scripts/internal/ansi-ui-preview.mjs']) {
27
+ assert.equal(fs.existsSync(path.join(root, rel)), true, `${rel} should remain available to contributors`);
28
+ }
29
+ assert.equal(fs.existsSync(path.join(root, 'src/ui/runtime-activity.js')), true, 'automatic runtime activity must ship with the product CLI');
30
+
31
+ const pkg = JSON.parse(read('package.json'));
32
+ assert.ok(pkg.files.includes('skills'));
33
+ assert.equal(pkg.files.includes('scripts'), false, 'internal preview scripts must not be published');
34
+ });
@@ -0,0 +1,112 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import {
4
+ buildRepositorySnapshotFacets,
5
+ projectRepositorySnapshot,
6
+ repositoryFileMatches,
7
+ } from '../src/capabilities/repository-snapshot-view.js';
8
+
9
+ function snapshot() {
10
+ return {
11
+ schema_version: 1,
12
+ capability: 'repository.snapshot',
13
+ snapshot_id: 'rsnap_0123456789abcdef01234567',
14
+ created_at: '2026-09-11T00:00:00.000Z',
15
+ content_hash: `sha256:${'1'.repeat(64)}`,
16
+ repository: { full_name: 'SamPrimeaux/agentsam-sdk', branch: 'main', revision_sha: 'abc123', dirty: false },
17
+ tree: {
18
+ merkle_root: `sha256:${'2'.repeat(64)}`,
19
+ metadata_root: `sha256:${'3'.repeat(64)}`,
20
+ manifest: { format: 'agentsam-merkle', version: 1, hash_algorithm: 'sha256', policy_hash: `sha256:${'4'.repeat(64)}` },
21
+ classifier: { format: 'agentsam-filemeta', version: 1, source: 'path+package+ast' },
22
+ stats: { files: 4, directories: 3, symlinks: 0, bytes: 1000 },
23
+ semantic_stats: { entries: 4, files: 4, packages: 2, ast_indexed: 4 },
24
+ paths: ['packages/identity/src/core/accounts.js', 'packages/identity/src/oauth/login.js', 'apps/cms/src/editor.tsx', 'apps/cms/src/assets.ts'],
25
+ files: [
26
+ {
27
+ path: 'packages/identity/src/core/accounts.js', type: 'file', size: 213, mode: 420, hash: `sha256:${'a'.repeat(64)}`,
28
+ package: '@inneranimalmedia/agentsam-sdk-identity', package_root: 'packages/identity', system: 'identity',
29
+ category: 'accounts', layer: 'core', kind: 'source', language: 'javascript', role: 'business-logic', execution_domain: 'unknown',
30
+ tags: ['account-scoped', 'authentication'], symbols: ['accountLinkingNotConfigured'], imports: [],
31
+ },
32
+ {
33
+ path: 'packages/identity/src/oauth/login.js', type: 'file', size: 300, mode: 420, hash: `sha256:${'b'.repeat(64)}`,
34
+ package: '@inneranimalmedia/agentsam-sdk-identity', package_root: 'packages/identity', system: 'identity',
35
+ category: 'login', layer: 'oauth', kind: 'source', language: 'javascript', role: 'business-logic', execution_domain: 'unknown',
36
+ tags: ['authentication'], symbols: ['login'], imports: ['./accounts.js'],
37
+ },
38
+ {
39
+ path: 'apps/cms/src/editor.tsx', type: 'file', size: 250, mode: 420, hash: `sha256:${'c'.repeat(64)}`,
40
+ package: '@inneranimalmedia/cms', package_root: 'apps/cms', system: 'cms-frontend', category: 'editor', layer: 'ui',
41
+ kind: 'source', language: 'typescript', role: 'ui', execution_domain: 'browser', tags: ['cms'], symbols: ['CmsEditor'], imports: ['react'],
42
+ },
43
+ {
44
+ path: 'apps/cms/src/assets.ts', type: 'file', size: 237, mode: 420, hash: `sha256:${'d'.repeat(64)}`,
45
+ package: '@inneranimalmedia/cms', package_root: 'apps/cms', system: 'cms-frontend', category: 'assets', layer: 'data',
46
+ kind: 'source', language: 'typescript', role: 'business-logic', execution_domain: 'browser', tags: ['cms', 'assets'], symbols: ['loadAsset'], imports: [],
47
+ },
48
+ ],
49
+ },
50
+ intelligence: { summary: { file_count: 4 } },
51
+ packages: [], knowledge: { configured: false },
52
+ analysis: {
53
+ trust_boundary: {
54
+ schema_version: 1, analyzer: 'agentsam-execution-boundary', metadata_root: `sha256:${'3'.repeat(64)}`,
55
+ complete: true, status: 'action-required', ok: false, browser_roots: 2, browser_reachable_files: 2, ast_files: 4,
56
+ findings: [{ kind: 'browser-server-import', severity: 'high', source: 'apps/cms/src/editor.tsx', target: 'server/secrets.ts', repair: { action: 'move-server-call-behind-api-boundary' } }],
57
+ },
58
+ },
59
+ deploy: null,
60
+ };
61
+ }
62
+
63
+ test('repository snapshot index is bounded and preserves the three canonical identities', () => {
64
+ const full = snapshot();
65
+ const view = projectRepositorySnapshot(full, { view: 'index' });
66
+ assert.equal(view.snapshot_id, full.snapshot_id);
67
+ assert.equal(view.content_hash, full.content_hash);
68
+ assert.equal(view.tree.merkle_root, full.tree.merkle_root);
69
+ assert.equal(view.tree.metadata_root, full.tree.metadata_root);
70
+ assert.equal(view.tree.manifest.policy_hash, full.tree.manifest.policy_hash);
71
+ assert.equal(view.files, undefined);
72
+ assert.equal(view.projection.matched, 4);
73
+ assert.match(view.projection.projection_hash, /^sha256:[a-f0-9]{64}$/);
74
+ assert.equal(view.tree.paths, undefined);
75
+ assert.equal(view.tree.files, undefined);
76
+ assert.equal(view.analysis.trust_boundary.status, 'action-required');
77
+ assert.equal(view.analysis.trust_boundary.finding_count, 1);
78
+ assert.equal(view.analysis.trust_boundary.findings[0].repair_action, 'move-server-call-behind-api-boundary');
79
+ });
80
+
81
+ test('repository snapshot files view filters semantics before bounding output', () => {
82
+ const full = snapshot();
83
+ const view = projectRepositorySnapshot(full, {
84
+ view: 'files',
85
+ filters: { system: ['identity'], tag: ['authentication'], category: ['accounts'], execution_domain: ['unknown'] },
86
+ limit: 1,
87
+ });
88
+ assert.equal(view.projection.matched, 1);
89
+ assert.equal(view.projection.returned, 1);
90
+ assert.equal(view.projection.truncated, false);
91
+ assert.deepEqual(view.files.map((entry) => entry.path), ['packages/identity/src/core/accounts.js']);
92
+ assert.equal(view.files[0].hash, undefined);
93
+ assert.equal(view.files[0].mode, undefined);
94
+ });
95
+
96
+ test('path globs, AST selectors, and facet counts are deterministic', () => {
97
+ const full = snapshot();
98
+ const files = full.tree.files;
99
+ assert.equal(repositoryFileMatches(files[2], { path: ['apps/cms/**'], symbol: ['CmsEditor'] }), true);
100
+ assert.equal(repositoryFileMatches(files[2], { import: ['react'], language: ['javascript'] }), false);
101
+ const facets = buildRepositorySnapshotFacets(files);
102
+ assert.deepEqual(facets.systems.slice(0, 2), [
103
+ { value: 'cms-frontend', count: 2 },
104
+ { value: 'identity', count: 2 },
105
+ ]);
106
+ assert.deepEqual(facets.tags.find((row) => row.value === 'authentication'), { value: 'authentication', count: 2 });
107
+ assert.deepEqual(facets.execution_domains, [
108
+ { value: 'browser', count: 2 },
109
+ { value: 'unknown', count: 2 },
110
+ ]);
111
+ assert.equal(repositoryFileMatches(files[2], { execution_domain: ['browser'] }), true);
112
+ });
@@ -0,0 +1,148 @@
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 { createCapabilityAdapter } from '../src/agent/capability-adapter.js';
7
+ import { buildAgentToolSurface, capabilityFunctionName, runResponsesAgent } from '../src/agent/responses-runner.js';
8
+
9
+ function usage(input = 10_000, cumulative = input) {
10
+ return {
11
+ current_context: { input_tokens: input, window_tokens: 1_050_000 },
12
+ cumulative: { input_tokens: cumulative, output_tokens: 100, cached_input_tokens: 0, cache_write_tokens: 0, reasoning_tokens: 0 },
13
+ estimate_kind: 'provider', provider_authoritative: true,
14
+ };
15
+ }
16
+ function cost(total = 0.1) { return { total_usd: total }; }
17
+
18
+ test('capability adapter hydrates packaged JSON schemas and tool surface exposes only selected executable schemas', () => {
19
+ const adapter = createCapabilityAdapter();
20
+ const descriptors = adapter.toolDescriptors();
21
+ assert.deepEqual(descriptors.map((row) => row.name).sort(), ['cloudflare.cpu.profile', 'cloudflare.wrangler.native', 'repository.snapshot']);
22
+ const repository = descriptors.find((row) => row.name === 'repository.snapshot');
23
+ assert.equal(repository.input_schema.type, 'object');
24
+ assert.ok(repository.input_schema.properties.cwd);
25
+ const surface = buildAgentToolSurface(adapter, 'snapshot inspect repository');
26
+ assert.equal(surface.tools.length, 1);
27
+ assert.equal(surface.tools[0].name, capabilityFunctionName('repository.snapshot'));
28
+ assert.equal(surface.tools[0].parameters.type, 'object');
29
+ assert.equal(surface.receipt.catalog_tools, 3);
30
+ });
31
+
32
+ test('runner owns cwd, executes selected tool, preserves call_id and returns provider-authoritative continuation', async t => {
33
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agentsam-runner-'));
34
+ t.after(() => fs.rmSync(root, { recursive: true, force: true }));
35
+ fs.mkdirSync(path.join(root, '.git'));
36
+ fs.writeFileSync(path.join(root, 'package.json'), '{"name":"runner-demo"}');
37
+ let invoked = null;
38
+ const capabilityAdapter = createCapabilityAdapter({
39
+ handlers: {
40
+ 'repository.snapshot': async input => {
41
+ invoked = input;
42
+ return { ok: true, cwd: input.cwd, evidence: 'x'.repeat(500) };
43
+ },
44
+ },
45
+ });
46
+ const provider = {
47
+ async create(params) {
48
+ assert.equal(params.model, 'gpt-6-astra');
49
+ assert.equal(params.reasoningEffort, 'high');
50
+ assert.equal(params.serviceTier, 'fast');
51
+ assert.equal(params.tools.length, 1);
52
+ return {
53
+ response_id: 'resp_1', output_text: '', actual_service_tier: 'fast',
54
+ tool_calls: [{ call_id: 'call_1', name: capabilityFunctionName('repository.snapshot'), arguments: '{"cwd":"/tmp/attacker","churnDays":7}' }],
55
+ usage_snapshot: usage(20_000), cost: cost(0.2),
56
+ };
57
+ },
58
+ async continueWithToolOutputs(params) {
59
+ assert.equal(params.previousResponseId, 'resp_1');
60
+ assert.equal(params.toolOutputs[0].call_id, 'call_1');
61
+ assert.match(params.toolOutputs[0].output, /runner-demo|runner-/);
62
+ return { response_id: 'resp_2', output_text: 'done', actual_service_tier: 'fast', tool_calls: [], usage_snapshot: usage(21_000, 41_000), cost: cost(0.3) };
63
+ },
64
+ async compact() { throw new Error('should_not_compact'); },
65
+ };
66
+ const events = [];
67
+ const result = await runResponsesAgent({
68
+ provider, capabilityAdapter, cwd: root, prompt: 'snapshot inspect repository', model: 'gpt-6-astra', reasoningEffort: 'high', serviceTier: 'fast',
69
+ emit: event => events.push(event),
70
+ });
71
+ assert.equal(invoked.cwd, root);
72
+ assert.equal(invoked.churnDays, 7);
73
+ assert.equal(result.output_text, 'done');
74
+ assert.equal(result.response_id, 'resp_2');
75
+ assert.equal(result.total_cost_usd, 0.5);
76
+ assert.equal(result.continuation.compact_before_next_turn, false);
77
+ assert.ok(events.some(event => event.type === 'tool.search'));
78
+ assert.ok(events.some(event => event.type === 'tool.completed'));
79
+ });
80
+
81
+ test('runtime approval hook can deny a model-triggered tool before execution', async t => {
82
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agentsam-runner-denied-'));
83
+ t.after(() => fs.rmSync(root, { recursive: true, force: true }));
84
+ fs.writeFileSync(path.join(root, 'package.json'), '{"name":"denied-demo"}');
85
+ let invoked = false;
86
+ const capabilityAdapter = createCapabilityAdapter({
87
+ handlers: {
88
+ 'repository.snapshot': async () => { invoked = true; return { ok: true }; },
89
+ },
90
+ });
91
+ const provider = {
92
+ async create() {
93
+ return {
94
+ response_id: 'resp_deny', output_text: '', actual_service_tier: 'default',
95
+ tool_calls: [{ call_id: 'call_deny', name: capabilityFunctionName('repository.snapshot'), arguments: '{}' }],
96
+ usage_snapshot: usage(10_000), cost: cost(0.01),
97
+ };
98
+ },
99
+ async continueWithToolOutputs() { throw new Error('continuation_should_not_run'); },
100
+ };
101
+ await assert.rejects(() => runResponsesAgent({
102
+ provider, capabilityAdapter, cwd: root, prompt: 'snapshot repository', model: 'gpt-6-astra', reasoningEffort: 'low', serviceTier: 'default',
103
+ beforeTool: async request => {
104
+ assert.equal(request.capability_id, 'repository.snapshot');
105
+ assert.equal(request.cwd, root);
106
+ return false;
107
+ },
108
+ }), /tool_execution_not_approved:repository\.snapshot/);
109
+ assert.equal(invoked, false);
110
+ });
111
+
112
+ test('runner compacts before a projected high-context continuation rather than crossing normal policy blindly', async () => {
113
+ let compactCalls = 0;
114
+ let createInput = null;
115
+ const capabilityAdapter = createCapabilityAdapter();
116
+ const provider = {
117
+ async compact(params) {
118
+ compactCalls += 1;
119
+ assert.equal(params.previousResponseId, 'resp_old');
120
+ return { output: [{ type: 'compaction', encrypted_content: 'opaque-small' }] };
121
+ },
122
+ async create(params) {
123
+ createInput = params.input;
124
+ assert.equal(params.previousResponseId, undefined);
125
+ return { response_id: 'resp_new', output_text: 'ok', actual_service_tier: 'default', tool_calls: [], usage_snapshot: usage(30_000), cost: cost(0.1) };
126
+ },
127
+ async continueWithToolOutputs() { throw new Error('unused'); },
128
+ };
129
+ const result = await runResponsesAgent({
130
+ provider, capabilityAdapter, cwd: process.cwd(), prompt: 'continue repository work', model: 'gpt-6-astra', reasoningEffort: 'low', serviceTier: 'default',
131
+ previousResponseId: 'resp_old', previousUsageSnapshot: usage(179_500),
132
+ });
133
+ assert.equal(compactCalls, 1);
134
+ assert.ok(Array.isArray(createInput));
135
+ assert.equal(createInput[0].type, 'compaction');
136
+ assert.equal(result.compacted_before_turn, true);
137
+ });
138
+
139
+ test('runner refuses an oversized initial context and supports an explicit projected call-cost ceiling', async () => {
140
+ const capabilityAdapter = createCapabilityAdapter();
141
+ const provider = { async create() { throw new Error('provider_should_not_run'); }, async continueWithToolOutputs() {}, async compact() {} };
142
+ await assert.rejects(() => runResponsesAgent({
143
+ provider, capabilityAdapter, cwd: process.cwd(), prompt: 'x'.repeat(800_000), model: 'gpt-6-astra', reasoningEffort: 'low', serviceTier: 'default',
144
+ }), /context_preflight_(pricing_threshold|max_normal|compaction_required)/);
145
+ await assert.rejects(() => runResponsesAgent({
146
+ provider, capabilityAdapter, cwd: process.cwd(), prompt: 'small task', model: 'gpt-6-astra', reasoningEffort: 'low', serviceTier: 'fast', maxCallCostUsd: 0.01,
147
+ }), /projected_call_cost_exceeds_budget/);
148
+ });
@@ -0,0 +1,98 @@
1
+ import assert from 'node:assert/strict';
2
+ import test from 'node:test';
3
+ import {
4
+ canAnimateTerminal,
5
+ createRuntimeActivity,
6
+ phaseForRuntimeEvent,
7
+ renderRuntimeActivityFrame,
8
+ renderRuntimeActivityPanel,
9
+ renderRuntimeActivityResult,
10
+ } from '../src/ui/runtime-activity.js';
11
+ import { runLocalAgent } from '../src/commands/shell.js';
12
+
13
+ test('runtime activity is automatic only in a real interactive terminal', () => {
14
+ assert.equal(canAnimateTerminal({ stdout: { isTTY: true }, env: { TERM: 'xterm-256color' } }), true);
15
+ assert.equal(canAnimateTerminal({ stdout: { isTTY: false }, env: { TERM: 'xterm-256color' } }), false);
16
+ assert.equal(canAnimateTerminal({ stdout: { isTTY: true }, env: { TERM: 'dumb' } }), false);
17
+ assert.equal(canAnimateTerminal({ stdout: { isTTY: true }, env: { TERM: 'xterm-256color', CI: '1' } }), false);
18
+ });
19
+
20
+ test('runtime renderer exposes thinking, tool, and context phases without product renderer vocabulary', () => {
21
+ assert.match(renderRuntimeActivityFrame({ phase: 'thinking', tick: 1, elapsedMs: 1250 }), /Agent Sam/);
22
+ assert.match(renderRuntimeActivityFrame({ phase: 'thinking', tick: 1, elapsedMs: 1250 }), /thinking/);
23
+ const panel = renderRuntimeActivityPanel({ phase: 'thinking', tick: 2, elapsedMs: 1250 });
24
+ assert.match(panel, /Agent Sam/);
25
+ assert.match(panel, /thinking · working locally/);
26
+ assert.match(panel, /\(●\)/);
27
+ assert.equal(panel.split('\n').length, 5);
28
+ assert.match(renderRuntimeActivityResult({ phase: 'done', elapsedMs: 1250 }), /done/);
29
+ assert.equal(phaseForRuntimeEvent({ type: 'model.started' }), 'thinking');
30
+ assert.equal(phaseForRuntimeEvent({ type: 'tool.started', tool: 'git.status' }), 'using git.status');
31
+ assert.equal(phaseForRuntimeEvent({ type: 'context.compaction.started' }), 'tidying context');
32
+ });
33
+
34
+ test('runtime activity redraws automatically and restores the cursor', () => {
35
+ let output = '';
36
+ let clock = 0;
37
+ let intervalFn = null;
38
+ const activity = createRuntimeActivity({
39
+ write: (text) => { output += text; },
40
+ interactive: true,
41
+ now: () => clock,
42
+ setInterval: (fn) => { intervalFn = fn; return 7; },
43
+ clearInterval: () => {},
44
+ });
45
+
46
+ activity.start('thinking');
47
+ clock = 320;
48
+ intervalFn();
49
+ activity.update('using repository.snapshot');
50
+ clock = 840;
51
+ activity.succeed('done');
52
+
53
+ assert.match(output, /thinking/);
54
+ assert.match(output, /using repository\.snapshot/);
55
+ assert.match(output, /done/);
56
+ assert.match(output, /\x1b\[\?25l/);
57
+ assert.match(output, /\x1b\[\?25h/);
58
+ });
59
+
60
+ test('/agent starts and completes product activity around the real request', async () => {
61
+ const phases = [];
62
+ let output = '';
63
+ const activity = {
64
+ start: (phase) => phases.push(`start:${phase}`),
65
+ succeed: (phase) => phases.push(`success:${phase}`),
66
+ fail: (phase) => phases.push(`fail:${phase}`),
67
+ };
68
+ const fetchImpl = async () => ({
69
+ ok: true,
70
+ status: 200,
71
+ async text() { return JSON.stringify({ ok: true, answer: 'ready' }); },
72
+ });
73
+
74
+ await runLocalAgent('inspect this repo', (text) => { output += text; }, { fetchImpl, activity, interactive: true });
75
+ assert.deepEqual(phases, ['start:thinking', 'success:done']);
76
+ assert.match(output, /"answer": "ready"/);
77
+ });
78
+
79
+
80
+ test('/agent restores product activity when the response body fails', async () => {
81
+ const phases = [];
82
+ const activity = {
83
+ start: (phase) => phases.push(`start:${phase}`),
84
+ succeed: (phase) => phases.push(`success:${phase}`),
85
+ fail: (phase) => phases.push(`fail:${phase}`),
86
+ };
87
+ const fetchImpl = async () => ({
88
+ ok: true,
89
+ status: 200,
90
+ async text() { throw new Error('body interrupted'); },
91
+ });
92
+
93
+ await assert.rejects(
94
+ runLocalAgent('inspect this repo', () => {}, { fetchImpl, activity, interactive: true }),
95
+ /response could not be read: body interrupted/,
96
+ );
97
+ assert.deepEqual(phases, ['start:thinking', 'fail:response error']);
98
+ });
@@ -0,0 +1,68 @@
1
+ import assert from 'node:assert/strict';
2
+ import fs from 'node:fs';
3
+ import test from 'node:test';
4
+
5
+ const read = (relative) => fs.readFileSync(new URL(`../${relative}`, import.meta.url), 'utf8');
6
+ const exists = (relative) => fs.existsSync(new URL(`../${relative}`, import.meta.url));
7
+
8
+ const wrangler = read('apps/local-studio/backend/wrangler.jsonc');
9
+ const providers = read('apps/local-studio/shared/agentsam/src/model-providers.ts');
10
+ const runtime = read('apps/local-studio/backend/server/lib/cloudflare-runtime.ts');
11
+ const worker = read('apps/local-studio/backend/worker/index.js');
12
+
13
+ test('Local Studio backend is the only agentsam-sdk Cloudflare application owner', () => {
14
+ assert.equal(exists('wrangler.jsonc'), false);
15
+ assert.equal(exists('worker/index.js'), false);
16
+ assert.equal(exists('scripts/with-cloudflare-env.sh'), false);
17
+ assert.ok(exists('apps/local-studio/backend/worker/index.js'));
18
+ assert.equal(exists('apps/local-studio/backend/wrangler.ui.toml'), false);
19
+ assert.equal(exists('apps/local-studio/backend/wrangler.workmode.toml'), false);
20
+ assert.ok(exists('apps/local-studio/backend/wrangler.jsonc'));
21
+ });
22
+
23
+ test('agentsam-sdk Worker uses the backend Worker entry, custom domain only, and canonical bindings', () => {
24
+ assert.match(wrangler, /"name"\s*:\s*"agentsam-sdk"/);
25
+ assert.match(wrangler, /"main"\s*:\s*"worker\/index\.js"/);
26
+ assert.match(wrangler, /"directory"\s*:\s*"\.\.\/\.output\/public"/);
27
+ assert.match(wrangler, /"workers_dev"\s*:\s*false/);
28
+ assert.match(wrangler, /"pattern"\s*:\s*"agentsam\.inneranimalmedia\.com"/);
29
+ assert.match(wrangler, /"binding"\s*:\s*"DB"/);
30
+ assert.match(wrangler, /"database_name"\s*:\s*"inneranimalmedia-business"/);
31
+ assert.match(wrangler, /"binding"\s*:\s*"WEBSITE_ASSETS"/);
32
+ assert.match(wrangler, /"bucket_name"\s*:\s*"agentsam-os-blueprint-content"/);
33
+ assert.match(wrangler, /"binding"\s*:\s*"AGENTSAM_WAI"/);
34
+ assert.match(wrangler, /"binding"\s*:\s*"EXECOS"/);
35
+ assert.match(wrangler, /"service"\s*:\s*"execos"/);
36
+ assert.match(wrangler, /"binding"\s*:\s*"PTY_SERVICE"/);
37
+ assert.match(wrangler, /"service_id"\s*:\s*"019db639-7c70-7071-8ef3-32ec0392a9ff"/);
38
+ assert.match(wrangler, /"IAM_ORIGIN"\s*:\s*"https:\/\/inneranimalmedia\.com"/);
39
+ assert.doesNotMatch(wrangler, /AGENTSAM_WORKER_ROLE/);
40
+ assert.doesNotMatch(wrangler, /"OLLAMA_BASE_URL"\s*:/);
41
+ assert.doesNotMatch(wrangler, /workers\.dev/);
42
+ });
43
+
44
+ test('canonical Worker preserves vault routes and delegates app traffic to Nitro', () => {
45
+ assert.match(worker, /url\.pathname\.startsWith\("\/api\/vault\/"\)/);
46
+ assert.match(worker, /\/api\/vault\/secrets/);
47
+ assert.match(worker, /\/api\/vault\/unwrap/);
48
+ assert.match(worker, /return nitroWorker\.fetch\(request, env, context\)/);
49
+ });
50
+
51
+ test('model providers include Grok independently from Grok gate authentication', () => {
52
+ for (const id of ['grok', 'openai', 'gemini', 'workers-ai', 'ollama']) {
53
+ assert.match(providers, new RegExp(`id: ["']${id}["']`));
54
+ }
55
+ assert.match(providers, /credential: "XAI_API_KEY"/);
56
+ assert.match(providers, /binding: "AGENTSAM_WAI"/);
57
+ assert.match(providers, /binding: "EXECOS"/);
58
+ });
59
+
60
+ test('Ollama uses local loopback behind ExecOS with a portable explicit cwd', () => {
61
+ assert.match(runtime, /baseUrl: "http:\/\/127\.0\.0\.1:11434"/);
62
+ assert.match(runtime, /target: "local"/);
63
+ assert.match(runtime, /x-bridge-key/);
64
+ assert.match(runtime, /return explicit \|\| "\/"/);
65
+ assert.match(runtime, /JSON\.stringify\(\{ command, target: "local", cwd \}\)/);
66
+ assert.match(runtime, /public_base_url: false/);
67
+ assert.doesNotMatch(runtime, /ollama\.inneranimalmedia\.com/);
68
+ });
@@ -181,3 +181,49 @@ test('a missing transitive dependency cannot pass as complete coverage', async t
181
181
  assert.equal(report.complete,false);
182
182
  assert.ok(report.issues.some(issue=>issue.includes('Missing locked dependency edge')));
183
183
  });
184
+
185
+ test('security scan includes AST/Merkle trust-boundary contradictions and mechanical repair evidence', async t => {
186
+ const f = fixture(t);
187
+ fs.mkdirSync(path.join(f.root, 'frontend'), { recursive: true });
188
+ fs.mkdirSync(path.join(f.root, 'backend'), { recursive: true });
189
+ fs.writeFileSync(path.join(f.root, 'frontend', 'client.ts'), [
190
+ "import { secretValue } from '../backend/secrets.ts';",
191
+ "export const value = secretValue;",
192
+ ].join('\n'));
193
+ fs.writeFileSync(path.join(f.root, 'backend', 'secrets.ts'), [
194
+ "export const secretValue = process.env.API_KEY;",
195
+ ].join('\n'));
196
+
197
+ const report = await scanProjectSecurity({ projectRoot: f.root, fetch: empty });
198
+ assert.equal(report.complete, true);
199
+ assert.equal(report.ok, false);
200
+ assert.equal(report.status, 'action-required');
201
+ assert.match(report.trust_boundary.merkle_root, /^sha256:/);
202
+ assert.match(report.trust_boundary.metadata_root, /^sha256:/);
203
+ const finding = report.trust_boundary.findings.find((item) => item.kind === 'browser-server-import');
204
+ assert.ok(finding);
205
+ assert.equal(finding.source, 'frontend/client.ts');
206
+ assert.equal(finding.target, 'backend/secrets.ts');
207
+ assert.equal(finding.repair.action, 'move-server-call-behind-api-boundary');
208
+ assert.equal(reportExitCode(report), 1);
209
+ const text = formatSecurityReport(report);
210
+ assert.match(text, /Trust boundary/);
211
+ assert.match(text, /frontend\/client\.ts/);
212
+ assert.match(text, /move-server-call-behind-api-boundary/);
213
+ });
214
+
215
+ test('browser env and server-runtime imports are derived from syntax rather than folder names alone', async t => {
216
+ const f = fixture(t);
217
+ fs.mkdirSync(path.join(f.root, 'frontend', 'src'), { recursive: true });
218
+ fs.writeFileSync(path.join(f.root, 'frontend', 'src', 'client.ts'), [
219
+ "import fs from 'node:fs';",
220
+ "export const leaked = import.meta.env.VITE_API_KEY;",
221
+ "export const privateValue = process.env.INTERNAL_TOKEN;",
222
+ "export const exists = Boolean(fs);",
223
+ ].join('\n'));
224
+ const report = await scanProjectSecurity({ projectRoot: f.root, fetch: empty });
225
+ const kinds = new Set(report.trust_boundary.findings.map((item) => item.kind));
226
+ assert.ok(kinds.has('browser-server-runtime-import'));
227
+ assert.ok(kinds.has('browser-public-secret-name'));
228
+ assert.ok(kinds.has('browser-private-env-access'));
229
+ });
@@ -4,7 +4,8 @@ import os from 'node:os';
4
4
  import path from 'node:path';
5
5
  import { spawnSync } from 'node:child_process';
6
6
  import test from 'node:test';
7
- import { dispatchShellLine, renderShellCatalog, tokenizeShellLine } from '../src/commands/shell.js';
7
+ import { dispatchShellLine, renderShellCatalog, renderShellPrompt, tokenizeShellLine } from '../src/commands/shell.js';
8
+ import { readCliPreferences, writeCliPreferences } from '../src/lib/cli-preferences.js';
8
9
 
9
10
  const repoRoot = path.resolve(new URL('..', import.meta.url).pathname);
10
11
 
@@ -14,47 +15,80 @@ test('shell tokenizer preserves Windows paths and quoted arguments', () => {
14
15
  assert.deepEqual(tokenizeShellLine('/agent "inspect this repo"'), ['/agent', 'inspect this repo']);
15
16
  });
16
17
 
17
- test('shell catalog advertises commands that the REPL owns', () => {
18
+ test('interactive prompt derives username and cwd instead of hardcoding Agent Sam identity', () => {
19
+ const env = { USER: 'alice', HOME: '/Users/alice' };
20
+ assert.equal(renderShellPrompt('/Users/alice/code/demo', env), 'alice ~/code/demo > ');
21
+ assert.equal(renderShellPrompt('/Users/alice', env), 'alice ~ > ');
22
+ assert.equal(renderShellPrompt('/tmp/demo', env), 'alice /tmp/demo > ');
23
+ });
24
+
25
+ test('shell catalog only advertises implemented core controls', () => {
18
26
  const catalog = renderShellCatalog();
19
- assert.match(catalog, /\/help\s+Show Agent Sam commands/);
20
- assert.match(catalog, /\/status\s+Local project/);
21
- assert.match(catalog, /\/exit\s+Exit Agent Sam shell/);
27
+ for (const command of ['/model', '/reasoning', '/fast', '/flex', '/standard', '/context', '/cf', '/diff', '/clear', '/exit']) {
28
+ assert.match(catalog, new RegExp(command.replace('/', '\\/')));
29
+ }
30
+ assert.match(catalog, /scrollable command picker/);
22
31
  });
23
32
 
24
- test('dispatch handles help, pwd, cd, and exit without falling through to host shell', async () => {
33
+ test('dispatch handles help, menu fallback, pwd, cd, and exit without falling through to host shell', async () => {
25
34
  const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agentsam-shell-'));
26
35
  const child = path.join(root, 'child folder');
27
36
  fs.mkdirSync(child);
28
37
  let output = '';
29
- const state = { cwd: root, write: (text) => { output += text; } };
30
-
38
+ const state = { cwd: root, write: (text) => { output += text; }, interactive: false };
31
39
  let result = await dispatchShellLine('/help', state);
32
40
  assert.equal(result.handled, true);
33
- assert.equal(result.exit, false);
34
41
  assert.match(output, /Slash commands/);
35
-
36
42
  output = '';
37
- result = await dispatchShellLine('/pwd', state);
38
- assert.equal(result.handled, true);
43
+ await dispatchShellLine('/', state);
44
+ assert.match(output, /Agent Sam Terminal/);
45
+ output = '';
46
+ await dispatchShellLine('/pwd', state);
39
47
  assert.equal(output.trim(), root);
40
-
41
48
  output = '';
42
- result = await dispatchShellLine('/cd "child folder"', state);
43
- assert.equal(result.handled, true);
49
+ await dispatchShellLine('/cd "child folder"', state);
44
50
  assert.equal(state.cwd, child);
45
51
  assert.equal(output.trim(), child);
46
-
47
52
  result = await dispatchShellLine('/exit', state);
48
53
  assert.equal(result.exit, true);
49
54
  });
50
55
 
56
+ test('reasoning and service-tier commands persist only supported controls for an exact model', async () => {
57
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agentsam-shell-model-'));
58
+ fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify({ name: 'model-demo' }));
59
+ writeCliPreferences(root, { trustedDirectory: true, modelPreference: 'openai:gpt-6-astra', reasoningEffort: 'low', serviceTier: 'default' });
60
+ let output = '';
61
+ const state = { cwd: root, write: (text) => { output += text; }, interactive: false };
62
+ await dispatchShellLine('/reasoning high', state);
63
+ assert.equal(readCliPreferences(root).reasoningEffort, 'high');
64
+ await dispatchShellLine('/fast', state);
65
+ assert.equal(readCliPreferences(root).serviceTier, 'fast');
66
+ await dispatchShellLine('/flex', state);
67
+ assert.equal(readCliPreferences(root).serviceTier, 'flex');
68
+ await dispatchShellLine('/standard', state);
69
+ assert.equal(readCliPreferences(root).serviceTier, 'default');
70
+ assert.match(output, /reasoning → high/);
71
+ assert.match(output, /Fast is a paid latency choice/);
72
+ assert.match(output, /Flex trades latency/);
73
+ });
74
+
75
+ test('bare /context shows truthful economics without inventing active token usage', async () => {
76
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agentsam-shell-context-'));
77
+ fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify({ name: 'context-demo' }));
78
+ writeCliPreferences(root, { trustedDirectory: true, modelPreference: 'openai:gpt-6-astra', reasoningEffort: 'medium', serviceTier: 'default' });
79
+ let output = '';
80
+ await dispatchShellLine('/context', { cwd: root, write: (text) => { output += text; }, interactive: false });
81
+ assert.match(output, /1,050,000/);
82
+ assert.match(output, /272,000/);
83
+ assert.match(output, /180,000/);
84
+ assert.match(output, /unavailable · no provider\/local usage snapshot yet/);
85
+ assert.match(output, /Batch is a separate asynchronous execution lane/);
86
+ });
87
+
51
88
  test('CLI supports a deterministic one-shot slash command for regression tests', () => {
52
- const result = spawnSync(process.execPath, ['src/cli.js', 'shell', '--command', '/help'], {
53
- cwd: repoRoot,
54
- encoding: 'utf8',
55
- });
89
+ const result = spawnSync(process.execPath, ['src/cli.js', 'shell', '--command', '/help'], { cwd: repoRoot, encoding: 'utf8' });
56
90
  assert.equal(result.status, 0, result.stderr);
57
91
  assert.match(result.stdout, /Agent Sam Terminal/);
58
- assert.match(result.stdout, /\/help/);
92
+ assert.match(result.stdout, /\/model/);
59
93
  assert.match(result.stdout, /\/exit/);
60
94
  });
@@ -0,0 +1,22 @@
1
+ import assert from 'node:assert/strict';
2
+ import test from 'node:test';
3
+ import { getSkill, listSkills, loadSkill } from '../src/skills/index.js';
4
+
5
+ test('portable skill registry exposes AgentSam Jr Dev by id and alias', () => {
6
+ const listed = listSkills();
7
+ assert.ok(listed.some((skill) => skill.id === 'agentsam-jr-dev'));
8
+
9
+ assert.equal(getSkill('agentsam_jr_dev')?.id, 'agentsam-jr-dev');
10
+ assert.equal(getSkill('jr-dev')?.id, 'agentsam-jr-dev');
11
+ });
12
+
13
+ test('AgentSam Jr Dev loads compact instructions and references on demand', () => {
14
+ const compact = loadSkill('agentsam-jr-dev');
15
+ assert.match(compact.instructions, /# AgentSam Jr Dev/);
16
+ assert.equal('references' in compact, false);
17
+
18
+ const full = loadSkill('agentsam_jr_dev', { references: true });
19
+ assert.equal(full.references.length, 2);
20
+ assert.match(full.references[0].content, /## HTTP/);
21
+ assert.match(full.references[1].content, /# Real Application Logic/);
22
+ });