@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,139 +0,0 @@
|
|
|
1
|
-
export {
|
|
2
|
-
DEFAULT_CONFIGURATION,
|
|
3
|
-
SANDBOX_DIRECTORY,
|
|
4
|
-
sandboxDirectory,
|
|
5
|
-
assertPlatformUrl,
|
|
6
|
-
loadSandboxConfiguration,
|
|
7
|
-
openSecret,
|
|
8
|
-
safeConfiguration,
|
|
9
|
-
saveSandboxConfiguration,
|
|
10
|
-
sealSecret,
|
|
11
|
-
secretFingerprint,
|
|
12
|
-
} from './config.ts';
|
|
13
|
-
export type {
|
|
14
|
-
ByokProviderConfiguration,
|
|
15
|
-
PreviewDataMode,
|
|
16
|
-
SafeSandboxConfiguration,
|
|
17
|
-
SandboxConfiguration,
|
|
18
|
-
SealedSecret,
|
|
19
|
-
} from './config.ts';
|
|
20
|
-
export { MAX_CHECKPOINTS, captureCheckpoint } from './checkpoints.ts';
|
|
21
|
-
export { checkDeclaredDependencies } from './dependencies.ts';
|
|
22
|
-
export type { DependencyReport } from './dependencies.ts';
|
|
23
|
-
export { diffFile, diffTrees } from './diff.ts';
|
|
24
|
-
export {
|
|
25
|
-
DeliveryError,
|
|
26
|
-
assertGatesPassed,
|
|
27
|
-
createLocalDeliveryTarget,
|
|
28
|
-
isEjectTarget,
|
|
29
|
-
listModuleFiles,
|
|
30
|
-
newPackages,
|
|
31
|
-
planModuleFiles,
|
|
32
|
-
resolveDeliveryTarget,
|
|
33
|
-
spawnCommand,
|
|
34
|
-
} from './delivery/index.ts';
|
|
35
|
-
export type {
|
|
36
|
-
CommandResult,
|
|
37
|
-
CommandRunner,
|
|
38
|
-
DeliveryAvailability,
|
|
39
|
-
DeliveryContext,
|
|
40
|
-
DeliveryEmit,
|
|
41
|
-
DeliveryModulePlan,
|
|
42
|
-
DeliveryOutcome,
|
|
43
|
-
DeliveryPlan,
|
|
44
|
-
DeliveryStepResult,
|
|
45
|
-
DeliveryTarget,
|
|
46
|
-
DeliveryTargetId,
|
|
47
|
-
EjectTarget,
|
|
48
|
-
StepResult,
|
|
49
|
-
} from './delivery/index.ts';
|
|
50
|
-
export type { DiffHunk, DiffLine, FileChange, FileDiff } from './diff.ts';
|
|
51
|
-
export {
|
|
52
|
-
GATE_IDS,
|
|
53
|
-
formatDirectory,
|
|
54
|
-
formatSession,
|
|
55
|
-
isGateId,
|
|
56
|
-
runGates,
|
|
57
|
-
} from './gates.ts';
|
|
58
|
-
export type { GateId, GateResult } from './gates.ts';
|
|
59
|
-
export {
|
|
60
|
-
SKILLS_DIRECTORY,
|
|
61
|
-
listSkills,
|
|
62
|
-
materializeModuleGraph,
|
|
63
|
-
materializeReference,
|
|
64
|
-
writeAgentPointer,
|
|
65
|
-
} from './reference.ts';
|
|
66
|
-
export { PlatformClient } from './platform-client.ts';
|
|
67
|
-
export type {
|
|
68
|
-
BridgeRequest,
|
|
69
|
-
BridgeResponse,
|
|
70
|
-
PlatformAuthority,
|
|
71
|
-
PlatformPrincipal,
|
|
72
|
-
} from './platform-client.ts';
|
|
73
|
-
export { createSandboxRoutes } from './routes.ts';
|
|
74
|
-
export { createSandboxRuntime } from './runtime.ts';
|
|
75
|
-
export type {
|
|
76
|
-
BrowserSession,
|
|
77
|
-
SandboxConnection,
|
|
78
|
-
SandboxRuntime,
|
|
79
|
-
} from './runtime.ts';
|
|
80
|
-
export {
|
|
81
|
-
addSessionModule,
|
|
82
|
-
appendChatEntry,
|
|
83
|
-
approveSpecification,
|
|
84
|
-
archiveSession,
|
|
85
|
-
assertSessionId,
|
|
86
|
-
basePathOf,
|
|
87
|
-
checkpointModulePath,
|
|
88
|
-
createSession,
|
|
89
|
-
deleteSession,
|
|
90
|
-
installSessionDependencies,
|
|
91
|
-
isSessionId,
|
|
92
|
-
listSessions,
|
|
93
|
-
modulePathOf,
|
|
94
|
-
moduleSuffixOf,
|
|
95
|
-
readChat,
|
|
96
|
-
readSession,
|
|
97
|
-
restoreCheckpoint,
|
|
98
|
-
restoreSession,
|
|
99
|
-
sessionPaths,
|
|
100
|
-
updateSession,
|
|
101
|
-
writeSession,
|
|
102
|
-
} from './sessions.ts';
|
|
103
|
-
export type {
|
|
104
|
-
ChatEntry,
|
|
105
|
-
CreateSessionInput,
|
|
106
|
-
DeleteSessionOptions,
|
|
107
|
-
HandoffPlan,
|
|
108
|
-
SandboxSession,
|
|
109
|
-
SandboxSessionKind,
|
|
110
|
-
SandboxSessionState,
|
|
111
|
-
SessionCheckpoint,
|
|
112
|
-
SessionModule,
|
|
113
|
-
SessionPaths,
|
|
114
|
-
} from './sessions.ts';
|
|
115
|
-
export {
|
|
116
|
-
collectDiffs,
|
|
117
|
-
forgetDiffs,
|
|
118
|
-
runSessionGates,
|
|
119
|
-
runTurn,
|
|
120
|
-
scaffoldFromSpec,
|
|
121
|
-
} from './turns.ts';
|
|
122
|
-
export type {
|
|
123
|
-
SessionFileDiff,
|
|
124
|
-
TurnContext,
|
|
125
|
-
TurnInput,
|
|
126
|
-
TurnOutcome,
|
|
127
|
-
} from './turns.ts';
|
|
128
|
-
export {
|
|
129
|
-
ensureSessionDependencies,
|
|
130
|
-
materializeSessionWorkspace,
|
|
131
|
-
} from './workspace-install.ts';
|
|
132
|
-
export type { InstallResult } from './workspace-install.ts';
|
|
133
|
-
export {
|
|
134
|
-
SandboxSetupError,
|
|
135
|
-
enabledModules,
|
|
136
|
-
findFlowdularWorkspace,
|
|
137
|
-
moduleRootsOf,
|
|
138
|
-
} from './workspace-root.ts';
|
|
139
|
-
export type { FlowdularWorkspace } from './workspace-root.ts';
|
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
-
import {
|
|
3
|
-
copyFile,
|
|
4
|
-
lstat,
|
|
5
|
-
mkdir,
|
|
6
|
-
readFile,
|
|
7
|
-
readdir,
|
|
8
|
-
readlink,
|
|
9
|
-
rm,
|
|
10
|
-
symlink,
|
|
11
|
-
writeFile,
|
|
12
|
-
} from 'node:fs/promises';
|
|
13
|
-
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
14
|
-
|
|
15
|
-
/* This is a post-turn containment boundary, not an instruction for the model.
|
|
16
|
-
The agent receives a complete workspace so it can read its contracts, but it
|
|
17
|
-
may only leave changes in the one module and paths owned by its role. */
|
|
18
|
-
const IGNORED_DIRECTORIES = new Set(['node_modules', '.git', 'dist', '.turbo']);
|
|
19
|
-
const QUARANTINE_DIRECTORY = 'path-violations';
|
|
20
|
-
|
|
21
|
-
type NodeKind = 'directory' | 'file' | 'symlink';
|
|
22
|
-
|
|
23
|
-
interface TreeNode {
|
|
24
|
-
readonly path: string;
|
|
25
|
-
readonly kind: NodeKind;
|
|
26
|
-
readonly digest?: string;
|
|
27
|
-
readonly target?: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface PathViolation {
|
|
31
|
-
readonly path: string;
|
|
32
|
-
readonly change: 'created' | 'modified' | 'deleted' | 'symlink-escape';
|
|
33
|
-
readonly reason: string;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface PathGuardResult {
|
|
37
|
-
readonly violations: readonly PathViolation[];
|
|
38
|
-
readonly quarantine: string | null;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface PathGuard {
|
|
42
|
-
verify(): Promise<PathGuardResult>;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function normalPath(value: string): string {
|
|
46
|
-
return value.split(sep).join('/');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function relativePath(root: string, path: string): string {
|
|
50
|
-
const result = relative(root, path);
|
|
51
|
-
if (!result || result.startsWith('..') || isAbsolute(result)) {
|
|
52
|
-
throw new Error('Path is outside the guarded workspace.');
|
|
53
|
-
}
|
|
54
|
-
return normalPath(result);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function matchesPath(path: string, pattern: string): boolean {
|
|
58
|
-
/* `**` may span path segments while `*` remains in one segment. */
|
|
59
|
-
const source = pattern
|
|
60
|
-
.split(/(\*\*|\*)/)
|
|
61
|
-
.map((part) => {
|
|
62
|
-
if (part === '**') return '.*';
|
|
63
|
-
if (part === '*') return '[^/]*';
|
|
64
|
-
return part.replace(/[.+?^$()|[\]\\]/g, '\\$&');
|
|
65
|
-
})
|
|
66
|
-
.join('');
|
|
67
|
-
return new RegExp(`^${source}$`).test(path);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function allowed(path: string, patterns: readonly string[]): boolean {
|
|
71
|
-
return patterns.some(
|
|
72
|
-
(pattern) => matchesPath(path, pattern) || pattern.startsWith(`${path}/`),
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async function digest(path: string): Promise<string> {
|
|
77
|
-
return createHash('sha256')
|
|
78
|
-
.update(await readFile(path))
|
|
79
|
-
.digest('hex');
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async function snapshot(
|
|
83
|
-
root: string,
|
|
84
|
-
directory = root,
|
|
85
|
-
): Promise<Map<string, TreeNode>> {
|
|
86
|
-
const nodes = new Map<string, TreeNode>();
|
|
87
|
-
let entries;
|
|
88
|
-
try {
|
|
89
|
-
entries = await readdir(directory, { withFileTypes: true });
|
|
90
|
-
} catch {
|
|
91
|
-
return nodes;
|
|
92
|
-
}
|
|
93
|
-
for (const entry of entries) {
|
|
94
|
-
if (entry.isDirectory() && IGNORED_DIRECTORIES.has(entry.name)) continue;
|
|
95
|
-
const fullPath = join(directory, entry.name);
|
|
96
|
-
const path = relativePath(root, fullPath);
|
|
97
|
-
const info = await lstat(fullPath);
|
|
98
|
-
if (info.isSymbolicLink()) {
|
|
99
|
-
nodes.set(path, {
|
|
100
|
-
path,
|
|
101
|
-
kind: 'symlink',
|
|
102
|
-
target: await readlink(fullPath),
|
|
103
|
-
});
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
if (info.isDirectory()) {
|
|
107
|
-
nodes.set(path, { path, kind: 'directory' });
|
|
108
|
-
for (const [childPath, child] of await snapshot(root, fullPath)) {
|
|
109
|
-
nodes.set(childPath, child);
|
|
110
|
-
}
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
if (info.isFile()) {
|
|
114
|
-
nodes.set(path, { path, kind: 'file', digest: await digest(fullPath) });
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return nodes;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function changed(
|
|
121
|
-
before: TreeNode | undefined,
|
|
122
|
-
after: TreeNode | undefined,
|
|
123
|
-
): PathViolation['change'] | null {
|
|
124
|
-
if (!before && after) return 'created';
|
|
125
|
-
if (before && !after) return 'deleted';
|
|
126
|
-
if (!before || !after) return null;
|
|
127
|
-
if (before.kind !== after.kind) return 'modified';
|
|
128
|
-
if (before.kind === 'file' && before.digest !== after.digest)
|
|
129
|
-
return 'modified';
|
|
130
|
-
if (before.kind === 'symlink' && before.target !== after.target)
|
|
131
|
-
return 'modified';
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function symlinkEscapes(root: string, path: string, target: string): boolean {
|
|
136
|
-
const resolved = resolve(dirname(join(root, path)), target);
|
|
137
|
-
const inside = relative(root, resolved);
|
|
138
|
-
return inside.startsWith('..') || isAbsolute(inside);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
async function saveBaseline(
|
|
142
|
-
root: string,
|
|
143
|
-
backup: string,
|
|
144
|
-
nodes: ReadonlyMap<string, TreeNode>,
|
|
145
|
-
): Promise<void> {
|
|
146
|
-
for (const node of nodes.values()) {
|
|
147
|
-
if (node.kind !== 'file') continue;
|
|
148
|
-
const target = join(backup, node.path);
|
|
149
|
-
await mkdir(dirname(target), { recursive: true, mode: 0o700 });
|
|
150
|
-
await copyFile(join(root, node.path), target);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
async function removeAt(root: string, path: string): Promise<void> {
|
|
155
|
-
await rm(join(root, path), { recursive: true, force: true });
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
async function restoreNode(
|
|
159
|
-
root: string,
|
|
160
|
-
backup: string,
|
|
161
|
-
node: TreeNode,
|
|
162
|
-
): Promise<void> {
|
|
163
|
-
const target = join(root, node.path);
|
|
164
|
-
if (node.kind === 'directory') {
|
|
165
|
-
await mkdir(target, { recursive: true, mode: 0o700 });
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
await mkdir(dirname(target), { recursive: true, mode: 0o700 });
|
|
169
|
-
await rm(target, { recursive: true, force: true });
|
|
170
|
-
if (node.kind === 'file') {
|
|
171
|
-
await copyFile(join(backup, node.path), target);
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
await symlink(node.target!, target);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
async function quarantineCurrent(
|
|
178
|
-
root: string,
|
|
179
|
-
directory: string,
|
|
180
|
-
path: string,
|
|
181
|
-
): Promise<void> {
|
|
182
|
-
const source = join(root, path);
|
|
183
|
-
const target = join(directory, 'files', path);
|
|
184
|
-
try {
|
|
185
|
-
const info = await lstat(source);
|
|
186
|
-
await mkdir(dirname(target), { recursive: true, mode: 0o700 });
|
|
187
|
-
if (info.isSymbolicLink()) await symlink(await readlink(source), target);
|
|
188
|
-
else if (info.isFile()) await copyFile(source, target);
|
|
189
|
-
} catch {
|
|
190
|
-
/* The evidence file still names a path that raced away before quarantine. */
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/* Baselines are outside the workspace and every restore uses lstat/rm, so a
|
|
195
|
-
new symlink is removed rather than followed. The guard deliberately refuses
|
|
196
|
-
a changed symlink whose target leaves the workspace: that shape is an escape
|
|
197
|
-
hatch even when its own pathname matches an allowed glob. */
|
|
198
|
-
export async function guardAgentPaths(input: {
|
|
199
|
-
readonly workspace: string;
|
|
200
|
-
readonly sessionRoot: string;
|
|
201
|
-
readonly allowedPaths: readonly string[];
|
|
202
|
-
}): Promise<PathGuard> {
|
|
203
|
-
const workspace = resolve(input.workspace);
|
|
204
|
-
const baseline = await snapshot(workspace);
|
|
205
|
-
const staging = join(
|
|
206
|
-
input.sessionRoot,
|
|
207
|
-
QUARANTINE_DIRECTORY,
|
|
208
|
-
`${Date.now()}-${randomUUID()}`,
|
|
209
|
-
);
|
|
210
|
-
const backup = join(staging, 'baseline');
|
|
211
|
-
await saveBaseline(workspace, backup, baseline);
|
|
212
|
-
|
|
213
|
-
return {
|
|
214
|
-
verify: async () => {
|
|
215
|
-
const current = await snapshot(workspace);
|
|
216
|
-
const paths = new Set([...baseline.keys(), ...current.keys()]);
|
|
217
|
-
const violations: PathViolation[] = [];
|
|
218
|
-
for (const path of [...paths].sort()) {
|
|
219
|
-
const before = baseline.get(path);
|
|
220
|
-
const after = current.get(path);
|
|
221
|
-
const change = changed(before, after);
|
|
222
|
-
if (!change) continue;
|
|
223
|
-
if (
|
|
224
|
-
after?.kind === 'symlink' &&
|
|
225
|
-
symlinkEscapes(workspace, path, after.target!)
|
|
226
|
-
) {
|
|
227
|
-
violations.push({
|
|
228
|
-
path,
|
|
229
|
-
change: 'symlink-escape',
|
|
230
|
-
reason:
|
|
231
|
-
'The changed path is a symbolic link that leaves the session workspace.',
|
|
232
|
-
});
|
|
233
|
-
continue;
|
|
234
|
-
}
|
|
235
|
-
if (!allowed(path, input.allowedPaths)) {
|
|
236
|
-
violations.push({
|
|
237
|
-
path,
|
|
238
|
-
change,
|
|
239
|
-
reason: 'The path is outside this role and module allowlist.',
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
if (violations.length === 0) {
|
|
244
|
-
/* The baseline is an enforcement aid, not session history. Retaining a
|
|
245
|
-
full copy on every successful turn leaks disk and duplicates any
|
|
246
|
-
sensitive attachment the role was allowed to read. */
|
|
247
|
-
await rm(staging, { recursive: true, force: true });
|
|
248
|
-
return { violations, quarantine: null };
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
for (const violation of violations)
|
|
252
|
-
await quarantineCurrent(workspace, staging, violation.path);
|
|
253
|
-
/* Remove offenders deepest first. A created parent cannot leave a child
|
|
254
|
-
behind, and `rm` unlinks a symlink without following it. */
|
|
255
|
-
for (const violation of [...violations].sort(
|
|
256
|
-
(left, right) => right.path.length - left.path.length,
|
|
257
|
-
)) {
|
|
258
|
-
await removeAt(workspace, violation.path);
|
|
259
|
-
}
|
|
260
|
-
/* Restore every baseline node below an offending path. This also repairs
|
|
261
|
-
a file replaced by a symlink, without traversing that link. */
|
|
262
|
-
const restore = [...baseline.values()]
|
|
263
|
-
.filter((node) =>
|
|
264
|
-
violations.some(
|
|
265
|
-
(violation) =>
|
|
266
|
-
node.path === violation.path ||
|
|
267
|
-
node.path.startsWith(`${violation.path}/`),
|
|
268
|
-
),
|
|
269
|
-
)
|
|
270
|
-
.sort((left, right) => left.path.length - right.path.length);
|
|
271
|
-
for (const node of restore) await restoreNode(workspace, backup, node);
|
|
272
|
-
await rm(backup, { recursive: true, force: true });
|
|
273
|
-
await mkdir(staging, { recursive: true, mode: 0o700 });
|
|
274
|
-
await writeFile(
|
|
275
|
-
join(staging, 'evidence.json'),
|
|
276
|
-
`${JSON.stringify({ allowedPaths: input.allowedPaths, violations }, null, '\t')}\n`,
|
|
277
|
-
{ encoding: 'utf8', mode: 0o600 },
|
|
278
|
-
);
|
|
279
|
-
return { violations, quarantine: staging };
|
|
280
|
-
},
|
|
281
|
-
};
|
|
282
|
-
}
|