Skip to content

The open-source agent harness - the runtime layer that turns an LLM into a working agent.

Release/v0.1.3 gateway migration (#2)

Srajan Asthana888bf74a0e59
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 67d4cd821..854654df7 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -34,14 +34,14 @@ jobs:
- name: Install dependencies
run: pnpm install --frozen-lockfile
+ - name: Build
+ run: pnpm build
+
- name: Format check
run: pnpm format:check
- name: Lint
run: pnpm lint:ci
- - name: Build
- run: pnpm build
-
- name: Test
run: pnpm test
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 86336e783..146e681b0 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -38,8 +38,11 @@ jobs:
exit 1
fi
+ # Publish from the staged dist/: dist/package.json is
+ # generated by the build with dist-relative paths, so the tarball root is
+ # the compiled file tree and deep imports have no dist/ segment.
- name: Publish
- working-directory: packages/harness
+ working-directory: packages/harness/dist
run: npm publish --access public
# TODO(oss): add --provenance once the repo is public. Do NOT add it now:
# provenance publicly attests the source repo and commit.
diff --git a/.gitignore b/.gitignore
index 6df4e9d02..6e72124be 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,3 +10,4 @@ coverage/
*.tsbuildinfo
.pnpm-store/
.eslintcache
+packages/harness/src/core/sandbox/sandboxScripts.gen.ts
diff --git a/README.md b/README.md
index 73222ee8c..0d59611f5 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@ pnpm workspace with:
| Package | Path | Role |
| --------------------- | -------------------------------------- | -------------------------------------------------- |
-| `@truefoundry/utils` | [`packages/harness`](packages/harness) | Published library (`core` + `agentSession`) |
+| `@truefoundry/utils` | [`packages/harness`](packages/harness) | Published library (`core` + `agent-session`) |
| `@truefoundry/server` | [`packages/server`](packages/server) | Future CLI/HTTP server (private; depends on utils) |
## Develop
diff --git a/RELEASING.md b/RELEASING.md
index 6fa38509d..acbe771eb 100644
--- a/RELEASING.md
+++ b/RELEASING.md
@@ -14,6 +14,22 @@ open-source release happens later — every deferred item carries a
> tsconfig.build.json), which embeds/references original TypeScript source in
> the published tarball — this is a deliberate, accepted trade-off for now.
+## Publishing model (openai-node style)
+
+The package publishes **from `packages/harness/dist`**, not the package
+folder. The build compiles every `src/**/*.ts` to its own `.js` (CJS) +
+`.mjs` (ESM) + `.d.ts` triple and generates `dist/package.json` with
+dist-relative paths (`scripts/make-dist-package-json.mjs`), so the tarball
+root is the compiled file tree. Consequences:
+
+- Deep imports mirror the source tree with no `dist/` segment:
+ `@truefoundry/utils/core/llm/LLMTypes`, `.../core/runtime/contextUtils`.
+- Legacy `moduleResolution: "node"` consumers (the gateway) resolve subpaths
+ as literal file lookups — no `exports`/`typesVersions` support needed.
+- `require()` and `import` both work (`.js` is CJS, `.mjs` is ESM).
+- The curated barrels (`.`, `./core`, `./agent-session`) remain the public
+ API; deep imports are the escape hatch for internals.
+
## Per-release flow
1. **Bump the version via PR** (direct pushes to `main` are blocked by org
@@ -38,9 +54,10 @@ open-source release happens later — every deferred item carries a
```
3. **CI publishes automatically.** `.github/workflows/release.yml` installs,
- builds, tests, verifies the tag matches `packages/harness/package.json`,
- and runs `npm publish` via trusted publishing (OIDC — no NPM_TOKEN
- anywhere). Watch it under the repo's Actions tab.
+ builds (which stages `dist/` with its own package.json and smoke-tests
+ it), tests, verifies the tag matches `packages/harness/package.json`, and
+ runs `npm publish` **from `packages/harness/dist`** via trusted publishing
+ (OIDC — no NPM_TOKEN anywhere). Watch it under the repo's Actions tab.
4. **Bump the pinned version in the gateway.** Pin exact versions (no `^`)
during the fast 0.x churn:
@@ -54,7 +71,7 @@ open-source release happens later — every deferred item carries a
For tight loops, skip the publish round-trip:
```bash
-cd packages/harness && pnpm build && pnpm pack
+cd packages/harness && pnpm build && cd dist && pnpm pack
```
Point the gateway at the tarball via a `file:` dependency (or use `yalc`).
@@ -77,7 +94,7 @@ Publish a real version when CI or teammates need it.
| Item | Where |
| ------------------------------------------------------------------------------- | ------------------------------------------------------- |
| License: UNLICENSED → Apache-2.0 + LICENSE file | both package.jsons, repo root |
-| Ship README / remove prepack guard / npmignore md-strip | packages/harness |
+| Ship README (guard lives in make-dist-package-json.mjs) | packages/harness/scripts |
| Add repository/homepage/bugs/keywords metadata | packages/harness/package.json |
| Add `--provenance` to publish | .github/workflows/release.yml |
| Replace `internal.devtest.truefoundry.tech` URLs | packages/server/src/config |
diff --git a/eslint.config.mjs b/eslint.config.mjs
index f423c1958..ec7c0c900 100644
--- a/eslint.config.mjs
+++ b/eslint.config.mjs
@@ -22,13 +22,15 @@ export default defineConfig(
files: ['**/*.{js,mjs,cjs}'],
extends: [tseslint.configs.disableTypeChecked],
languageOptions: {
- // Flat config does not support /* eslint-env node */; CJS configs need Node globals.
+ // Flat config does not support /* eslint-env node */; Node scripts and CJS configs need Node globals.
globals: {
module: 'readonly',
require: 'readonly',
__dirname: 'readonly',
__filename: 'readonly',
exports: 'writable',
+ console: 'readonly',
+ process: 'readonly',
},
},
},
diff --git a/package.json b/package.json
index 3d951c1f7..7873567e2 100644
--- a/package.json
+++ b/package.json
@@ -13,6 +13,7 @@
"test": "pnpm --filter @truefoundry/utils test",
"dev:server": "pnpm --filter @truefoundry/server dev",
"pack:dry": "pnpm --filter @truefoundry/utils pack:dry",
+ "postinstall": "pnpm --filter @truefoundry/utils build:gen",
"prepare": "husky || true"
},
"devDependencies": {
diff --git a/packages/harness/package.json b/packages/harness/package.json
index 993b01943..686b859ea 100644
--- a/packages/harness/package.json
+++ b/packages/harness/package.json
@@ -1,25 +1,42 @@
{
"name": "@truefoundry/utils",
- "version": "0.1.2",
+ "version": "0.1.3",
"description": "TrueFoundry agent core and session library",
"author": "Truefoundry",
"license": "UNLICENSED",
"private": false,
- "type": "module",
+ "type": "commonjs",
"main": "./dist/index.js",
+ "module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
- "import": "./dist/index.js"
+ "require": "./dist/index.js",
+ "default": "./dist/index.mjs"
},
"./core": {
"types": "./dist/core/index.d.ts",
- "import": "./dist/core/index.js"
+ "require": "./dist/core/index.js",
+ "default": "./dist/core/index.mjs"
},
"./agent-session": {
- "types": "./dist/agentSession/index.d.ts",
- "import": "./dist/agentSession/index.js"
+ "types": "./dist/agent-session/index.d.ts",
+ "require": "./dist/agent-session/index.js",
+ "default": "./dist/agent-session/index.mjs"
+ },
+ "./*.mjs": {
+ "types": "./dist/*.d.ts",
+ "default": "./dist/*.mjs"
+ },
+ "./*.js": {
+ "types": "./dist/*.d.ts",
+ "default": "./dist/*.js"
+ },
+ "./*": {
+ "types": "./dist/*.d.ts",
+ "require": "./dist/*.js",
+ "default": "./dist/*.mjs"
},
"./package.json": "./package.json"
},
@@ -27,14 +44,15 @@
"dist"
],
"scripts": {
- "build": "pnpm run build:js && pnpm run build:dts && pnpm run build:scripts",
+ "build": "pnpm run build:gen && pnpm run build:js && pnpm run build:dts && pnpm run build:pkg && pnpm run build:check",
+ "build:gen": "node scripts/generate-sandbox-scripts.mjs",
"build:js": "tsup",
"build:dts": "tsc -p tsconfig.build.json --emitDeclarationOnly",
- "build:scripts": "mkdir -p dist/sandbox-scripts && cp src/core/sandbox/scripts/*.py dist/sandbox-scripts/",
- "typecheck": "tsc --noEmit",
- "test": "jest --config jest.config.cjs --forceExit",
- "pack:dry": "pnpm pack --dry-run",
- "prepack": "node -e \"const fs=require('node:fs'); for (const f of fs.readdirSync('.')) { if (/^readme(\\.(md|txt|markdown))?$/i.test(f)) { console.error('Refusing to pack: remove '+f+' so the npm page has no README'); process.exit(1); } }\""
+ "build:pkg": "node scripts/make-dist-package-json.mjs",
+ "build:check": "node scripts/check-dist.mjs",
+ "typecheck": "pnpm run build:gen && tsc --noEmit",
+ "test": "pnpm run build:gen && jest --config jest.config.cjs --forceExit",
+ "pack:dry": "cd dist && pnpm pack --dry-run"
},
"dependencies": {
"@daytona/sdk": "^0.190.0",
@@ -57,6 +75,7 @@
"@types/jest": "^29.5.14",
"@types/node": "^24.12.0",
"@types/ws": "^8.5.10",
+ "esbuild-plugin-file-path-extensions": "^2.1.4",
"jest": "^29.7.0",
"tsup": "^8.5.0",
"typescript": "^7.0.2"
diff --git a/packages/harness/scripts/check-dist.mjs b/packages/harness/scripts/check-dist.mjs
new file mode 100644
index 000000000..44e08fccb
--- /dev/null
+++ b/packages/harness/scripts/check-dist.mjs
@@ -0,0 +1,53 @@
+// Post-build smoke tests, mirroring the tail of openai-node's build script:
+// the staged dist must be loadable via require() and import() at the root,
+// the subpath barrels, and a deep file path, with declarations beside them.
+import fs from 'node:fs';
+import { createRequire } from 'node:module';
+import path from 'node:path';
+import { fileURLToPath, pathToFileURL } from 'node:url';
+
+const pkgRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
+const require = createRequire(import.meta.url);
+
+const modulePaths = [
+ 'dist/index',
+ 'dist/core/index',
+ 'dist/agent-session/index',
+ // Deep paths: one class module, one dropped-from-the-barrel internals module.
+ 'dist/core/sandbox/Sandbox',
+ 'dist/core/runtime/contextUtils',
+];
+
+let failures = 0;
+
+for (const modulePath of modulePaths) {
+ const base = path.join(pkgRoot, modulePath);
+ try {
+ require(`${base}.js`);
+ await import(pathToFileURL(`${base}.mjs`).href);
+ if (!fs.existsSync(`${base}.d.ts`)) throw new Error('missing .d.ts');
+ console.log(`ok ${modulePath}.{js,mjs,d.ts}`);
+ } catch (error) {
+ failures += 1;
+ console.error(`FAIL ${modulePath}: ${error instanceof Error ? error.message : String(error)}`);
+ }
+}
+
+const distPkgPath = path.join(pkgRoot, 'dist', 'package.json');
+if (!fs.existsSync(distPkgPath)) {
+ failures += 1;
+ console.error('FAIL dist/package.json is missing (run build:pkg)');
+} else {
+ const distPkg = JSON.parse(fs.readFileSync(distPkgPath, 'utf-8'));
+ const staged = JSON.stringify(distPkg);
+ if (staged.includes('./dist/')) {
+ failures += 1;
+ console.error('FAIL dist/package.json still references ./dist/ paths');
+ }
+}
+
+if (failures > 0) {
+ console.error(`check-dist: ${failures} failure(s)`);
+ process.exit(1);
+}
+console.log('check-dist: all good');
diff --git a/packages/harness/scripts/generate-sandbox-scripts.mjs b/packages/harness/scripts/generate-sandbox-scripts.mjs
new file mode 100644
index 000000000..a94f06e66
--- /dev/null
+++ b/packages/harness/scripts/generate-sandbox-scripts.mjs
@@ -0,0 +1,24 @@
+/**
+ * Inlines the sandbox Python helper scripts into a generated TS module so
+ * `Sandbox` can self-serve its scripts with no loose files in the package.
+ * A plain generated `.ts` file works unchanged across tsup, plain `tsc`
+ * (the .d.ts build), and @swc/jest — no loaders or transforms needed.
+ *
+ * Runs via the `build:gen` script before build/typecheck/test. The generated
+ * output (src/core/sandbox/sandboxScripts.gen.ts) is gitignored.
+ */
+import { readFileSync, writeFileSync } from 'node:fs';
+import { dirname, join } from 'node:path';
+import { fileURLToPath } from 'node:url';
+
+const root = join(dirname(fileURLToPath(import.meta.url)), '..');
+const scriptsDir = join(root, 'src/core/sandbox/scripts');
+const read = f => readFileSync(join(scriptsDir, f), 'utf-8');
+
+const out = `// AUTO-GENERATED by scripts/generate-sandbox-scripts.mjs — do not edit.
+export const sandboxScripts = {
+ mcpClient: ${JSON.stringify(read('mcp_client.py'))},
+ skillDownloader: ${JSON.stringify(read('skill_downloader.py'))},
+} as const;
+`;
+writeFileSync(join(root, 'src/core/sandbox/sandboxScripts.gen.ts'), out);
diff --git a/packages/harness/scripts/make-dist-package-json.mjs b/packages/harness/scripts/make-dist-package-json.mjs
new file mode 100644
index 000000000..591f10abf
--- /dev/null
+++ b/packages/harness/scripts/make-dist-package-json.mjs
@@ -0,0 +1,40 @@
+// Generates dist/package.json so the package can be published from dist/,
+// making dist the package root: src/core/foo.ts is importable as @truefoundry/utils/core/foo
+import fs from 'node:fs';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
+
+const pkgRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
+const distDir = path.join(pkgRoot, 'dist');
+
+const pkg = JSON.parse(fs.readFileSync(path.join(pkgRoot, 'package.json'), 'utf-8'));
+
+// dist/ becomes the package root, so ./dist/foo.js is published as ./foo.js.
+function stripDistPrefix(value) {
+ if (typeof value === 'string') return value.replace(/^\.\/dist\//, './');
+ if (value && typeof value === 'object') {
+ return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, stripDistPrefix(entry)]));
+ }
+ return value;
+}
+
+const distPkg = {
+ ...pkg,
+ main: stripDistPrefix(pkg.main),
+ module: stripDistPrefix(pkg.module),
+ types: stripDistPrefix(pkg.types),
+ exports: stripDistPrefix(pkg.exports),
+ files: ['**/*'],
+};
+delete distPkg.scripts;
+delete distPkg.devDependencies;
+
+// Interim stance: the npm page must stay blank, so no README may ship.
+const readmes = fs.readdirSync(distDir).filter(name => /^readme(\.(md|txt|markdown))?$/i.test(name));
+if (readmes.length > 0) {
+ console.error(`Refusing to stage dist: remove ${readmes.join(', ')} so the npm page has no README`);
+ process.exit(1);
+}
+
+fs.writeFileSync(path.join(distDir, 'package.json'), `${JSON.stringify(distPkg, null, 2)}\n`);
+console.log('Wrote dist/package.json');
diff --git a/packages/harness/src/agentSession/ITurnResourceResolver.ts b/packages/harness/src/agent-session/ITurnResourceResolver.ts
similarity index 100%
rename from packages/harness/src/agentSession/ITurnResourceResolver.ts
rename to packages/harness/src/agent-session/ITurnResourceResolver.ts
diff --git a/packages/harness/src/agentSession/README.md b/packages/harness/src/agent-session/README.md
similarity index 100%
rename from packages/harness/src/agentSession/README.md
rename to packages/harness/src/agent-session/README.md
diff --git a/packages/harness/src/agentSession/SessionHandle.ts b/packages/harness/src/agent-session/SessionHandle.ts
similarity index 100%
rename from packages/harness/src/agentSession/SessionHandle.ts
rename to packages/harness/src/agent-session/SessionHandle.ts
diff --git a/packages/harness/src/agentSession/Sessions.ts b/packages/harness/src/agent-session/Sessions.ts
similarity index 100%
rename from packages/harness/src/agentSession/Sessions.ts
rename to packages/harness/src/agent-session/Sessions.ts
diff --git a/packages/harness/src/agentSession/TurnHandle.ts b/packages/harness/src/agent-session/TurnHandle.ts
similarity index 100%
rename from packages/harness/src/agentSession/TurnHandle.ts
rename to packages/harness/src/agent-session/TurnHandle.ts
diff --git a/packages/harness/src/agentSession/TurnResourceResolver.ts b/packages/harness/src/agent-session/TurnResourceResolver.ts
similarity index 100%
rename from packages/harness/src/agentSession/TurnResourceResolver.ts
rename to packages/harness/src/agent-session/TurnResourceResolver.ts
diff --git a/packages/harness/src/agentSession/builtinsFromSpec.ts b/packages/harness/src/agent-session/builtinsFromSpec.ts
similarity index 100%
rename from packages/harness/src/agentSession/builtinsFromSpec.ts
rename to packages/harness/src/agent-session/builtinsFromSpec.ts
diff --git a/packages/harness/src/agentSession/index.ts b/packages/harness/src/agent-session/index.ts
similarity index 100%
rename from packages/harness/src/agentSession/index.ts
rename to packages/harness/src/agent-session/index.ts
diff --git a/packages/harness/src/agentSession/models/SessionRecord.ts b/packages/harness/src/agent-session/models/SessionRecord.ts
similarity index 100%
rename from packages/harness/src/agentSession/models/SessionRecord.ts
rename to packages/harness/src/agent-session/models/SessionRecord.ts
diff --git a/packages/harness/src/agentSession/models/TurnRecord.ts b/packages/harness/src/agent-session/models/TurnRecord.ts
similarity index 100%
rename from packages/harness/src/agentSession/models/TurnRecord.ts
rename to packages/harness/src/agent-session/models/TurnRecord.ts
diff --git a/packages/harness/src/agentSession/schemas/agentSpec.ts b/packages/harness/src/agent-session/schemas/agentSpec.ts
similarity index 100%
rename from packages/harness/src/agentSession/schemas/agentSpec.ts
rename to packages/harness/src/agent-session/schemas/agentSpec.ts
diff --git a/packages/harness/src/agentSession/schemas/events.ts b/packages/harness/src/agent-session/schemas/events.ts
similarity index 100%
rename from packages/harness/src/agentSession/schemas/events.ts
rename to packages/harness/src/agent-session/schemas/events.ts
diff --git a/packages/harness/src/agentSession/schemas/pagination.ts b/packages/harness/src/agent-session/schemas/pagination.ts
similarity index 100%
rename from packages/harness/src/agentSession/schemas/pagination.ts
rename to packages/harness/src/agent-session/schemas/pagination.ts
diff --git a/packages/harness/src/agentSession/schemas/session.ts b/packages/harness/src/agent-session/schemas/session.ts
similarity index 100%
rename from packages/harness/src/agentSession/schemas/session.ts
rename to packages/harness/src/agent-session/schemas/session.ts
diff --git a/packages/harness/src/agentSession/schemas/turn.ts b/packages/harness/src/agent-session/schemas/turn.ts
similarity index 100%
rename from packages/harness/src/agentSession/schemas/turn.ts
rename to packages/harness/src/agent-session/schemas/turn.ts
diff --git a/packages/harness/src/agentSession/store/ISessionStore.ts b/packages/harness/src/agent-session/store/ISessionStore.ts
similarity index 100%
rename from packages/harness/src/agentSession/store/ISessionStore.ts
rename to packages/harness/src/agent-session/store/ISessionStore.ts
diff --git a/packages/harness/src/agentSession/store/InMemorySessionStore.ts b/packages/harness/src/agent-session/store/InMemorySessionStore.ts
similarity index 100%
rename from packages/harness/src/agentSession/store/InMemorySessionStore.ts
rename to packages/harness/src/agent-session/store/InMemorySessionStore.ts
diff --git a/packages/harness/src/agentSession/store/SessionStoreErrors.ts b/packages/harness/src/agent-session/store/SessionStoreErrors.ts
similarity index 100%
rename from packages/harness/src/agentSession/store/SessionStoreErrors.ts
rename to packages/harness/src/agent-session/store/SessionStoreErrors.ts
diff --git a/packages/harness/src/core/index.ts b/packages/harness/src/core/index.ts
index 34e32dcf5..f05eec8e6 100644
--- a/packages/harness/src/core/index.ts
+++ b/packages/harness/src/core/index.ts
@@ -6,7 +6,17 @@
// Runtime
export type { AgentDefinition } from './runtime/AgentDefinition';
export { AgentThread } from './runtime/AgentThread';
-export type { AgentInfo, AgentParent } from './runtime/AgentThread.types';
+export type {
+ AgentInfo,
+ AgentParent,
+ AgentSendInput,
+ AgentThreadAppendContext,
+ AgentThreadCreateSubAgent,
+ AgentThreadEvent,
+ AgentThreadExecutionEvent,
+ AgentThreadExecutionResult,
+ SubAgentCompletionMarker,
+} from './runtime/AgentThread.types';
export { AgentThreadOrchestrator } from './runtime/AgentThreadOrchestrator';
export type { CreateDynamicSubAgentThread } from './runtime/CreateDynamicSubAgentThread';
export { isAgentInputUserMessage, isEmptyMessageContent, isFileContentPart } from './runtime/UserInputMessage';
@@ -23,10 +33,18 @@ export type {
// Built-in factories
export { askUserQuestion } from './capabilities/builtins/AskUserQuestion';
-export { contextCompaction } from './capabilities/builtins/ContextCompaction';
+export {
+ DEFAULT_CONTEXT_COMPACTION_THRESHOLD_TOKENS,
+ contextCompaction,
+} from './capabilities/builtins/ContextCompaction';
export { currentDateTime } from './capabilities/builtins/CurrentDateTime';
export { SUB_AGENT_IDENTITY, dynamicSubAgents } from './capabilities/builtins/DynamicSubAgents';
-export { largeToolResponse } from './capabilities/builtins/LargeToolResponse';
+export {
+ DEFAULT_INDIVIDUAL_TOOL_TOKEN_THRESHOLD,
+ DEFAULT_PREVIEW_NUMBER_OF_CHARACTERS,
+ DEFAULT_TOTAL_TOOL_TOKEN_THRESHOLD,
+ largeToolResponse,
+} from './capabilities/builtins/LargeToolResponse';
export { openUI } from './capabilities/builtins/OpenUI';
// MCP contracts
@@ -52,17 +70,27 @@ export { RemoteMCP } from './mcp/RemoteMCP';
export type { RemoteMcpHeaders, ResolveHeadersResult } from './mcp/RemoteMCP';
export type { RemoteMcpConnection, RemoteMcpTransportType } from './mcp/remoteMcpClient';
export type { ToolSelectorConfig } from './mcp/ToolSelectorPolicy';
+export {
+ DEFAULT_DISABLE_TOOLS,
+ DEFAULT_ENABLE_TOOLS,
+ DEFAULT_PRELOAD_TOOLS,
+ DEFAULT_REQUIRE_APPROVAL_FOR_TOOLS,
+ REQUIRE_APPROVAL_TOOLS_SELECTOR_TAGS,
+ TOOLS_SELECTOR_TAGS,
+} from './mcp/toolSelectors';
export { ToolSet } from './mcp/ToolSet';
// LLM contracts
-export type { ILLM } from './llm/ILLM';
-export type { CompletionUsage, LLMUserMessage } from './llm/LLMTypes';
+export type { AgentMetadata, ILLM } from './llm/ILLM';
export { OpenAILLM } from './llm/OpenAILLM';
export { ResponseFormatSchema, toOpenAIResponseFormat } from './llm/responseFormat';
export type { ResponseFormat } from './llm/responseFormat';
// Event contracts
export {
+ ActionRequiredEventSchema,
+ AgentInputUserMessageSchema,
+ EventIdSchema,
EventType,
MCPAuthRequiredEventSchema,
MCPInitializeEventSchema,
@@ -71,15 +99,25 @@ export {
SandboxCreatedEventSchema,
ThreadCreatedEventSchema,
ThreadDoneEventSchema,
+ ThreadOverwriteContextEventSchema,
ToolApprovalRequiredEventSchema,
ToolResponseEventSchema,
ToolResponseRequiredEventSchema,
+ UserToolApprovalMessageSchema,
+ UserToolResponseMessageSchema,
newEventId,
} from './events/schema';
+export type {
+ AgentOutputEvent,
+ MCPAuthRequiredEvent,
+ MCPServerAuthInfo,
+ MCPServerInitInfo,
+ ThreadDoneEvent,
+ ThreadOverwriteContextEvent,
+} from './events/schema';
export { InternalEventType } from './runtime/AgentThread.types';
export type { AgentThreadSendBatch, ContextMessage } from './runtime/AgentThread.types';
export type { AgentThreadMetrics } from './runtime/metrics';
-export type { SandboxInfo } from './sandbox/Sandbox';
// Tracing
export type {
@@ -101,6 +139,9 @@ export {
} from './sandbox/provider/createSandboxProvider';
export type { CreateSandboxProviderInput, SandboxProviderSettings } from './sandbox/provider/createSandboxProvider';
export { DaytonaSandboxProvider } from './sandbox/provider/DaytonaProvider';
+export type { DaytonaSandboxSettings } from './sandbox/provider/DaytonaProvider';
export type { SandboxProvider } from './sandbox/provider/Provider';
export { TFYSandboxProvider } from './sandbox/provider/TFYSandboxProvider';
export { Sandbox } from './sandbox/Sandbox';
+export type { MountedSkill, SandboxInfo } from './sandbox/Sandbox';
+export { SandboxError } from './sandbox/SandboxErrors';
diff --git a/packages/harness/src/core/sandbox/Sandbox.ts b/packages/harness/src/core/sandbox/Sandbox.ts
index b1716fa9c..a98abd880 100644
--- a/packages/harness/src/core/sandbox/Sandbox.ts
+++ b/packages/harness/src/core/sandbox/Sandbox.ts
@@ -19,6 +19,7 @@ import { SANDBOX_FILE_UPLOADS_DIR, SANDBOX_NATS_WS_PORT } from './constants';
import { type SandboxProvider, ensureExecSuccess } from './provider/Provider';
import { validateNoPathTraversal, validateSandboxOwnedByTenant } from './SandboxErrors';
import { SandboxNatsBridge } from './SandboxNatsBridge';
+import { sandboxScripts } from './sandboxScripts.gen';
export interface SandboxInfo {
sandbox_id: string;
@@ -74,10 +75,6 @@ export interface SandboxOptions {
* instead. Must be `true` — approvals are always enabled (the kill switch is gone).
*/
blockDestructiveToolsInCodeMode: true;
- scripts: {
- mcpClient: string;
- skillDownloader: string;
- };
execExtraEnv?: Readonly<Record<string, string>> | undefined;
skillInitEnv?: Readonly<Record<string, string>> | undefined;
tracing: AgentTracing;
@@ -244,8 +241,11 @@ export class Sandbox extends LocalToolMCP {
this.fileDownloadEnabled = options.fileDownloadEnabled ?? false;
this.execExtraEnv = options.execExtraEnv;
this.skillInitEnv = options.skillInitEnv;
- this.mcpClientScriptBase64 = Buffer.from(options.scripts.mcpClient, 'utf-8').toString('base64');
- this.skillDownloaderScriptBase64 = Buffer.from(options.scripts.skillDownloader, 'utf-8').toString('base64');
+ // Scripts are internal to Sandbox: the upload paths, env contract, and prompt
+ // text are all hardcoded here, so injecting different content was never a
+ // real extension point. Consumers don't see or provide them.
+ this.mcpClientScriptBase64 = Buffer.from(sandboxScripts.mcpClient, 'utf-8').toString('base64');
+ this.skillDownloaderScriptBase64 = Buffer.from(sandboxScripts.skillDownloader, 'utf-8').toString('base64');
this.logger = options.logger.child({ module: 'Sandbox' });
this.resolvedGitCredentialsContent = options.resolvedGitCredentialsContent ?? null;
diff --git a/packages/harness/src/index.ts b/packages/harness/src/index.ts
index 38ea2bebd..2f70ee159 100644
--- a/packages/harness/src/index.ts
+++ b/packages/harness/src/index.ts
@@ -2,5 +2,5 @@
* Root barrel for @truefoundry/utils.
* Namespaced to avoid colliding event-schema exports between layers.
*/
-export * as agentSession from './agentSession';
+export * as agentSession from './agent-session';
export * as core from './core';
diff --git a/packages/harness/tests/agentSession/capabilityState.test.ts b/packages/harness/tests/agent-session/capabilityState.test.ts
similarity index 96%
rename from packages/harness/tests/agentSession/capabilityState.test.ts
rename to packages/harness/tests/agent-session/capabilityState.test.ts
index 528269692..9c58fac94 100644
--- a/packages/harness/tests/agentSession/capabilityState.test.ts
+++ b/packages/harness/tests/agent-session/capabilityState.test.ts
@@ -3,10 +3,10 @@
* Does not migrate private Plan / overwriteAgentPlan — gateway adoption is out of scope.
*/
import type { Logger } from 'winston';
-import { MAIN_THREAD_ID } from '../../src/agentSession/models/TurnRecord';
-import { EventType } from '../../src/agentSession/schemas/events';
-import { Sessions } from '../../src/agentSession/Sessions';
-import { InMemorySessionStore } from '../../src/agentSession/store/InMemorySessionStore';
+import { MAIN_THREAD_ID } from '../../src/agent-session/models/TurnRecord';
+import { EventType } from '../../src/agent-session/schemas/events';
+import { Sessions } from '../../src/agent-session/Sessions';
+import { InMemorySessionStore } from '../../src/agent-session/store/InMemorySessionStore';
import type { AgentCapability } from '../../src/core/capabilities/AgentCapability';
import type { AgentContextProcessorOutput } from '../../src/core/capabilities/AgentContextProcessor';
import { AgentThread } from '../../src/core/runtime/AgentThread';
diff --git a/packages/harness/tests/agentSession/inMemorySessionStore.test.ts b/packages/harness/tests/agent-session/inMemorySessionStore.test.ts
similarity index 98%
rename from packages/harness/tests/agentSession/inMemorySessionStore.test.ts
rename to packages/harness/tests/agent-session/inMemorySessionStore.test.ts
index a7b0da112..1bc97a60f 100644
--- a/packages/harness/tests/agentSession/inMemorySessionStore.test.ts
+++ b/packages/harness/tests/agent-session/inMemorySessionStore.test.ts
@@ -1,9 +1,9 @@
-import { MAIN_THREAD_ID } from '../../src/agentSession/models/TurnRecord';
-import type { PersistedTurnEvent } from '../../src/agentSession/schemas/events';
-import { CancellationReason } from '../../src/agentSession/schemas/turn';
-import type { ISessionStore } from '../../src/agentSession/store/ISessionStore';
-import { InMemorySessionStore } from '../../src/agentSession/store/InMemorySessionStore';
-import { SessionStoreConflictError, SessionStoreNotFoundError } from '../../src/agentSession/store/SessionStoreErrors';
+import { MAIN_THREAD_ID } from '../../src/agent-session/models/TurnRecord';
+import type { PersistedTurnEvent } from '../../src/agent-session/schemas/events';
+import { CancellationReason } from '../../src/agent-session/schemas/turn';
+import type { ISessionStore } from '../../src/agent-session/store/ISessionStore';
+import { InMemorySessionStore } from '../../src/agent-session/store/InMemorySessionStore';
+import { SessionStoreConflictError, SessionStoreNotFoundError } from '../../src/agent-session/store/SessionStoreErrors';
import { EventType, newEventId } from '../../src/core/events/schema';
import { getEmptyUsage } from '../../src/core/llm/LLMTypes';
import { makeAgentSpec, makeModelMessageEvent, makeRunningTurnRecord, makeTurnCreatedEvent } from './testHelpers';
diff --git a/packages/harness/tests/agentSession/sessions.test.ts b/packages/harness/tests/agent-session/sessions.test.ts
similarity index 96%
rename from packages/harness/tests/agentSession/sessions.test.ts
rename to packages/harness/tests/agent-session/sessions.test.ts
index 97f19fa40..a191e4f17 100644
--- a/packages/harness/tests/agentSession/sessions.test.ts
+++ b/packages/harness/tests/agent-session/sessions.test.ts
@@ -1,6 +1,6 @@
-import { EventType } from '../../src/agentSession/schemas/events';
-import { Sessions } from '../../src/agentSession/Sessions';
-import { InMemorySessionStore } from '../../src/agentSession/store/InMemorySessionStore';
+import { EventType } from '../../src/agent-session/schemas/events';
+import { Sessions } from '../../src/agent-session/Sessions';
+import { InMemorySessionStore } from '../../src/agent-session/store/InMemorySessionStore';
import { makeAgentSpec, makeTestResolver } from './testHelpers';
describe('Sessions / SessionHandle / TurnHandle (storage + run)', () => {
diff --git a/packages/harness/tests/agentSession/testHelpers.ts b/packages/harness/tests/agent-session/testHelpers.ts
similarity index 95%
rename from packages/harness/tests/agentSession/testHelpers.ts
rename to packages/harness/tests/agent-session/testHelpers.ts
index 9ef153db5..41e5410eb 100644
--- a/packages/harness/tests/agentSession/testHelpers.ts
+++ b/packages/harness/tests/agent-session/testHelpers.ts
@@ -1,7 +1,7 @@
-import type { ITurnResourceResolver } from '../../src/agentSession/ITurnResourceResolver';
-import { MAIN_THREAD_ID, type TurnRecord } from '../../src/agentSession/models/TurnRecord';
-import { AgentSpecSchema, type AgentSpec } from '../../src/agentSession/schemas/agentSpec';
-import { TurnResourceResolver } from '../../src/agentSession/TurnResourceResolver';
+import type { ITurnResourceResolver } from '../../src/agent-session/ITurnResourceResolver';
+import { MAIN_THREAD_ID, type TurnRecord } from '../../src/agent-session/models/TurnRecord';
+import { AgentSpecSchema, type AgentSpec } from '../../src/agent-session/schemas/agentSpec';
+import { TurnResourceResolver } from '../../src/agent-session/TurnResourceResolver';
import type { AgentCapability } from '../../src/core/capabilities/AgentCapability';
import { EventType, newEventId } from '../../src/core/events/schema';
import type { ExtendedChatCompletionChunk, RawAssistantMessageWithUsage } from '../../src/core/llm/LLMTypes';
diff --git a/packages/harness/tests/agentSession/turnStream.test.ts b/packages/harness/tests/agent-session/turnStream.test.ts
similarity index 95%
rename from packages/harness/tests/agentSession/turnStream.test.ts
rename to packages/harness/tests/agent-session/turnStream.test.ts
index f3c25942a..1bad5ed95 100644
--- a/packages/harness/tests/agentSession/turnStream.test.ts
+++ b/packages/harness/tests/agent-session/turnStream.test.ts
@@ -1,8 +1,8 @@
-import { EventType } from '../../src/agentSession/schemas/events';
-import { CancellationReason } from '../../src/agentSession/schemas/turn';
-import { Sessions } from '../../src/agentSession/Sessions';
-import { InMemorySessionStore } from '../../src/agentSession/store/InMemorySessionStore';
-import { TurnResourceResolver } from '../../src/agentSession/TurnResourceResolver';
+import { EventType } from '../../src/agent-session/schemas/events';
+import { CancellationReason } from '../../src/agent-session/schemas/turn';
+import { Sessions } from '../../src/agent-session/Sessions';
+import { InMemorySessionStore } from '../../src/agent-session/store/InMemorySessionStore';
+import { TurnResourceResolver } from '../../src/agent-session/TurnResourceResolver';
import { RemoteMCP } from '../../src/core/mcp/RemoteMCP';
import { makeStubPublicSandbox } from '../core/harnessMocks';
import { emptyLlmStream, makeAgentSpec, makeMockILLM, makeSilentLogger, makeTestResolver } from './testHelpers';
diff --git a/packages/harness/tests/core/harnessMocks.ts b/packages/harness/tests/core/harnessMocks.ts
index 432c8108c..6d307915e 100644
--- a/packages/harness/tests/core/harnessMocks.ts
+++ b/packages/harness/tests/core/harnessMocks.ts
@@ -70,7 +70,6 @@ export function makeStubPublicSandbox(tenantName = 'test-tenant'): Sandbox {
provider,
blockDestructiveToolsInCodeMode: true,
execExtraEnv: { TFY_TENANT_NAME: tenantName },
- scripts: { mcpClient: '# mcp', skillDownloader: '# skills' },
logger: makeSilentLogger(),
tracing: NOOP_AGENT_TRACING,
});
diff --git a/packages/harness/tsup.config.ts b/packages/harness/tsup.config.ts
index 247bc64e3..7bae0eac5 100644
--- a/packages/harness/tsup.config.ts
+++ b/packages/harness/tsup.config.ts
@@ -1,31 +1,21 @@
+import { esbuildPluginFilePathExtensions } from 'esbuild-plugin-file-path-extensions';
import { defineConfig } from 'tsup';
+// every src module compiles to its own .js (CJS) + .mjs (ESM) pair so consumers can deep-import real file paths.
export default defineConfig({
- entry: {
- index: 'src/index.ts',
- 'core/index': 'src/core/index.ts',
- 'agentSession/index': 'src/agentSession/index.ts',
- },
- format: ['esm'],
+ entry: ['src/**/*.ts'],
+ format: ['esm', 'cjs'],
+ // The plugin externalizes relative imports and rewrites extensionless
+ // specifiers per format ('./foo' -> './foo.mjs' / './foo.js'). It requires
+ // bundle mode, but with every file as an entry nothing actually inlines.
+ bundle: true,
+ esbuildPlugins: [esbuildPluginFilePathExtensions({ esmExtension: 'mjs', cjsExtension: 'js' })],
dts: false,
splitting: false,
+ // TODO(oss): revisit sourcemaps at the public release — with sourcesContent
sourcemap: true,
clean: true,
target: 'esnext',
outDir: 'dist',
- external: [
- '@daytona/sdk',
- '@hono/zod-openapi',
- '@modelcontextprotocol/sdk',
- '@nats-io/nats-core',
- '@opentelemetry/api',
- '@opentelemetry/core',
- 'dedent',
- 'openai',
- 'ulid',
- 'winston',
- 'ws',
- 'zod',
- 'zod-to-json-schema',
- ],
+ skipNodeModulesBundle: true,
});
diff --git a/packages/server/src/runtime/sandboxFactory.ts b/packages/server/src/runtime/sandboxFactory.ts
index 38a570ec1..fd201fee7 100644
--- a/packages/server/src/runtime/sandboxFactory.ts
+++ b/packages/server/src/runtime/sandboxFactory.ts
@@ -10,26 +10,11 @@
*/
import type { TurnSandboxFactory } from '@truefoundry/utils/agent-session';
import { createSandboxProvider, Sandbox, SandboxProviderSettingsSchema } from '@truefoundry/utils/core';
-import { readFileSync } from 'node:fs';
-import { createRequire } from 'node:module';
-import { dirname, join } from 'node:path';
import type { Logger } from 'winston';
import { ZodError } from 'zod';
import { TENANT_NAME } from '../apis/sessions';
import configuration from '../config/config';
-// Python helpers ship with @truefoundry/utils under dist/sandbox-scripts.
-const require = createRequire(import.meta.url);
-const UTILS_ROOT = dirname(require.resolve('@truefoundry/utils/package.json'));
-const SCRIPTS_DIR = join(UTILS_ROOT, 'dist/sandbox-scripts');
-
-function loadSandboxScripts(): { mcpClient: string; skillDownloader: string } {
- return {
- mcpClient: readFileSync(join(SCRIPTS_DIR, 'mcp_client.py'), 'utf-8'),
- skillDownloader: readFileSync(join(SCRIPTS_DIR, 'skill_downloader.py'), 'utf-8'),
- };
-}
-
function parseSandboxSettings(rawJson: string) {
let raw: unknown;
try {
@@ -80,7 +65,6 @@ export function createServerSandboxFactory(deps: { logger: Logger }): TurnSandbo
previewUrlExpirySeconds: configuration.SANDBOX_PREVIEW_URL_EXPIRY_SECONDS,
logger,
});
- const scripts = loadSandboxScripts();
// TODO(skills): wire the complete skills flow. Spec-declared skills (from
// skills.yaml) should be resolved to MountedSkill[] and passed as
@@ -95,7 +79,6 @@ export function createServerSandboxFactory(deps: { logger: Logger }): TurnSandbo
existingSandboxId,
fileDownloadEnabled: spec.config?.sandbox?.file_downloads ?? false,
blockDestructiveToolsInCodeMode: true,
- scripts,
// Sandbox reads its tenant from TFY_TENANT_NAME (see Sandbox constructor)
// for the ownership check against provider-created sandbox ids
// (`<tenant>.<uuid>`). Must match the tenantName given to the provider.
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index b54b26f95..d958a23fe 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -87,6 +87,9 @@ importers:
'@types/ws':
specifier: ^8.5.10
version: 8.18.1
+ esbuild-plugin-file-path-extensions:
+ specifier: ^2.1.4
+ version: 2.1.4
jest:
specifier: ^29.7.0
version: 29.7.0(@types/[email protected])([email protected])
@@ -2134,6 +2137,10 @@ packages:
resolution: {integrity: sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==}
engines: {node: '>= 0.4'}
+ resolution: {integrity: sha512-lNjylaAsJMprYg28zjUyBivP3y0ms9b7RJZ5tdhDUFLa3sCbqZw4wDnbFUSmnyZYWhCYDPxxp7KkXM2TXGw3PQ==}
+ engines: {node: '>=v14.0.0', npm: '>=7.0.0'}
+
resolution: {integrity: sha512-IxpibTjyVnmrIQo5aqNpCgoACA/dTKLTlhMHihVHhdkxKyPO1uBBthumT0rdHmcsk9uMonIWS0m4FljWzILh3w==}
engines: {node: '>=18'}
@@ -5680,6 +5687,8 @@ snapshots:
has-tostringtag: 1.0.2
hasown: 2.0.4
+
optionalDependencies:
'@esbuild/aix-ppc64': 0.27.7