@namzu/sdk 74.1.0 → 76.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +85 -0
- package/dist/bridge/acp/server.d.ts +2 -0
- package/dist/bridge/acp/server.d.ts.map +1 -1
- package/dist/bridge/acp/server.js +13 -2
- package/dist/bridge/acp/server.js.map +1 -1
- package/dist/bridge/acp/update.d.ts.map +1 -1
- package/dist/bridge/acp/update.js +22 -2
- package/dist/bridge/acp/update.js.map +1 -1
- package/dist/connector/mcp/adapter.d.ts +1 -1
- package/dist/connector/mcp/adapter.d.ts.map +1 -1
- package/dist/connector/mcp/adapter.js +3 -2
- package/dist/connector/mcp/adapter.js.map +1 -1
- package/dist/connector/mcp/client.d.ts +4 -25
- package/dist/connector/mcp/client.d.ts.map +1 -1
- package/dist/connector/mcp/client.js +32 -32
- package/dist/connector/mcp/client.js.map +1 -1
- package/dist/peers/record.d.ts +3 -3
- package/dist/provider/errors.d.ts.map +1 -1
- package/dist/provider/errors.js +13 -18
- package/dist/provider/errors.js.map +1 -1
- package/dist/provider/stream-request-timeout.d.ts +9 -0
- package/dist/provider/stream-request-timeout.d.ts.map +1 -0
- package/dist/provider/stream-request-timeout.js +34 -0
- package/dist/provider/stream-request-timeout.js.map +1 -0
- package/dist/public-runtime.d.ts +3 -2
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +2 -1
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts +1 -1
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +1 -1
- package/dist/public-tools.js.map +1 -1
- package/dist/runtime/query/executor.d.ts +3 -0
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +25 -4
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/file-evidence-replay.d.ts +1 -0
- package/dist/runtime/query/file-evidence-replay.d.ts.map +1 -1
- package/dist/runtime/query/file-evidence-replay.js +64 -21
- package/dist/runtime/query/file-evidence-replay.js.map +1 -1
- package/dist/runtime/query/file-evidence-seed.d.ts +7 -0
- package/dist/runtime/query/file-evidence-seed.d.ts.map +1 -1
- package/dist/runtime/query/file-evidence-seed.js +12 -1
- package/dist/runtime/query/file-evidence-seed.js.map +1 -1
- package/dist/runtime/query/index.d.ts +2 -0
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +5 -2
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/path-escalation.d.ts.map +1 -1
- package/dist/runtime/query/path-escalation.js +4 -3
- package/dist/runtime/query/path-escalation.js.map +1 -1
- package/dist/runtime/query/tooling.d.ts +2 -0
- package/dist/runtime/query/tooling.d.ts.map +1 -1
- package/dist/runtime/query/tooling.js +1 -0
- package/dist/runtime/query/tooling.js.map +1 -1
- package/dist/sandbox/provider/local.d.ts.map +1 -1
- package/dist/sandbox/provider/local.js +45 -18
- package/dist/sandbox/provider/local.js.map +1 -1
- package/dist/schedules/cron.js +1 -1
- package/dist/schedules/cron.js.map +1 -1
- package/dist/schedules/describe.js +1 -1
- package/dist/schedules/describe.js.map +1 -1
- package/dist/schedules/next-fire.d.ts +2 -2
- package/dist/schedules/next-fire.d.ts.map +1 -1
- package/dist/schedules/next-fire.js +7 -4
- package/dist/schedules/next-fire.js.map +1 -1
- package/dist/schedules/spec.d.ts.map +1 -1
- package/dist/schedules/spec.js +23 -7
- package/dist/schedules/spec.js.map +1 -1
- package/dist/schedules/types.d.ts +2 -0
- package/dist/schedules/types.d.ts.map +1 -1
- package/dist/session/workspace/git-worktree.d.ts +18 -0
- package/dist/session/workspace/git-worktree.d.ts.map +1 -1
- package/dist/session/workspace/git-worktree.js +100 -1
- package/dist/session/workspace/git-worktree.js.map +1 -1
- package/dist/session/workspace/index.d.ts +1 -1
- package/dist/session/workspace/index.d.ts.map +1 -1
- package/dist/session/workspace/index.js +1 -1
- package/dist/session/workspace/index.js.map +1 -1
- package/dist/store/checkpoint/contract.d.ts.map +1 -1
- package/dist/store/checkpoint/contract.js +5 -2
- package/dist/store/checkpoint/contract.js.map +1 -1
- package/dist/store/session-index/sqlite.d.ts.map +1 -1
- package/dist/store/session-index/sqlite.js +7 -3
- package/dist/store/session-index/sqlite.js.map +1 -1
- package/dist/store/session-log/core.d.ts.map +1 -1
- package/dist/store/session-log/core.js +118 -25
- package/dist/store/session-log/core.js.map +1 -1
- package/dist/store/session-log/disk.js +1 -1
- package/dist/store/session-log/disk.js.map +1 -1
- package/dist/tools/admit-facts.d.ts.map +1 -1
- package/dist/tools/admit-facts.js +19 -0
- package/dist/tools/admit-facts.js.map +1 -1
- package/dist/tools/builtins/bash.d.ts +1 -1
- package/dist/tools/builtins/bash.d.ts.map +1 -1
- package/dist/tools/builtins/bash.js +9 -7
- package/dist/tools/builtins/bash.js.map +1 -1
- package/dist/tools/builtins/browser.d.ts +2 -2
- package/dist/tools/builtins/browser.d.ts.map +1 -1
- package/dist/tools/builtins/browser.js +15 -3
- package/dist/tools/builtins/browser.js.map +1 -1
- package/dist/tools/builtins/code-analysis.d.ts.map +1 -1
- package/dist/tools/builtins/code-analysis.js +4 -1
- package/dist/tools/builtins/code-analysis.js.map +1 -1
- package/dist/tools/builtins/computer-use.d.ts +19 -3
- package/dist/tools/builtins/computer-use.d.ts.map +1 -1
- package/dist/tools/builtins/computer-use.js +150 -50
- package/dist/tools/builtins/computer-use.js.map +1 -1
- package/dist/tools/builtins/edit-apply.d.ts.map +1 -1
- package/dist/tools/builtins/edit-apply.js +24 -10
- package/dist/tools/builtins/edit-apply.js.map +1 -1
- package/dist/tools/builtins/edit.d.ts.map +1 -1
- package/dist/tools/builtins/edit.js +31 -15
- package/dist/tools/builtins/edit.js.map +1 -1
- package/dist/tools/builtins/file-text.d.ts +3 -0
- package/dist/tools/builtins/file-text.d.ts.map +1 -0
- package/dist/tools/builtins/file-text.js +14 -0
- package/dist/tools/builtins/file-text.js.map +1 -0
- package/dist/tools/builtins/glob.d.ts.map +1 -1
- package/dist/tools/builtins/glob.js +7 -2
- package/dist/tools/builtins/glob.js.map +1 -1
- package/dist/tools/builtins/grep.d.ts.map +1 -1
- package/dist/tools/builtins/grep.js +8 -5
- package/dist/tools/builtins/grep.js.map +1 -1
- package/dist/tools/builtins/ls.d.ts.map +1 -1
- package/dist/tools/builtins/ls.js +2 -1
- package/dist/tools/builtins/ls.js.map +1 -1
- package/dist/tools/builtins/notebook-edit.d.ts.map +1 -1
- package/dist/tools/builtins/notebook-edit.js +19 -10
- package/dist/tools/builtins/notebook-edit.js.map +1 -1
- package/dist/tools/builtins/read-file.d.ts.map +1 -1
- package/dist/tools/builtins/read-file.js +48 -24
- package/dist/tools/builtins/read-file.js.map +1 -1
- package/dist/tools/builtins/read-regular-file.d.ts +5 -0
- package/dist/tools/builtins/read-regular-file.d.ts.map +1 -0
- package/dist/tools/builtins/read-regular-file.js +23 -0
- package/dist/tools/builtins/read-regular-file.js.map +1 -0
- package/dist/tools/builtins/search-support.d.ts +2 -0
- package/dist/tools/builtins/search-support.d.ts.map +1 -1
- package/dist/tools/builtins/search-support.js +14 -0
- package/dist/tools/builtins/search-support.js.map +1 -1
- package/dist/tools/builtins/stale-before-review.d.ts.map +1 -1
- package/dist/tools/builtins/stale-before-review.js +8 -5
- package/dist/tools/builtins/stale-before-review.js.map +1 -1
- package/dist/tools/builtins/write-file.d.ts.map +1 -1
- package/dist/tools/builtins/write-file.js +17 -13
- package/dist/tools/builtins/write-file.js.map +1 -1
- package/dist/tools/coordinator/agent.d.ts.map +1 -1
- package/dist/tools/coordinator/agent.js +6 -0
- package/dist/tools/coordinator/agent.js.map +1 -1
- package/dist/tools/coordinator/index.d.ts.map +1 -1
- package/dist/tools/coordinator/index.js +6 -0
- package/dist/tools/coordinator/index.js.map +1 -1
- package/dist/tools/coordinator/progress.d.ts +9 -0
- package/dist/tools/coordinator/progress.d.ts.map +1 -0
- package/dist/tools/coordinator/progress.js +30 -0
- package/dist/tools/coordinator/progress.js.map +1 -0
- package/dist/tools/paths.d.ts +9 -0
- package/dist/tools/paths.d.ts.map +1 -1
- package/dist/tools/paths.js +39 -9
- package/dist/tools/paths.js.map +1 -1
- package/dist/tools/posix-path.d.ts +2 -14
- package/dist/tools/posix-path.d.ts.map +1 -1
- package/dist/tools/posix-path.js +7 -0
- package/dist/tools/posix-path.js.map +1 -1
- package/dist/tools/shell-output-window.d.ts +12 -0
- package/dist/tools/shell-output-window.d.ts.map +1 -0
- package/dist/tools/shell-output-window.js +92 -0
- package/dist/tools/shell-output-window.js.map +1 -0
- package/dist/types/acp/index.d.ts +3 -0
- package/dist/types/acp/index.d.ts.map +1 -1
- package/dist/types/browser/index.d.ts +4 -0
- package/dist/types/browser/index.d.ts.map +1 -1
- package/dist/types/code-analysis/index.d.ts +1 -1
- package/dist/types/code-analysis/index.d.ts.map +1 -1
- package/dist/types/computer-use/index.d.ts +4 -0
- package/dist/types/computer-use/index.d.ts.map +1 -1
- package/dist/types/provider/errors.d.ts.map +1 -1
- package/dist/types/provider/errors.js +3 -5
- package/dist/types/provider/errors.js.map +1 -1
- package/dist/types/session/checkpoint.d.ts +13 -0
- package/dist/types/session/checkpoint.d.ts.map +1 -1
- package/dist/types/session/checkpoint.js +33 -0
- package/dist/types/session/checkpoint.js.map +1 -1
- package/dist/types/session/events.d.ts +3 -0
- package/dist/types/session/events.d.ts.map +1 -1
- package/dist/types/session/events.js.map +1 -1
- package/dist/types/tool/index.d.ts +17 -0
- package/dist/types/tool/index.d.ts.map +1 -1
- package/dist/types/tool/index.js.map +1 -1
- package/dist/types/tool/presentation.d.ts +8 -0
- package/dist/types/tool/presentation.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/bridge/acp/server.ts +22 -8
- package/src/bridge/acp/update.ts +23 -2
- package/src/connector/mcp/adapter.ts +4 -3
- package/src/connector/mcp/client.ts +33 -32
- package/src/provider/errors.ts +12 -19
- package/src/provider/stream-request-timeout.ts +34 -0
- package/src/public-runtime.ts +3 -0
- package/src/public-tools.ts +1 -0
- package/src/runtime/query/executor.ts +41 -6
- package/src/runtime/query/file-evidence-replay.ts +73 -19
- package/src/runtime/query/file-evidence-seed.ts +16 -0
- package/src/runtime/query/index.ts +9 -1
- package/src/runtime/query/path-escalation.ts +4 -3
- package/src/runtime/query/tooling.ts +3 -0
- package/src/sandbox/provider/local.ts +53 -25
- package/src/schedules/cron.ts +1 -1
- package/src/schedules/describe.ts +1 -1
- package/src/schedules/next-fire.ts +7 -4
- package/src/schedules/spec.ts +36 -7
- package/src/schedules/types.ts +2 -0
- package/src/session/workspace/git-worktree.ts +115 -1
- package/src/session/workspace/index.ts +6 -1
- package/src/store/checkpoint/contract.ts +9 -2
- package/src/store/session-index/sqlite.ts +8 -4
- package/src/store/session-log/core.ts +130 -26
- package/src/store/session-log/disk.ts +1 -1
- package/src/tools/admit-facts.ts +20 -0
- package/src/tools/builtins/bash.ts +11 -12
- package/src/tools/builtins/browser.ts +16 -3
- package/src/tools/builtins/code-analysis.ts +6 -1
- package/src/tools/builtins/computer-use.ts +188 -44
- package/src/tools/builtins/edit-apply.ts +25 -10
- package/src/tools/builtins/edit.ts +31 -15
- package/src/tools/builtins/file-text.ts +14 -0
- package/src/tools/builtins/glob.ts +6 -1
- package/src/tools/builtins/grep.ts +7 -5
- package/src/tools/builtins/ls.ts +2 -1
- package/src/tools/builtins/notebook-edit.ts +18 -11
- package/src/tools/builtins/read-file.ts +52 -27
- package/src/tools/builtins/read-regular-file.ts +25 -0
- package/src/tools/builtins/search-support.ts +13 -0
- package/src/tools/builtins/stale-before-review.ts +8 -6
- package/src/tools/builtins/write-file.ts +18 -12
- package/src/tools/coordinator/agent.ts +6 -0
- package/src/tools/coordinator/index.ts +6 -0
- package/src/tools/coordinator/progress.ts +40 -0
- package/src/tools/paths.ts +49 -7
- package/src/tools/posix-path.ts +9 -0
- package/src/tools/shell-output-window.ts +97 -0
- package/src/types/acp/index.ts +3 -0
- package/src/types/browser/index.ts +2 -0
- package/src/types/code-analysis/index.ts +1 -1
- package/src/types/computer-use/index.ts +17 -0
- package/src/types/provider/errors.ts +3 -5
- package/src/types/session/checkpoint.ts +37 -0
- package/src/types/session/events.ts +3 -0
- package/src/types/tool/index.ts +12 -0
- package/src/types/tool/presentation.ts +12 -1
|
@@ -664,6 +664,7 @@ class LocalSandbox implements Sandbox {
|
|
|
664
664
|
environment: SandboxEnvironment,
|
|
665
665
|
private readonly wrapperCommand: string | undefined,
|
|
666
666
|
private readonly removeRootOnDestroy: boolean,
|
|
667
|
+
private readonly seatbeltTempDir: string | undefined,
|
|
667
668
|
config: SandboxCreateConfig,
|
|
668
669
|
log: Logger,
|
|
669
670
|
) {
|
|
@@ -706,7 +707,7 @@ class LocalSandbox implements Sandbox {
|
|
|
706
707
|
this._status = 'busy'
|
|
707
708
|
const startTime = Date.now()
|
|
708
709
|
|
|
709
|
-
const env =
|
|
710
|
+
const env = this.buildSpawnEnv(opts?.env)
|
|
710
711
|
const timeout = opts?.timeout ?? this.config.timeoutMs ?? SANDBOX_DEFAULT_TIMEOUT_MS
|
|
711
712
|
|
|
712
713
|
const cwd = opts?.cwd ? await resolveWithinAnyReal(this.roots, opts.cwd) : this.rootDir
|
|
@@ -871,9 +872,12 @@ class LocalSandbox implements Sandbox {
|
|
|
871
872
|
// A generated temp root belongs to this allocation. A working-directory
|
|
872
873
|
// root belongs to the caller. Conflating those lifetimes turns normal run
|
|
873
874
|
// teardown into recursive deletion of the project the turn just edited.
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
875
|
+
await Promise.all([
|
|
876
|
+
this.removeRootOnDestroy ? rm(this.rootDir, { recursive: true, force: true }) : undefined,
|
|
877
|
+
this.seatbeltTempDir === undefined
|
|
878
|
+
? undefined
|
|
879
|
+
: rm(this.seatbeltTempDir, { recursive: true, force: true }),
|
|
880
|
+
])
|
|
877
881
|
|
|
878
882
|
this.log.info('Sandbox destroyed', { 'namzu.sandbox.id': this.id })
|
|
879
883
|
}
|
|
@@ -896,7 +900,7 @@ class LocalSandbox implements Sandbox {
|
|
|
896
900
|
const { spawnCommand, spawnArgs, bwrapInfoFd, bwrapBlockFd } = this.buildSpawnArgs(command, [
|
|
897
901
|
...args,
|
|
898
902
|
])
|
|
899
|
-
const env =
|
|
903
|
+
const env = this.buildSpawnEnv(opts?.env)
|
|
900
904
|
const child = spawn(spawnCommand, spawnArgs, {
|
|
901
905
|
cwd,
|
|
902
906
|
env,
|
|
@@ -943,6 +947,13 @@ class LocalSandbox implements Sandbox {
|
|
|
943
947
|
}
|
|
944
948
|
}
|
|
945
949
|
|
|
950
|
+
private buildSpawnEnv(overrides?: Record<string, string>): Record<string, string> {
|
|
951
|
+
const env = buildSafeEnv(this.config.env, overrides)
|
|
952
|
+
const tempDir = this.environment === 'linux-bwrap' ? '/tmp' : this.seatbeltTempDir
|
|
953
|
+
if (tempDir !== undefined) env.TMPDIR ??= tempDir
|
|
954
|
+
return env
|
|
955
|
+
}
|
|
956
|
+
|
|
946
957
|
private buildSpawnArgs(
|
|
947
958
|
command: string,
|
|
948
959
|
args: string[],
|
|
@@ -952,15 +963,17 @@ class LocalSandbox implements Sandbox {
|
|
|
952
963
|
bwrapInfoFd?: number
|
|
953
964
|
bwrapBlockFd?: number
|
|
954
965
|
} {
|
|
966
|
+
const additionalDirectories =
|
|
967
|
+
this.seatbeltTempDir === undefined
|
|
968
|
+
? this.additionalDirectories
|
|
969
|
+
: [...this.additionalDirectories, this.seatbeltTempDir]
|
|
955
970
|
const built = buildLimitedSpawn({
|
|
956
971
|
environment: this.environment,
|
|
957
972
|
...(this.wrapperCommand !== undefined ? { wrapperCommand: this.wrapperCommand } : {}),
|
|
958
973
|
command,
|
|
959
974
|
args,
|
|
960
975
|
rootDir: this.rootDir,
|
|
961
|
-
|
|
962
|
-
? { additionalDirectories: this.additionalDirectories }
|
|
963
|
-
: {}),
|
|
976
|
+
additionalDirectories,
|
|
964
977
|
...(this.config.memoryLimitMb !== undefined
|
|
965
978
|
? { memoryLimitMb: this.config.memoryLimitMb }
|
|
966
979
|
: {}),
|
|
@@ -1278,24 +1291,39 @@ export class LocalSandboxProvider implements SandboxProvider {
|
|
|
1278
1291
|
rootDir = canonicalizePath(rawDir)
|
|
1279
1292
|
removeRootOnDestroy = true
|
|
1280
1293
|
}
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1294
|
+
let seatbeltTempDir: string | undefined
|
|
1295
|
+
try {
|
|
1296
|
+
config?.signal?.throwIfAborted()
|
|
1297
|
+
if (this.environment === 'macos-seatbelt') {
|
|
1298
|
+
// Keep scratch outside caller-owned workspaces, which may be read-only
|
|
1299
|
+
// on the host and outlive this sandbox.
|
|
1300
|
+
seatbeltTempDir = canonicalizePath(await createTempDir('namzu-seatbelt-'))
|
|
1301
|
+
}
|
|
1302
|
+
config?.signal?.throwIfAborted()
|
|
1285
1303
|
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1304
|
+
this.log.info('Creating sandbox', {
|
|
1305
|
+
'namzu.sandbox.id': id,
|
|
1306
|
+
'namzu.sandbox.root_dir': rootDir,
|
|
1307
|
+
})
|
|
1290
1308
|
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1309
|
+
return new LocalSandbox(
|
|
1310
|
+
id,
|
|
1311
|
+
rootDir,
|
|
1312
|
+
this.environment,
|
|
1313
|
+
this.wrapperCommand,
|
|
1314
|
+
removeRootOnDestroy,
|
|
1315
|
+
seatbeltTempDir,
|
|
1316
|
+
config ?? {},
|
|
1317
|
+
this.log,
|
|
1318
|
+
)
|
|
1319
|
+
} catch (error) {
|
|
1320
|
+
await Promise.all([
|
|
1321
|
+
removeRootOnDestroy ? rm(rootDir, { recursive: true, force: true }) : undefined,
|
|
1322
|
+
seatbeltTempDir === undefined
|
|
1323
|
+
? undefined
|
|
1324
|
+
: rm(seatbeltTempDir, { recursive: true, force: true }),
|
|
1325
|
+
])
|
|
1326
|
+
throw error
|
|
1327
|
+
}
|
|
1300
1328
|
}
|
|
1301
1329
|
}
|
package/src/schedules/cron.ts
CHANGED
|
@@ -129,7 +129,7 @@ function parseField(text: string, field: FieldSpec): number[] {
|
|
|
129
129
|
} else {
|
|
130
130
|
lo = parseValue(rangeText, field)
|
|
131
131
|
// `5/15` means "from 5, every 15", as in Vixie cron.
|
|
132
|
-
hi = stepText !== undefined ?
|
|
132
|
+
hi = stepText !== undefined ? field.max : lo
|
|
133
133
|
}
|
|
134
134
|
for (let v = lo; v <= hi; v += step) values.add(v)
|
|
135
135
|
}
|
|
@@ -119,7 +119,7 @@ export function describeSchedule(
|
|
|
119
119
|
spec: ScheduleSpec,
|
|
120
120
|
options: DescribeScheduleOptions = {},
|
|
121
121
|
): string {
|
|
122
|
-
const tz = options.tz ?? 'UTC'
|
|
122
|
+
const tz = options.tz ?? (spec.kind === 'at' ? spec.tz : undefined) ?? 'UTC'
|
|
123
123
|
switch (spec.kind) {
|
|
124
124
|
case 'at':
|
|
125
125
|
return `once at ${formatWall(Date.parse(spec.at), tz)} (${tz})`
|
|
@@ -107,8 +107,8 @@ function validEvery(spec: { everyMs: number; anchorAt: string }): number {
|
|
|
107
107
|
|
|
108
108
|
/**
|
|
109
109
|
* The first instant strictly after `afterExclusive` at which `spec` fires,
|
|
110
|
-
* or `null` when there is none
|
|
111
|
-
*
|
|
110
|
+
* or `null` when there is none within the supported date range (or, for cron,
|
|
111
|
+
* within the next five years).
|
|
112
112
|
*/
|
|
113
113
|
export function nextFireTime(spec: ScheduleSpec, afterExclusive: Date): Date | null {
|
|
114
114
|
const after = afterExclusive.getTime()
|
|
@@ -123,7 +123,8 @@ export function nextFireTime(spec: ScheduleSpec, afterExclusive: Date): Date | n
|
|
|
123
123
|
case 'every': {
|
|
124
124
|
const anchor = validEvery(spec)
|
|
125
125
|
const k = after < anchor ? 1 : Math.floor((after - anchor) / spec.everyMs) + 1
|
|
126
|
-
|
|
126
|
+
const next = new Date(anchor + Math.max(1, k) * spec.everyMs)
|
|
127
|
+
return Number.isFinite(next.getTime()) ? next : null
|
|
127
128
|
}
|
|
128
129
|
case 'cron': {
|
|
129
130
|
const expr = cronOf(spec.expr)
|
|
@@ -259,7 +260,9 @@ export function assertSpecFires(spec: ScheduleSpec, now: Date): void {
|
|
|
259
260
|
throw new ScheduleValidationError(
|
|
260
261
|
spec.kind === 'at'
|
|
261
262
|
? `${spec.at} is in the past`
|
|
262
|
-
:
|
|
263
|
+
: spec.kind === 'every'
|
|
264
|
+
? 'the next interval is outside the supported date range'
|
|
265
|
+
: `"${spec.expr}" never fires in the next five years`,
|
|
263
266
|
spec.kind === 'cron' ? spec.expr : spec.kind === 'at' ? spec.at : undefined,
|
|
264
267
|
)
|
|
265
268
|
}
|
package/src/schedules/spec.ts
CHANGED
|
@@ -71,6 +71,9 @@ function formatInterval(ms: number): string {
|
|
|
71
71
|
|
|
72
72
|
function everySpec(text: string, now: Date): ScheduleSpec {
|
|
73
73
|
const ms = parseDuration(text)
|
|
74
|
+
if (!Number.isSafeInteger(ms)) {
|
|
75
|
+
throw new ScheduleValidationError(`every ${text} is outside the supported date range`, text)
|
|
76
|
+
}
|
|
74
77
|
if (ms < MINUTE) {
|
|
75
78
|
throw new ScheduleValidationError(
|
|
76
79
|
`every ${text} is shorter than the minimum interval; the nearest allowed is every 1m`,
|
|
@@ -89,6 +92,22 @@ function everySpec(text: string, now: Date): ScheduleSpec {
|
|
|
89
92
|
return { kind: 'every', everyMs: ms, anchorAt: anchor.toISOString() }
|
|
90
93
|
}
|
|
91
94
|
|
|
95
|
+
function validateCivilTime(
|
|
96
|
+
wall: number,
|
|
97
|
+
y: number,
|
|
98
|
+
mo: number,
|
|
99
|
+
d: number,
|
|
100
|
+
h: number,
|
|
101
|
+
mi: number,
|
|
102
|
+
s: number,
|
|
103
|
+
token: string,
|
|
104
|
+
): void {
|
|
105
|
+
const c = civil(wall)
|
|
106
|
+
if (c.year !== y || c.month !== mo || c.day !== d || h > 23 || mi > 59 || s > 59) {
|
|
107
|
+
throw new ScheduleValidationError(`"${token}" is not a real date and time`, token)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
92
111
|
/** Resolve a local `YYYY-MM-DD HH:MM` in `tz` to one instant (the earlier of two). */
|
|
93
112
|
function localToInstant(
|
|
94
113
|
y: number,
|
|
@@ -100,10 +119,7 @@ function localToInstant(
|
|
|
100
119
|
token: string,
|
|
101
120
|
): number {
|
|
102
121
|
const wall = Date.UTC(y, mo - 1, d, h, mi)
|
|
103
|
-
|
|
104
|
-
if (c.year !== y || c.month !== mo || c.day !== d || h > 23 || mi > 59) {
|
|
105
|
-
throw new ScheduleValidationError(`"${token}" is not a real date and time`, token)
|
|
106
|
-
}
|
|
122
|
+
validateCivilTime(wall, y, mo, d, h, mi, 0, token)
|
|
107
123
|
const instants = instantsForWall(wall, tz)
|
|
108
124
|
if (instants.length === 0) {
|
|
109
125
|
throw new ScheduleValidationError(
|
|
@@ -116,8 +132,18 @@ function localToInstant(
|
|
|
116
132
|
|
|
117
133
|
function atSpec(text: string, now: Date, tz: string): ScheduleSpec {
|
|
118
134
|
const t = text.trim()
|
|
119
|
-
|
|
120
|
-
|
|
135
|
+
const offset =
|
|
136
|
+
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2})(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})$/i.exec(
|
|
137
|
+
t,
|
|
138
|
+
)
|
|
139
|
+
if (offset) {
|
|
140
|
+
const [, year, month, day, hour, minute, second = '0'] = offset
|
|
141
|
+
const y = Number(year)
|
|
142
|
+
const mo = Number(month)
|
|
143
|
+
const d = Number(day)
|
|
144
|
+
// setUTCFullYear keeps years 0000–0099 literal.
|
|
145
|
+
const wall = new Date(0).setUTCFullYear(y, mo - 1, d)
|
|
146
|
+
validateCivilTime(wall, y, mo, d, Number(hour), Number(minute), Number(second), t)
|
|
121
147
|
const at = Date.parse(t)
|
|
122
148
|
if (!Number.isFinite(at)) throw new ScheduleValidationError(`"${t}" is not a date`, t)
|
|
123
149
|
return { kind: 'at', at: new Date(at).toISOString() }
|
|
@@ -181,7 +207,10 @@ export function parseScheduleSpec(input: string, options: ParseScheduleOptions =
|
|
|
181
207
|
text.slice(3).trim(),
|
|
182
208
|
)
|
|
183
209
|
}
|
|
184
|
-
|
|
210
|
+
const at = new Date(now.getTime() + ms)
|
|
211
|
+
if (!Number.isFinite(at.getTime()))
|
|
212
|
+
throw new ScheduleValidationError(`${text} is outside the supported date range`, text)
|
|
213
|
+
spec = { kind: 'at', at: at.toISOString() }
|
|
185
214
|
} else if (lower.startsWith('at ')) {
|
|
186
215
|
spec = atSpec(text.slice(3), now, tz)
|
|
187
216
|
} else if (/^\d{4}-\d{2}-\d{2}T/i.test(text)) {
|
package/src/schedules/types.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
import { execFile } from 'node:child_process'
|
|
15
15
|
import { readFileSync, realpathSync } from 'node:fs'
|
|
16
|
-
import { realpath } from 'node:fs/promises'
|
|
16
|
+
import { lstat, readdir, readlink, realpath } from 'node:fs/promises'
|
|
17
17
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
18
18
|
import { promisify } from 'node:util'
|
|
19
19
|
import { NAMZU } from '../../constants/telemetry/index.js'
|
|
@@ -91,6 +91,31 @@ export interface GitWorktreeDriverConfig {
|
|
|
91
91
|
|
|
92
92
|
const DEFAULT_BRANCH_PREFIX = 'namzu'
|
|
93
93
|
|
|
94
|
+
/**
|
|
95
|
+
* The refusal creating a worktree reports when the checkout it was asked to
|
|
96
|
+
* branch from does not own the Git directory it uses.
|
|
97
|
+
*
|
|
98
|
+
* `git worktree add` writes into the repository it runs in. When the Git
|
|
99
|
+
* directory is reached through a link, or is a `cp -al` copy whose files are
|
|
100
|
+
* hard links, those writes land in the checkout on the other end: the command
|
|
101
|
+
* succeeds, the new checkout looks right, and the refs and object store being
|
|
102
|
+
* changed belong to somebody else's repository. The message names what was
|
|
103
|
+
* found and what to do about it, because this is read by a person whose
|
|
104
|
+
* checkout is not what it appears to be.
|
|
105
|
+
*/
|
|
106
|
+
export class LinkedCheckoutError extends Error {
|
|
107
|
+
override readonly name = 'LinkedCheckoutError'
|
|
108
|
+
|
|
109
|
+
constructor(
|
|
110
|
+
readonly repoRoot: string,
|
|
111
|
+
readonly found: string,
|
|
112
|
+
) {
|
|
113
|
+
super(
|
|
114
|
+
`The checkout ${repoRoot} is not a plain clone: ${found}. Creating a worktree in it would write into the repository it shares its Git directory with. Clone the repository again and work in that clone.`,
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
94
119
|
/** One safe branch component: no slash, no leading dot or hyphen, no Git syntax. */
|
|
95
120
|
function isBranchPrefix(value: string): boolean {
|
|
96
121
|
return (
|
|
@@ -154,6 +179,10 @@ export class GitWorktreeDriver implements WorkspaceBackendDriver {
|
|
|
154
179
|
throw new WorkspaceBackendError({ op: 'create:ownership', kind: this.kind, cause })
|
|
155
180
|
}
|
|
156
181
|
|
|
182
|
+
// Before Git runs: a checkout that does not own the Git directory it
|
|
183
|
+
// uses would have its new worktree registered in another repository.
|
|
184
|
+
await assertSoleGitDirectory(repoRoot)
|
|
185
|
+
|
|
157
186
|
const relativePath = relative(worktreesDir, worktreePath).split(sep).join('/')
|
|
158
187
|
const branch = `${this.branchPrefix}/${relativePath}`
|
|
159
188
|
|
|
@@ -471,6 +500,91 @@ export class GitWorktreeDriver implements WorkspaceBackendDriver {
|
|
|
471
500
|
}
|
|
472
501
|
}
|
|
473
502
|
|
|
503
|
+
/**
|
|
504
|
+
* The entries of a Git directory that decide where a repository's state lives.
|
|
505
|
+
*
|
|
506
|
+
* A link on one of these hands that state to another directory, and Git run in
|
|
507
|
+
* this checkout then writes through it. A link elsewhere — `hooks`, for
|
|
508
|
+
* instance, which some setups point at a shared folder — changes nothing about
|
|
509
|
+
* where the repository is, so it is left alone.
|
|
510
|
+
*/
|
|
511
|
+
const SHARED_STATE_ENTRIES = new Set([
|
|
512
|
+
'HEAD',
|
|
513
|
+
'ORIG_HEAD',
|
|
514
|
+
'FETCH_HEAD',
|
|
515
|
+
'MERGE_HEAD',
|
|
516
|
+
'commondir',
|
|
517
|
+
'config',
|
|
518
|
+
'logs',
|
|
519
|
+
'objects',
|
|
520
|
+
'packed-refs',
|
|
521
|
+
'refs',
|
|
522
|
+
'worktrees',
|
|
523
|
+
])
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Refuse a checkout whose Git directory does not belong to it alone.
|
|
527
|
+
*
|
|
528
|
+
* `git worktree add` writes into the repository it runs in: the entry under
|
|
529
|
+
* `<git dir>/worktrees`, the branch under `refs/heads`, and the checkout's own
|
|
530
|
+
* files. That is correct only when the Git directory belongs to this checkout.
|
|
531
|
+
* A `git-new-workdir` layout — a `.git` that is a link, or a directory whose
|
|
532
|
+
* state entries are links into another repository — and a `cp -al` copy, whose
|
|
533
|
+
* files are hard links to the originals, both hand Git a directory it does not
|
|
534
|
+
* own: the command succeeds, the new checkout looks right, and the writes land
|
|
535
|
+
* in the other repository, whose refs and object store are the ones changed.
|
|
536
|
+
*
|
|
537
|
+
* Runs before Git does, and judges the Git directory and its own entries only,
|
|
538
|
+
* never the object store below them: `git clone --local` hard-links object
|
|
539
|
+
* files by design and is an ordinary, independent clone. A checkout with no
|
|
540
|
+
* `.git` at all is left to Git, which reports it better than this can, and a
|
|
541
|
+
* `.git` file is Git's own indirection — a linked worktree and a submodule both
|
|
542
|
+
* use one — so it is left alone as well.
|
|
543
|
+
*/
|
|
544
|
+
async function assertSoleGitDirectory(repoRoot: string): Promise<void> {
|
|
545
|
+
const gitDir = join(repoRoot, '.git')
|
|
546
|
+
const node = await lstat(gitDir).catch((cause) => {
|
|
547
|
+
if ((cause as NodeJS.ErrnoException).code === 'ENOENT') return undefined
|
|
548
|
+
throw cause
|
|
549
|
+
})
|
|
550
|
+
if (node === undefined) return
|
|
551
|
+
|
|
552
|
+
if (node.isSymbolicLink()) {
|
|
553
|
+
const target = await readlink(gitDir).catch(() => undefined)
|
|
554
|
+
throw new LinkedCheckoutError(
|
|
555
|
+
repoRoot,
|
|
556
|
+
`its .git is a symbolic link${target === undefined ? '' : ` to ${target}`}, so it uses another checkout's Git directory`,
|
|
557
|
+
)
|
|
558
|
+
}
|
|
559
|
+
if (!node.isDirectory()) {
|
|
560
|
+
// A `.git` file is Git's own indirection: a linked worktree
|
|
561
|
+
// (`gitdir: <common>/worktrees/<name>`) and a submodule
|
|
562
|
+
// (`gitdir: <super>/.git/modules/<name>`) both use one, and Git
|
|
563
|
+
// resolves the directory it names without writing outside it. Only a
|
|
564
|
+
// `.git` that is a link, or a directory whose state entries are links,
|
|
565
|
+
// hands Git a directory it does not own.
|
|
566
|
+
return
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
for (const name of await readdir(gitDir)) {
|
|
570
|
+
const entryPath = join(gitDir, name)
|
|
571
|
+
const entry = await lstat(entryPath)
|
|
572
|
+
if (entry.isSymbolicLink() && SHARED_STATE_ENTRIES.has(name)) {
|
|
573
|
+
const target = await readlink(entryPath).catch(() => undefined)
|
|
574
|
+
throw new LinkedCheckoutError(
|
|
575
|
+
repoRoot,
|
|
576
|
+
`its .git/${name} is a symbolic link${target === undefined ? '' : ` to ${target}`}, so Git would write through it into another checkout`,
|
|
577
|
+
)
|
|
578
|
+
}
|
|
579
|
+
if (entry.isFile() && entry.nlink > 1) {
|
|
580
|
+
throw new LinkedCheckoutError(
|
|
581
|
+
repoRoot,
|
|
582
|
+
`its .git/${name} is one of ${entry.nlink} hard links, so another checkout holds the same file`,
|
|
583
|
+
)
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
|
|
474
588
|
/** Resolve every existing path component, preserving only a missing suffix. */
|
|
475
589
|
async function canonicalizeThroughExisting(input: string): Promise<string> {
|
|
476
590
|
let existing = resolve(input)
|
|
@@ -19,7 +19,12 @@ export type {
|
|
|
19
19
|
|
|
20
20
|
export { WorkspaceBackendRegistry } from './registry.js'
|
|
21
21
|
|
|
22
|
-
export {
|
|
22
|
+
export {
|
|
23
|
+
GitWorktreeDriver,
|
|
24
|
+
LinkedCheckoutError,
|
|
25
|
+
defaultWorktreesDir,
|
|
26
|
+
parseWorktreeList,
|
|
27
|
+
} from './git-worktree.js'
|
|
23
28
|
export type { ExecFile, ExecFileResult, GitWorktreeDriverConfig } from './git-worktree.js'
|
|
24
29
|
|
|
25
30
|
export {
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto'
|
|
2
2
|
import type { CheckpointId, SessionId, TenantId, TurnId } from '../../types/ids/index.js'
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
type Checkpoint,
|
|
5
|
+
parseCheckpoint,
|
|
6
|
+
persistedTokenUsage,
|
|
7
|
+
} from '../../types/session/checkpoint.js'
|
|
4
8
|
import type { ProjectId } from '../../types/session/ids.js'
|
|
5
9
|
import { asCheckpointId, asProjectId, asSessionId, asTenantId, asTurnId } from '../../utils/id.js'
|
|
6
10
|
|
|
@@ -197,7 +201,10 @@ export class CheckpointOwnerError extends Error {
|
|
|
197
201
|
|
|
198
202
|
/** Refuse a write whose document names another session or turn than its scope. */
|
|
199
203
|
export function checkWriteOwner(scope: CheckpointScope, checkpoint: Checkpoint): Checkpoint {
|
|
200
|
-
const parsed = parseCheckpoint(
|
|
204
|
+
const parsed = parseCheckpoint({
|
|
205
|
+
...checkpoint,
|
|
206
|
+
tokenUsage: persistedTokenUsage(checkpoint.tokenUsage),
|
|
207
|
+
})
|
|
201
208
|
if (parsed.sessionId !== scope.sessionId || parsed.turnId !== scope.turnId) {
|
|
202
209
|
throw new CheckpointOwnerError(
|
|
203
210
|
`Checkpoint ${parsed.checkpointId} belongs to session ${parsed.sessionId} turn ${parsed.turnId}; it cannot be written under session ${scope.sessionId} turn ${scope.turnId}.`,
|
|
@@ -943,13 +943,17 @@ export class SqliteSessionIndex extends SessionIndexBase {
|
|
|
943
943
|
|
|
944
944
|
async listChildren(sessionId: SessionId): Promise<ChildSessionSummary[]> {
|
|
945
945
|
await this.settledFor(sessionId)
|
|
946
|
-
|
|
946
|
+
const rows = this.#all(
|
|
947
947
|
'SELECT * FROM children WHERE session_id = ? ORDER BY spawned_at, child_id',
|
|
948
948
|
sessionId,
|
|
949
|
-
)
|
|
949
|
+
)
|
|
950
|
+
const children: ChildSessionSummary[] = []
|
|
951
|
+
for (const row of rows) {
|
|
950
952
|
const child = childRow(row)
|
|
951
|
-
|
|
952
|
-
|
|
953
|
+
await this.settledFor(child.childId)
|
|
954
|
+
children.push(childView(child, this.readSession(child.childId)))
|
|
955
|
+
}
|
|
956
|
+
return children
|
|
953
957
|
}
|
|
954
958
|
|
|
955
959
|
async listPendingDecisions(
|