Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

projection.ts

46 lines2.0 KB

1/**
2 * Workspace projection capability — provided by `withSandbox` and consumed by
3 * harness adapters (claude-code, codex, opencode) to idempotently
4 * project skills, plugins, and resolved secrets into the native harness format.
5 *
6 * The capability carries the raw provisioning inputs (skills, plugins, a
7 * resolve function for secret refs) together with a marker path that lets
8 * adapters guard the projection with a one-time idempotency file.
9 */
10import { createCapability } from '@tanstack/ai'
11import type { SecretRef } from './secrets'
12import type { WorkspaceSkill } from './workspace'
13​
14/**
15 * The shape provided to harness adapters via the sandbox projection capability.
16 * Harness adapters read this in their `chatStream` setup to project workspace
17 * inputs into their native format (MCP config, skills dirs, plugin installs).
18 */
19export interface WorkspaceProjection {
20 /** Skills declared on the workspace — MCP servers, file skills, git repos, etc. */
21 skills: Array<WorkspaceSkill>
22 /** Harness plugin identifiers to install idempotently. */
23 plugins: Array<string>
24 /**
25 * Resolve a SecretRef to its plaintext value. Bound to the workspace's
26 * secrets registry; throws when the ref is unknown.
27 */
28 resolveSecret: (ref: SecretRef) => string
29 /**
30 * Absolute path to the idempotency marker file. Harness adapters write this
31 * file after a successful projection so subsequent runs skip re-projection.
32 * The file is NOT included in snapshots — absent on restore, triggering
33 * re-projection (which re-writes any secret-bearing config files).
34 */
35 markerPath: string
36 /** Workspace root inside the sandbox (e.g. `/workspace`). */
37 root: string
38 /** Named commands declared on the workspace (e.g. `{ test: 'pnpm test' }`). */
39 scripts?: Record<string, string>
41​
42export const ProjectionCapability =
43 createCapability<WorkspaceProjection>()('sandbox-projection')
44​
45export const [getWorkspaceProjection, provideWorkspaceProjection] =
46 ProjectionCapability