@flowdular/sdk 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.ai/skills/test-hardening/SKILL.md +1 -1
- package/README.md +69 -12
- package/assets/flowdular-banner.png +0 -0
- package/modules/agents/package.json +1 -1
- package/modules/auth/package.json +1 -1
- package/modules/auth/src/client/AuthenticationCore.tsrx +3 -1
- package/modules/auth/src/server/endpoints.ts +3 -1
- package/modules/auth/src/server/runtime.ts +4 -0
- package/modules/automations/package.json +1 -1
- package/modules/automations-workflows-integration/package.json +1 -1
- package/modules/profile/package.json +1 -1
- package/modules/sandbox/package.json +1 -1
- package/modules/system/package.json +1 -1
- package/modules/users/package.json +1 -1
- package/modules/workflows/package.json +1 -1
- package/package.json +5 -13
- package/packages/ai-provider/package.json +1 -1
- package/packages/cli-protocol/package.json +1 -1
- package/packages/client/package.json +1 -1
- package/packages/client/src/routing.ts +39 -2
- package/packages/client/src/shell/BrandMark.tsrx +5 -1
- package/packages/client/src/shell/navigation.ts +3 -1
- package/packages/client/src/state.ts +6 -2
- package/packages/contracts/package.json +1 -1
- package/packages/contracts/schemas/project.schema.json +16 -42
- package/packages/database/package.json +1 -1
- package/packages/database-pglite/package.json +2 -2
- package/packages/database-pglite/src/driver.ts +21 -3
- package/packages/database-testing/package.json +1 -1
- package/packages/dev-console/package.json +1 -1
- package/packages/harness/package.json +1 -1
- package/packages/kernel/package.json +1 -1
- package/packages/server/package.json +1 -1
- package/packages/server/src/application-routes.ts +80 -8
- package/packages/server/src/index.ts +4 -1
- package/packages/server/src/web-html.ts +9 -5
- package/packages/server/src/web.ts +59 -7
- package/packages/ui/package.json +1 -1
- package/packages/coding-agent/package.json +0 -44
- package/packages/coding-agent/src/drivers/byok.ts +0 -322
- package/packages/coding-agent/src/drivers/claude-code.ts +0 -290
- package/packages/coding-agent/src/drivers/codex.ts +0 -281
- package/packages/coding-agent/src/index.ts +0 -56
- package/packages/coding-agent/src/registry.ts +0 -119
- package/packages/coding-agent/src/roles/contract.ts +0 -60
- package/packages/coding-agent/src/roles/defaults.ts +0 -134
- package/packages/coding-agent/src/roles/handoff.ts +0 -41
- package/packages/coding-agent/src/roles/registry.ts +0 -156
- package/packages/coding-agent/src/roles/skills.ts +0 -72
- package/packages/coding-agent/src/roles/sync.ts +0 -88
- package/packages/coding-agent/src/types.ts +0 -102
- package/packages/coding-agent/src/workspace.ts +0 -275
- package/packages/sandbox/README.md +0 -691
- package/packages/sandbox/bin/flowdular-sandbox.mjs +0 -393
- package/packages/sandbox/dist/client/assets/App-ClMOrpyg.js +0 -11
- package/packages/sandbox/dist/client/assets/PreviewHost-BHiHrfbQ.js +0 -1
- package/packages/sandbox/dist/client/assets/auto-buGEq6de.js +0 -3
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-400-normal-BSMlKf0J.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-400-normal-CEL4l2ZJ.woff +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-500-normal-Ael50iVv.woff +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-500-normal-Bq9vWWag.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-ext-400-normal-DMdlQ8Kv.woff +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-ext-400-normal-xuaO2J-f.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-ext-500-normal-BIfNGwUT.woff +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-ext-500-normal-BqneJy0T.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-500-normal-CB9ihrfo.woff +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-500-normal-DSY6xOcd.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-ext-400-normal-BmRBH3aV.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-ext-400-normal-D3D2R8hC.woff +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-ext-500-normal-CAhNIIs5.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-ext-500-normal-CZ70TYgx.woff +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-vietnamese-400-normal-BulugwFq.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-vietnamese-400-normal-DDuiU_S-.woff +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-vietnamese-500-normal-C8zxqsMH.woff +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-vietnamese-500-normal-DZ4AoWbu.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-sans-cyrillic-ext-wght-normal-d45eAU9y.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-sans-cyrillic-wght-normal-BAAhND-U.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-sans-greek-wght-normal-CmyJS8uq.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-sans-latin-ext-wght-normal-CIII54If.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-sans-latin-wght-normal-IvpUvPa2.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-sans-vietnamese-wght-normal-Dg1JeJN0.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/index-CvwhlQ87.js +0 -4
- package/packages/sandbox/dist/client/assets/styles-BPWaGf55.js +0 -3
- package/packages/sandbox/dist/client/assets/styles-Dx1_KOag.css +0 -1
- package/packages/sandbox/dist/client/favicon.svg +0 -1
- package/packages/sandbox/dist/server/assets/auto-CVGNYyb3.js +0 -12785
- package/packages/sandbox/dist/server/assets/chunk-DDJLRBDX-3OUNo51g.js +0 -4125
- package/packages/sandbox/dist/server/assets/nodefs-DVSI7kG0.js +0 -24
- package/packages/sandbox/dist/server/assets/opfs-ahp-D56iokt1.js +0 -388
- package/packages/sandbox/dist/server/assets/token-Bvaq7Anz.js +0 -55
- package/packages/sandbox/dist/server/assets/token-util-BqSvdIPQ.js +0 -3
- package/packages/sandbox/dist/server/assets/token-util-CktFFT4z.js +0 -494
- package/packages/sandbox/dist/server/entry.js +0 -91671
- package/packages/sandbox/dist/server/favicon.svg +0 -1
- package/packages/sandbox/dist/server/index.html +0 -161
- package/packages/sandbox/index.html +0 -159
- package/packages/sandbox/octane.config.ts +0 -36
- package/packages/sandbox/package.json +0 -83
- package/packages/sandbox/public/favicon.svg +0 -1
- package/packages/sandbox/public/og.png +0 -0
- package/packages/sandbox/src/App.tsrx +0 -924
- package/packages/sandbox/src/client/ApprovalHandoff.tsrx +0 -39
- package/packages/sandbox/src/client/ChatPane.tsrx +0 -694
- package/packages/sandbox/src/client/ConnectView.tsrx +0 -86
- package/packages/sandbox/src/client/DiffPane.tsrx +0 -150
- package/packages/sandbox/src/client/EjectModal.tsrx +0 -571
- package/packages/sandbox/src/client/GateResults.tsrx +0 -60
- package/packages/sandbox/src/client/GitHubSettingsModal.tsrx +0 -219
- package/packages/sandbox/src/client/NewSessionForm.tsrx +0 -214
- package/packages/sandbox/src/client/SessionBar.tsrx +0 -151
- package/packages/sandbox/src/client/SessionPicker.tsrx +0 -472
- package/packages/sandbox/src/client/SpecEditor.tsrx +0 -109
- package/packages/sandbox/src/client/SpecReviewCard.tsrx +0 -321
- package/packages/sandbox/src/client/WorkCard.tsrx +0 -128
- package/packages/sandbox/src/client/WorkbenchModal.tsrx +0 -161
- package/packages/sandbox/src/client/WorkspaceMenu.tsrx +0 -100
- package/packages/sandbox/src/client/api.ts +0 -797
- package/packages/sandbox/src/client/attachments.ts +0 -73
- package/packages/sandbox/src/client/dashboard.ts +0 -46
- package/packages/sandbox/src/client/github-settings.ts +0 -48
- package/packages/sandbox/src/client/highlight.ts +0 -105
- package/packages/sandbox/src/client/i18n.ts +0 -32
- package/packages/sandbox/src/client/locales/en.json +0 -466
- package/packages/sandbox/src/client/locales/pl.json +0 -466
- package/packages/sandbox/src/client/session-labels.ts +0 -77
- package/packages/sandbox/src/client/state.ts +0 -108
- package/packages/sandbox/src/index.ts +0 -10
- package/packages/sandbox/src/preview/PreviewHost.tsrx +0 -373
- package/packages/sandbox/src/preview/load-module.ts +0 -16
- package/packages/sandbox/src/server/attachments.ts +0 -308
- package/packages/sandbox/src/server/auto-review.ts +0 -181
- package/packages/sandbox/src/server/checkpoints.ts +0 -90
- package/packages/sandbox/src/server/config.ts +0 -460
- package/packages/sandbox/src/server/dashboard.ts +0 -245
- package/packages/sandbox/src/server/delivery/configuration.ts +0 -193
- package/packages/sandbox/src/server/delivery/git-pr.ts +0 -1473
- package/packages/sandbox/src/server/delivery/index.ts +0 -83
- package/packages/sandbox/src/server/delivery/local.ts +0 -151
- package/packages/sandbox/src/server/delivery/official-modules.ts +0 -516
- package/packages/sandbox/src/server/delivery/plan.ts +0 -218
- package/packages/sandbox/src/server/delivery/policies.ts +0 -239
- package/packages/sandbox/src/server/delivery/record.ts +0 -41
- package/packages/sandbox/src/server/delivery/steps.ts +0 -464
- package/packages/sandbox/src/server/delivery/types.ts +0 -158
- package/packages/sandbox/src/server/dependencies.ts +0 -88
- package/packages/sandbox/src/server/diff.ts +0 -230
- package/packages/sandbox/src/server/gates.ts +0 -388
- package/packages/sandbox/src/server/index.ts +0 -139
- package/packages/sandbox/src/server/path-guard.ts +0 -282
- package/packages/sandbox/src/server/planning.ts +0 -749
- package/packages/sandbox/src/server/platform-client.ts +0 -189
- package/packages/sandbox/src/server/preview-database-host.ts +0 -340
- package/packages/sandbox/src/server/preview-database-protocol.ts +0 -163
- package/packages/sandbox/src/server/preview-database-proxy.ts +0 -356
- package/packages/sandbox/src/server/preview-database.ts +0 -109
- package/packages/sandbox/src/server/preview-ipc.ts +0 -15
- package/packages/sandbox/src/server/preview-modules.ts +0 -83
- package/packages/sandbox/src/server/preview-revision.ts +0 -44
- package/packages/sandbox/src/server/preview-runtime.ts +0 -467
- package/packages/sandbox/src/server/preview-worker-manager.ts +0 -436
- package/packages/sandbox/src/server/preview-worker.ts +0 -168
- package/packages/sandbox/src/server/reference.ts +0 -251
- package/packages/sandbox/src/server/routes.ts +0 -2258
- package/packages/sandbox/src/server/runtime.ts +0 -188
- package/packages/sandbox/src/server/session-owner.ts +0 -23
- package/packages/sandbox/src/server/sessions.ts +0 -849
- package/packages/sandbox/src/server/spec.ts +0 -471
- package/packages/sandbox/src/server/turn-lifecycle.ts +0 -56
- package/packages/sandbox/src/server/turns.ts +0 -993
- package/packages/sandbox/src/server/workspace-install.ts +0 -266
- package/packages/sandbox/src/server/workspace-root.ts +0 -73
- package/packages/sandbox/src/styles.css +0 -1573
- package/packages/sandbox/vite.config.ts +0 -133
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import type { AiUsage } from '@flowdular/sdk/ai-provider';
|
|
2
|
-
|
|
3
|
-
/* A sandbox that cannot prove it is loopback treats itself as self-hosted and
|
|
4
|
-
never offers a driver that shells out to a local binary. */
|
|
5
|
-
export type SandboxRuntimeMode = 'loopback' | 'self-hosted';
|
|
6
|
-
|
|
7
|
-
export type CodingAgentDriverKind = 'local-cli' | 'byok';
|
|
8
|
-
|
|
9
|
-
export type FileChangeKind = 'created' | 'modified' | 'deleted';
|
|
10
|
-
|
|
11
|
-
export type CodingAgentEvent =
|
|
12
|
-
| {
|
|
13
|
-
readonly type: 'turn.started';
|
|
14
|
-
readonly driver: string;
|
|
15
|
-
readonly role: string;
|
|
16
|
-
readonly resumeId: string | null;
|
|
17
|
-
}
|
|
18
|
-
| { readonly type: 'assistant.message'; readonly text: string }
|
|
19
|
-
| { readonly type: 'reasoning'; readonly text: string }
|
|
20
|
-
| {
|
|
21
|
-
readonly type: 'tool.started';
|
|
22
|
-
readonly tool: string;
|
|
23
|
-
readonly detail: string;
|
|
24
|
-
}
|
|
25
|
-
| {
|
|
26
|
-
readonly type: 'tool.completed';
|
|
27
|
-
readonly tool: string;
|
|
28
|
-
readonly detail: string;
|
|
29
|
-
readonly ok: boolean;
|
|
30
|
-
}
|
|
31
|
-
| {
|
|
32
|
-
readonly type: 'file.changed';
|
|
33
|
-
readonly path: string;
|
|
34
|
-
readonly change: FileChangeKind;
|
|
35
|
-
}
|
|
36
|
-
| {
|
|
37
|
-
readonly type: 'error';
|
|
38
|
-
readonly code: string;
|
|
39
|
-
readonly message: string;
|
|
40
|
-
}
|
|
41
|
-
| {
|
|
42
|
-
readonly type: 'turn.completed';
|
|
43
|
-
readonly resumeId: string | null;
|
|
44
|
-
readonly usage: AiUsage;
|
|
45
|
-
readonly costUsd: number | null;
|
|
46
|
-
readonly finishReason: 'stop' | 'error' | 'aborted';
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export interface CodingAgentMessage {
|
|
50
|
-
readonly role: 'user' | 'assistant';
|
|
51
|
-
readonly text: string;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export interface CodingAgentTurnRequest {
|
|
55
|
-
/* The only directory the driver may read from or write to. */
|
|
56
|
-
readonly workspacePath: string;
|
|
57
|
-
/* Writes are narrower than reads. The orchestrator expands the active
|
|
58
|
-
role's globs to the one draft module owned by this turn. */
|
|
59
|
-
readonly allowedPaths?: readonly string[] | undefined;
|
|
60
|
-
readonly role: string;
|
|
61
|
-
readonly systemInstruction: string;
|
|
62
|
-
readonly prompt: string;
|
|
63
|
-
/* Provider-side conversation identifier returned by an earlier turn. */
|
|
64
|
-
readonly resumeId?: string | null;
|
|
65
|
-
/* Prior turns of this session. Drivers backed by a stateful CLI ignore it
|
|
66
|
-
and resume by identifier; the BYOK driver replays it. */
|
|
67
|
-
readonly history?: readonly CodingAgentMessage[] | undefined;
|
|
68
|
-
readonly model?: string | null;
|
|
69
|
-
readonly signal?: AbortSignal | undefined;
|
|
70
|
-
readonly timeoutMs?: number | undefined;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export interface CodingAgentAvailability {
|
|
74
|
-
readonly available: boolean;
|
|
75
|
-
readonly detail: string;
|
|
76
|
-
readonly version: string | null;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export interface CodingAgentDriverInfo {
|
|
80
|
-
readonly id: string;
|
|
81
|
-
readonly label: string;
|
|
82
|
-
readonly kind: CodingAgentDriverKind;
|
|
83
|
-
/* Local binaries carry the operator's own login and file system reach, so
|
|
84
|
-
they are offered only by a loopback sandbox. */
|
|
85
|
-
readonly requiresLoopback: boolean;
|
|
86
|
-
readonly description: string;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export interface CodingAgentDriver extends CodingAgentDriverInfo {
|
|
90
|
-
probe(): Promise<CodingAgentAvailability>;
|
|
91
|
-
run(request: CodingAgentTurnRequest): AsyncIterable<CodingAgentEvent>;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export class CodingAgentError extends Error {
|
|
95
|
-
constructor(
|
|
96
|
-
readonly code: string,
|
|
97
|
-
message: string,
|
|
98
|
-
) {
|
|
99
|
-
super(message);
|
|
100
|
-
this.name = 'CodingAgentError';
|
|
101
|
-
}
|
|
102
|
-
}
|
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process';
|
|
2
|
-
import { lstat, realpath } from 'node:fs/promises';
|
|
3
|
-
import { createInterface } from 'node:readline';
|
|
4
|
-
import { isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
5
|
-
import { CodingAgentError } from './types.ts';
|
|
6
|
-
|
|
7
|
-
/* Every path a driver touches is resolved against the session workspace and
|
|
8
|
-
rejected when it escapes, so a prompt cannot reach the real module tree. */
|
|
9
|
-
export function resolveInsideWorkspace(
|
|
10
|
-
workspacePath: string,
|
|
11
|
-
candidate: string,
|
|
12
|
-
): string {
|
|
13
|
-
const root = resolve(workspacePath);
|
|
14
|
-
const absolute = isAbsolute(candidate)
|
|
15
|
-
? resolve(candidate)
|
|
16
|
-
: resolve(root, candidate);
|
|
17
|
-
const fromRoot = relative(root, absolute);
|
|
18
|
-
if (fromRoot.startsWith('..') || isAbsolute(fromRoot)) {
|
|
19
|
-
throw new CodingAgentError(
|
|
20
|
-
'PATH_ESCAPES_WORKSPACE',
|
|
21
|
-
`Path escapes the session workspace: ${candidate}`,
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
return absolute;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function workspaceRelative(
|
|
28
|
-
workspacePath: string,
|
|
29
|
-
candidate: string,
|
|
30
|
-
): string {
|
|
31
|
-
const root = resolve(workspacePath);
|
|
32
|
-
const absolute = isAbsolute(candidate)
|
|
33
|
-
? resolve(candidate)
|
|
34
|
-
: resolve(root, candidate);
|
|
35
|
-
const fromRoot = relative(root, absolute);
|
|
36
|
-
return fromRoot === '' ? '.' : fromRoot;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const PROTECTED_WRITE_SEGMENTS = new Set([
|
|
40
|
-
'node_modules',
|
|
41
|
-
'.git',
|
|
42
|
-
'dist',
|
|
43
|
-
'.turbo',
|
|
44
|
-
]);
|
|
45
|
-
|
|
46
|
-
function normalPath(value: string): string {
|
|
47
|
-
return value.split(sep).join('/');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function matchesPath(path: string, pattern: string): boolean {
|
|
51
|
-
const source = pattern
|
|
52
|
-
.split(/(\*\*|\*)/)
|
|
53
|
-
.map((part) => {
|
|
54
|
-
if (part === '**') return '.*';
|
|
55
|
-
if (part === '*') return '[^/]*';
|
|
56
|
-
return part.replace(/[.+?^$()|[\]\\]/g, '\\$&');
|
|
57
|
-
})
|
|
58
|
-
.join('');
|
|
59
|
-
return new RegExp(`^${source}$`).test(path);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function assertUnprotected(path: string): void {
|
|
63
|
-
if (
|
|
64
|
-
path.split('/').some((segment) => PROTECTED_WRITE_SEGMENTS.has(segment))
|
|
65
|
-
) {
|
|
66
|
-
throw new CodingAgentError(
|
|
67
|
-
'PATH_NOT_ALLOWED',
|
|
68
|
-
`The coding agent cannot change protected workspace path: ${path}`,
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function assertContained(root: string, candidate: string): void {
|
|
74
|
-
const fromRoot = relative(root, candidate);
|
|
75
|
-
if (fromRoot.startsWith('..') || isAbsolute(fromRoot)) {
|
|
76
|
-
throw new CodingAgentError(
|
|
77
|
-
'PATH_ESCAPES_WORKSPACE',
|
|
78
|
-
'The path resolves through a symbolic link outside the session workspace.',
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/* Check every existing component rather than only the lexical path. Without
|
|
84
|
-
this, `module/node_modules/pkg/file` can follow a workspace symlink and let a
|
|
85
|
-
model read or overwrite the host package or pnpm store. */
|
|
86
|
-
async function assertPhysicalContainment(
|
|
87
|
-
workspacePath: string,
|
|
88
|
-
absolute: string,
|
|
89
|
-
): Promise<void> {
|
|
90
|
-
const lexicalRoot = resolve(workspacePath);
|
|
91
|
-
const physicalRoot = await realpath(lexicalRoot);
|
|
92
|
-
const fromRoot = relative(lexicalRoot, absolute);
|
|
93
|
-
let cursor = physicalRoot;
|
|
94
|
-
for (const segment of fromRoot.split(sep).filter(Boolean)) {
|
|
95
|
-
cursor = join(cursor, segment);
|
|
96
|
-
try {
|
|
97
|
-
const info = await lstat(cursor);
|
|
98
|
-
if (info.isSymbolicLink()) cursor = await realpath(cursor);
|
|
99
|
-
assertContained(physicalRoot, cursor);
|
|
100
|
-
} catch (error) {
|
|
101
|
-
if (
|
|
102
|
-
error &&
|
|
103
|
-
typeof error === 'object' &&
|
|
104
|
-
'code' in error &&
|
|
105
|
-
(error as { code?: string }).code === 'ENOENT'
|
|
106
|
-
) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
throw error;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export async function resolveReadableInsideWorkspace(
|
|
115
|
-
workspacePath: string,
|
|
116
|
-
candidate: string,
|
|
117
|
-
): Promise<string> {
|
|
118
|
-
const absolute = resolveInsideWorkspace(workspacePath, candidate);
|
|
119
|
-
const path = normalPath(workspaceRelative(workspacePath, absolute));
|
|
120
|
-
assertUnprotected(path);
|
|
121
|
-
await assertPhysicalContainment(workspacePath, absolute);
|
|
122
|
-
return absolute;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export async function resolveWritableInsideWorkspace(
|
|
126
|
-
workspacePath: string,
|
|
127
|
-
candidate: string,
|
|
128
|
-
allowedPaths: readonly string[],
|
|
129
|
-
): Promise<string> {
|
|
130
|
-
const absolute = resolveInsideWorkspace(workspacePath, candidate);
|
|
131
|
-
const path = normalPath(workspaceRelative(workspacePath, absolute));
|
|
132
|
-
assertUnprotected(path);
|
|
133
|
-
if (!allowedPaths.some((pattern) => matchesPath(path, pattern))) {
|
|
134
|
-
throw new CodingAgentError(
|
|
135
|
-
'PATH_NOT_ALLOWED',
|
|
136
|
-
`The coding agent cannot change a path outside its role allowlist: ${path}`,
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
await assertPhysicalContainment(workspacePath, absolute);
|
|
140
|
-
return absolute;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export interface ProcessLineStream {
|
|
144
|
-
readonly lines: AsyncIterable<string>;
|
|
145
|
-
readonly finished: Promise<{
|
|
146
|
-
readonly code: number | null;
|
|
147
|
-
readonly stderr: string;
|
|
148
|
-
readonly aborted: boolean;
|
|
149
|
-
}>;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export interface SpawnJsonOptions {
|
|
153
|
-
readonly command: string;
|
|
154
|
-
readonly args: readonly string[];
|
|
155
|
-
readonly cwd: string;
|
|
156
|
-
readonly env?: NodeJS.ProcessEnv;
|
|
157
|
-
readonly signal?: AbortSignal | undefined;
|
|
158
|
-
readonly timeoutMs?: number | undefined;
|
|
159
|
-
readonly stderrLimit?: number;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/* Drivers stream newline-delimited JSON from a child process. The process is
|
|
163
|
-
killed on abort or timeout, and stderr is captured with a hard cap so a
|
|
164
|
-
failing binary cannot exhaust memory. */
|
|
165
|
-
export function spawnLineStream(options: SpawnJsonOptions): ProcessLineStream {
|
|
166
|
-
const child = spawn(options.command, [...options.args], {
|
|
167
|
-
cwd: options.cwd,
|
|
168
|
-
env: options.env ?? process.env,
|
|
169
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
170
|
-
});
|
|
171
|
-
const stderrLimit = options.stderrLimit ?? 8_192;
|
|
172
|
-
let stderr = '';
|
|
173
|
-
let aborted = false;
|
|
174
|
-
child.stderr.setEncoding('utf8');
|
|
175
|
-
child.stderr.on('data', (chunk: string) => {
|
|
176
|
-
if (stderr.length < stderrLimit) {
|
|
177
|
-
stderr = (stderr + chunk).slice(0, stderrLimit);
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
const stop = () => {
|
|
182
|
-
aborted = true;
|
|
183
|
-
child.kill('SIGTERM');
|
|
184
|
-
setTimeout(() => child.kill('SIGKILL'), 2_000).unref();
|
|
185
|
-
};
|
|
186
|
-
const timer =
|
|
187
|
-
options.timeoutMs === undefined
|
|
188
|
-
? undefined
|
|
189
|
-
: setTimeout(stop, options.timeoutMs);
|
|
190
|
-
timer?.unref();
|
|
191
|
-
if (options.signal) {
|
|
192
|
-
if (options.signal.aborted) stop();
|
|
193
|
-
else options.signal.addEventListener('abort', stop, { once: true });
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
const finished = new Promise<{
|
|
197
|
-
code: number | null;
|
|
198
|
-
stderr: string;
|
|
199
|
-
aborted: boolean;
|
|
200
|
-
}>((resolvePromise, rejectPromise) => {
|
|
201
|
-
child.on('error', (error) => {
|
|
202
|
-
if (timer) clearTimeout(timer);
|
|
203
|
-
rejectPromise(
|
|
204
|
-
new CodingAgentError(
|
|
205
|
-
'DRIVER_PROCESS_FAILED',
|
|
206
|
-
`Could not start ${options.command}: ${error.message}`,
|
|
207
|
-
),
|
|
208
|
-
);
|
|
209
|
-
});
|
|
210
|
-
child.on('close', (code) => {
|
|
211
|
-
if (timer) clearTimeout(timer);
|
|
212
|
-
resolvePromise({ code, stderr, aborted });
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
return {
|
|
217
|
-
lines: createInterface({ input: child.stdout, crlfDelay: Infinity }),
|
|
218
|
-
finished,
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
export function parseJsonLine(line: string): Record<string, unknown> | null {
|
|
223
|
-
const trimmed = line.trim();
|
|
224
|
-
if (!trimmed.startsWith('{')) return null;
|
|
225
|
-
try {
|
|
226
|
-
const value = JSON.parse(trimmed) as unknown;
|
|
227
|
-
return value && typeof value === 'object' && !Array.isArray(value)
|
|
228
|
-
? (value as Record<string, unknown>)
|
|
229
|
-
: null;
|
|
230
|
-
} catch {
|
|
231
|
-
return null;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
export async function probeCommand(
|
|
236
|
-
command: string,
|
|
237
|
-
args: readonly string[] = ['--version'],
|
|
238
|
-
): Promise<{ available: boolean; detail: string; version: string | null }> {
|
|
239
|
-
try {
|
|
240
|
-
const stream = spawnLineStream({
|
|
241
|
-
command,
|
|
242
|
-
args,
|
|
243
|
-
cwd: process.cwd(),
|
|
244
|
-
timeoutMs: 10_000,
|
|
245
|
-
});
|
|
246
|
-
let first = '';
|
|
247
|
-
for await (const line of stream.lines) {
|
|
248
|
-
if (!first) first = line.trim();
|
|
249
|
-
}
|
|
250
|
-
const result = await stream.finished;
|
|
251
|
-
if (result.code !== 0) {
|
|
252
|
-
return {
|
|
253
|
-
available: false,
|
|
254
|
-
detail:
|
|
255
|
-
result.stderr.trim().slice(0, 200) ||
|
|
256
|
-
`${command} exited with code ${result.code}.`,
|
|
257
|
-
version: null,
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
return {
|
|
261
|
-
available: true,
|
|
262
|
-
detail: `${command} is installed.`,
|
|
263
|
-
version: first || null,
|
|
264
|
-
};
|
|
265
|
-
} catch (error) {
|
|
266
|
-
return {
|
|
267
|
-
available: false,
|
|
268
|
-
detail:
|
|
269
|
-
error instanceof CodingAgentError
|
|
270
|
-
? error.message
|
|
271
|
-
: `${command} is not installed.`,
|
|
272
|
-
version: null,
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
}
|