@cjhyy/code-shell-core 0.6.0-rc.9 → 0.7.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/THIRD_PARTY_NOTICES.md +206 -0
- package/dist/automation/scheduler.d.ts +13 -7
- package/dist/automation/scheduler.js +116 -37
- package/dist/capability-control/service.d.ts +2 -0
- package/dist/capability-control/service.js +4 -2
- package/dist/cc-orchestrator/agent-adapter.d.ts +4 -0
- package/dist/cc-orchestrator/agent-adapter.js +11 -1
- package/dist/cc-orchestrator/codex-session-history.d.ts +14 -1
- package/dist/cc-orchestrator/codex-session-history.js +65 -5
- package/dist/cc-orchestrator/cwd-normalize.d.ts +2 -0
- package/dist/cc-orchestrator/cwd-normalize.js +19 -0
- package/dist/cc-orchestrator/external-agent-bindings.d.ts +27 -0
- package/dist/cc-orchestrator/external-agent-bindings.js +150 -0
- package/dist/cc-orchestrator/external-agent-changes.js +22 -5
- package/dist/cc-orchestrator/external-agent-driver.d.ts +1 -0
- package/dist/cc-orchestrator/external-agent-driver.js +265 -50
- package/dist/cc-orchestrator/external-agent-session-store.d.ts +23 -0
- package/dist/cc-orchestrator/external-agent-session-store.js +146 -0
- package/dist/cc-orchestrator/session-history.d.ts +35 -0
- package/dist/cc-orchestrator/session-history.js +98 -15
- package/dist/cli/agent-server-stdio.js +9 -2
- package/dist/context/compaction.d.ts +8 -1
- package/dist/context/compaction.js +49 -4
- package/dist/context/manager.d.ts +16 -2
- package/dist/context/manager.js +103 -19
- package/dist/credentials/access.d.ts +57 -0
- package/dist/credentials/access.js +185 -0
- package/dist/credentials/index.d.ts +3 -1
- package/dist/credentials/index.js +2 -0
- package/dist/credentials/inject-credential-tool.d.ts +3 -1
- package/dist/credentials/inject-credential-tool.js +30 -11
- package/dist/credentials/oauth.d.ts +20 -0
- package/dist/credentials/oauth.js +114 -0
- package/dist/credentials/store.d.ts +1 -0
- package/dist/credentials/store.js +3 -1
- package/dist/credentials/types.d.ts +49 -3
- package/dist/credentials/use-credential-tool.d.ts +9 -1
- package/dist/credentials/use-credential-tool.js +58 -45
- package/dist/engine/engine.d.ts +23 -3
- package/dist/engine/engine.js +380 -255
- package/dist/engine/goal.d.ts +17 -0
- package/dist/engine/goal.js +16 -6
- package/dist/engine/image-policy.d.ts +6 -0
- package/dist/engine/image-policy.js +17 -6
- package/dist/engine/input-attachments.d.ts +13 -0
- package/dist/engine/input-attachments.js +398 -0
- package/dist/engine/model-facade.d.ts +5 -2
- package/dist/engine/model-facade.js +4 -4
- package/dist/engine/parse-task.d.ts +10 -0
- package/dist/engine/parse-task.js +5 -0
- package/dist/engine/run-image-input.d.ts +22 -0
- package/dist/engine/run-image-input.js +195 -0
- package/dist/engine/steer-queue.d.ts +3 -1
- package/dist/engine/steer-queue.js +10 -2
- package/dist/engine/streaming-tool-queue.d.ts +11 -7
- package/dist/engine/streaming-tool-queue.js +11 -7
- package/dist/engine/turn-loop.d.ts +37 -2
- package/dist/engine/turn-loop.js +228 -43
- package/dist/engine/types.d.ts +8 -0
- package/dist/git/worktree/crud.d.ts +69 -0
- package/dist/git/worktree/crud.js +206 -0
- package/dist/git/worktree/diff.d.ts +14 -0
- package/dist/git/worktree/diff.js +82 -0
- package/dist/git/worktree/git-exec.d.ts +7 -0
- package/dist/git/worktree/git-exec.js +51 -0
- package/dist/git/worktree/index.d.ts +5 -0
- package/dist/git/worktree/index.js +5 -0
- package/dist/git/worktree/query.d.ts +42 -0
- package/dist/git/worktree/query.js +121 -0
- package/dist/git/worktree/slug.d.ts +11 -0
- package/dist/git/worktree/slug.js +58 -0
- package/dist/git/worktree.d.ts +1 -84
- package/dist/git/worktree.js +5 -230
- package/dist/hooks/goal-stop-hook.d.ts +33 -1
- package/dist/hooks/goal-stop-hook.js +202 -34
- package/dist/index.d.ts +31 -28
- package/dist/index.js +27 -25
- package/dist/logging/logger.js +6 -6
- package/dist/logging/sanitize-messages.d.ts +10 -2
- package/dist/logging/sanitize-messages.js +21 -6
- package/dist/plugins/installer/checkUpdate.d.ts +4 -1
- package/dist/plugins/installer/checkUpdate.js +4 -2
- package/dist/plugins/installer/install.js +2 -0
- package/dist/plugins/installer/installFromSource.js +9 -1
- package/dist/plugins/installer/parseSource.d.ts +4 -1
- package/dist/plugins/installer/parseSource.js +28 -10
- package/dist/plugins/installer/sourcePath.d.ts +9 -0
- package/dist/plugins/installer/sourcePath.js +50 -0
- package/dist/plugins/installer/update.d.ts +4 -1
- package/dist/plugins/installer/update.js +5 -3
- package/dist/plugins/parseMarketplaceInput.d.ts +4 -1
- package/dist/plugins/parseMarketplaceInput.js +4 -3
- package/dist/plugins/pluginInstaller.js +24 -22
- package/dist/preset/index.d.ts +1 -0
- package/dist/preset/index.js +30 -13
- package/dist/prompt/sections/base.md +1 -1
- package/dist/protocol/chat-session-manager.d.ts +2 -0
- package/dist/protocol/chat-session-manager.js +38 -2
- package/dist/protocol/chat-session.d.ts +3 -0
- package/dist/protocol/chat-session.js +1 -0
- package/dist/protocol/client.d.ts +9 -4
- package/dist/protocol/client.js +18 -1
- package/dist/protocol/server.d.ts +30 -0
- package/dist/protocol/server.js +247 -47
- package/dist/protocol/types.d.ts +49 -0
- package/dist/protocol/types.js +6 -0
- package/dist/run/FileRunStore.js +10 -1
- package/dist/run/Heartbeat.js +12 -0
- package/dist/run/RunApprovalBackend.d.ts +3 -0
- package/dist/run/RunApprovalBackend.js +41 -6
- package/dist/run/RunLock.js +2 -0
- package/dist/run/RunManager.d.ts +2 -0
- package/dist/run/RunManager.js +64 -24
- package/dist/run/ids.d.ts +2 -0
- package/dist/run/ids.js +23 -0
- package/dist/runtime/background-shell.d.ts +1 -0
- package/dist/runtime/background-shell.js +23 -13
- package/dist/runtime/spawn-common.js +10 -0
- package/dist/services/auto-dream.d.ts +15 -4
- package/dist/services/auto-dream.js +20 -20
- package/dist/services/dream-consolidation.d.ts +2 -3
- package/dist/services/dream-consolidation.js +65 -15
- package/dist/services/extract-memories.d.ts +14 -5
- package/dist/services/extract-memories.js +20 -3
- package/dist/services/global-dream-promotion.d.ts +23 -0
- package/dist/services/global-dream-promotion.js +112 -0
- package/dist/services/memory-orchestrator.js +347 -34
- package/dist/session/memory.d.ts +61 -18
- package/dist/session/memory.js +342 -79
- package/dist/session/session-manager.d.ts +35 -1
- package/dist/session/session-manager.js +224 -4
- package/dist/session/transcript.d.ts +1 -1
- package/dist/session/transcript.js +17 -5
- package/dist/settings/manager.d.ts +1 -0
- package/dist/settings/manager.js +87 -37
- package/dist/settings/schema-export.d.ts +2 -3
- package/dist/settings/schema-export.js +2 -3
- package/dist/settings/schema.d.ts +21 -0
- package/dist/settings/schema.js +12 -0
- package/dist/skills/scanner.d.ts +3 -2
- package/dist/skills/scanner.js +12 -9
- package/dist/tool-system/builtin/agent-notifications.d.ts +11 -4
- package/dist/tool-system/builtin/agent-notifications.js +19 -7
- package/dist/tool-system/builtin/background-jobs.d.ts +35 -6
- package/dist/tool-system/builtin/background-jobs.js +116 -7
- package/dist/tool-system/builtin/background-work.d.ts +17 -18
- package/dist/tool-system/builtin/background-work.js +51 -5
- package/dist/tool-system/builtin/config.d.ts +2 -1
- package/dist/tool-system/builtin/config.js +16 -11
- package/dist/tool-system/builtin/cron-list.definition.d.ts +3 -0
- package/dist/tool-system/builtin/cron-list.definition.js +6 -0
- package/dist/tool-system/builtin/cron.d.ts +1 -2
- package/dist/tool-system/builtin/cron.js +9 -7
- package/dist/tool-system/builtin/drive-claude-code.d.ts +23 -2
- package/dist/tool-system/builtin/drive-claude-code.js +589 -48
- package/dist/tool-system/builtin/edit.js +5 -2
- package/dist/tool-system/builtin/generate-video.d.ts +1 -0
- package/dist/tool-system/builtin/generate-video.js +13 -4
- package/dist/tool-system/builtin/index.d.ts +8 -3
- package/dist/tool-system/builtin/index.js +50 -22
- package/dist/tool-system/builtin/lsp.d.ts +2 -1
- package/dist/tool-system/builtin/lsp.js +6 -3
- package/dist/tool-system/builtin/memory.js +40 -8
- package/dist/tool-system/builtin/notebook-edit.js +5 -2
- package/dist/tool-system/builtin/powershell.d.ts +5 -2
- package/dist/tool-system/builtin/powershell.js +11 -7
- package/dist/tool-system/builtin/read.js +118 -6
- package/dist/tool-system/builtin/sleep.d.ts +1 -2
- package/dist/tool-system/builtin/sleep.definition.d.ts +8 -0
- package/dist/tool-system/builtin/sleep.definition.js +28 -0
- package/dist/tool-system/builtin/sleep.js +1 -22
- package/dist/tool-system/builtin/view-image.d.ts +2 -2
- package/dist/tool-system/builtin/view-image.js +109 -19
- package/dist/tool-system/builtin/worktree.d.ts +4 -4
- package/dist/tool-system/builtin/worktree.js +297 -74
- package/dist/tool-system/builtin/write.js +5 -3
- package/dist/tool-system/context.d.ts +41 -1
- package/dist/tool-system/executor.d.ts +1 -5
- package/dist/tool-system/executor.js +94 -115
- package/dist/tool-system/mcp-manager.d.ts +31 -6
- package/dist/tool-system/mcp-manager.js +193 -78
- package/dist/tool-system/path-policy.d.ts +2 -0
- package/dist/tool-system/path-policy.js +41 -12
- package/dist/tool-system/permission.d.ts +28 -7
- package/dist/tool-system/permission.js +130 -49
- package/dist/tool-system/registry.js +11 -4
- package/dist/tool-system/tool-result-redaction.d.ts +7 -0
- package/dist/tool-system/tool-result-redaction.js +48 -0
- package/dist/tool-system/workspace-bridge.d.ts +11 -0
- package/dist/tool-system/workspace-bridge.js +1 -0
- package/dist/types.d.ts +78 -11
- package/dist/utils/toolDisplay.js +1 -1
- package/package.json +4 -3
package/dist/git/worktree.d.ts
CHANGED
|
@@ -1,84 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Git worktree management — create/remove isolated worktrees for agents.
|
|
3
|
-
*/
|
|
4
|
-
import type { SandboxBackend } from "../tool-system/sandbox/index.js";
|
|
5
|
-
export interface WorktreeSession {
|
|
6
|
-
originalCwd: string;
|
|
7
|
-
worktreePath: string;
|
|
8
|
-
worktreeName: string;
|
|
9
|
-
worktreeBranch: string;
|
|
10
|
-
originalBranch?: string;
|
|
11
|
-
sessionId: string;
|
|
12
|
-
createdAt: number;
|
|
13
|
-
}
|
|
14
|
-
/** Per-platform setup/cleanup scripts (a project's localEnvironment). */
|
|
15
|
-
export interface PlatformScripts {
|
|
16
|
-
default?: string;
|
|
17
|
-
macos?: string;
|
|
18
|
-
linux?: string;
|
|
19
|
-
windows?: string;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Pick the setup/cleanup script for the running platform, falling back to
|
|
23
|
-
* `default`. Empty/whitespace-only scripts are treated as absent so a project
|
|
24
|
-
* can leave a platform key blank without spawning an empty shell. `platform`
|
|
25
|
-
* defaults to `process.platform` so callers usually omit it; tests pass a
|
|
26
|
-
* fixed value.
|
|
27
|
-
*/
|
|
28
|
-
export declare function selectPlatformScript(scripts: PlatformScripts | undefined, platform?: NodeJS.Platform): string | undefined;
|
|
29
|
-
/**
|
|
30
|
-
* Validate worktree slug to prevent path traversal attacks.
|
|
31
|
-
*/
|
|
32
|
-
export declare function validateWorktreeSlug(slug: string): void;
|
|
33
|
-
/**
|
|
34
|
-
* Find the canonical git root (resolves worktree → main repo).
|
|
35
|
-
*/
|
|
36
|
-
export declare function findGitRoot(cwd: string): string;
|
|
37
|
-
/**
|
|
38
|
-
* Create an isolated git worktree for an agent session.
|
|
39
|
-
*/
|
|
40
|
-
export declare function createWorktree(cwd: string, slug: string, sessionId: string): WorktreeSession;
|
|
41
|
-
export interface WorktreeSetupResult {
|
|
42
|
-
/** True if no setup script was configured for this platform (nothing ran). */
|
|
43
|
-
skipped: boolean;
|
|
44
|
-
/** True if a script ran and exited 0. */
|
|
45
|
-
ok: boolean;
|
|
46
|
-
/** Combined stdout/stderr, for surfacing to the user on failure. */
|
|
47
|
-
output: string;
|
|
48
|
-
/** Exit code when a script ran; undefined when skipped. */
|
|
49
|
-
exitCode?: number | null;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Run a project's `localEnvironment.setupScripts` once, in the freshly-created
|
|
53
|
-
* worktree's root, right after `git worktree add`. This mirrors Codex's
|
|
54
|
-
* local-environment semantics: setup belongs to the *worktree* lifecycle, not
|
|
55
|
-
* the conversation — it runs when the isolated copy is born so e.g. `bun
|
|
56
|
-
* install` or `cp .env.example .env` happens before the agent works there.
|
|
57
|
-
*
|
|
58
|
-
* Failure is non-fatal by design (Beta decision 2026-06-08, "警告但继续"): a
|
|
59
|
-
* broken setup script shouldn't strand the agent outside a worktree it already
|
|
60
|
-
* created. The caller surfaces `output` as a warning and proceeds. cleanup
|
|
61
|
-
* scripts are intentionally NOT auto-run on exit (same decision).
|
|
62
|
-
*
|
|
63
|
-
* Reuses the same sandbox + env primitives as the Bash tool so the setup
|
|
64
|
-
* command sees the project's `localEnvironment.env` and runs under the same
|
|
65
|
-
* isolation the agent's later commands will.
|
|
66
|
-
*/
|
|
67
|
-
export declare function runWorktreeSetup(worktreePath: string, script: string | undefined, opts?: {
|
|
68
|
-
sandbox?: SandboxBackend;
|
|
69
|
-
shellEnv?: Record<string, string>;
|
|
70
|
-
timeoutMs?: number;
|
|
71
|
-
signal?: AbortSignal;
|
|
72
|
-
}): Promise<WorktreeSetupResult>;
|
|
73
|
-
/**
|
|
74
|
-
* Remove a worktree and optionally its branch.
|
|
75
|
-
*/
|
|
76
|
-
export declare function removeWorktree(worktreePath: string, removeBranch?: boolean): void;
|
|
77
|
-
/**
|
|
78
|
-
* List active worktrees.
|
|
79
|
-
*/
|
|
80
|
-
export declare function listWorktrees(cwd: string): Array<{
|
|
81
|
-
path: string;
|
|
82
|
-
branch: string;
|
|
83
|
-
head: string;
|
|
84
|
-
}>;
|
|
1
|
+
export * from "./worktree/index.js";
|
package/dist/git/worktree.js
CHANGED
|
@@ -1,230 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { join, resolve, dirname } from "node:path";
|
|
7
|
-
import { safeSpawnShell } from "../runtime/safe-spawn.js";
|
|
8
|
-
import { buildSandboxEnv, mergeShellEnv, defaultShellBinary } from "../runtime/spawn-common.js";
|
|
9
|
-
import { resolveExecutable } from "../utils/exec.js";
|
|
10
|
-
// git resolved via PATH×PATHEXT on Windows (.cmd/.exe shim); no-op on POSIX.
|
|
11
|
-
const GIT_BIN = resolveExecutable("git");
|
|
12
|
-
/**
|
|
13
|
-
* Pick the setup/cleanup script for the running platform, falling back to
|
|
14
|
-
* `default`. Empty/whitespace-only scripts are treated as absent so a project
|
|
15
|
-
* can leave a platform key blank without spawning an empty shell. `platform`
|
|
16
|
-
* defaults to `process.platform` so callers usually omit it; tests pass a
|
|
17
|
-
* fixed value.
|
|
18
|
-
*/
|
|
19
|
-
export function selectPlatformScript(scripts, platform = process.platform) {
|
|
20
|
-
if (!scripts)
|
|
21
|
-
return undefined;
|
|
22
|
-
const key = platform === "darwin" ? "macos" : platform === "win32" ? "windows" : "linux";
|
|
23
|
-
// A blank platform key shouldn't shadow a real `default` — fall through.
|
|
24
|
-
const platformScript = scripts[key]?.trim() ? scripts[key] : undefined;
|
|
25
|
-
const candidate = platformScript ?? scripts.default;
|
|
26
|
-
const trimmed = candidate?.trim();
|
|
27
|
-
return trimmed ? candidate : undefined;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Validate worktree slug to prevent path traversal attacks.
|
|
31
|
-
*/
|
|
32
|
-
export function validateWorktreeSlug(slug) {
|
|
33
|
-
if (slug.length > 64)
|
|
34
|
-
throw new Error("Worktree slug too long (max 64 chars)");
|
|
35
|
-
if (/[^a-zA-Z0-9._-]/.test(slug))
|
|
36
|
-
throw new Error("Worktree slug contains invalid characters");
|
|
37
|
-
if (slug.startsWith(".") || slug.includes(".."))
|
|
38
|
-
throw new Error("Worktree slug cannot start with '.' or contain '..'");
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Find the canonical git root (resolves worktree → main repo).
|
|
42
|
-
*/
|
|
43
|
-
export function findGitRoot(cwd) {
|
|
44
|
-
return execFileSync(GIT_BIN, ["rev-parse", "--show-toplevel"], { cwd, encoding: "utf-8", timeout: 5000 }).trim();
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Create an isolated git worktree for an agent session.
|
|
48
|
-
*/
|
|
49
|
-
export function createWorktree(cwd, slug, sessionId) {
|
|
50
|
-
validateWorktreeSlug(slug);
|
|
51
|
-
const gitRoot = findGitRoot(cwd);
|
|
52
|
-
const branchName = `worktree/${slug}-${sessionId.slice(0, 8)}`;
|
|
53
|
-
const worktreePath = resolve(gitRoot, "..", `.worktrees/${slug}-${sessionId.slice(0, 8)}`);
|
|
54
|
-
// Get current branch for later reference
|
|
55
|
-
let originalBranch;
|
|
56
|
-
try {
|
|
57
|
-
originalBranch = execFileSync(GIT_BIN, ["branch", "--show-current"], {
|
|
58
|
-
cwd: gitRoot,
|
|
59
|
-
encoding: "utf-8",
|
|
60
|
-
timeout: 5000,
|
|
61
|
-
}).trim();
|
|
62
|
-
}
|
|
63
|
-
catch {
|
|
64
|
-
// Detached HEAD
|
|
65
|
-
}
|
|
66
|
-
// Create the worktree. Pre-fix this used a quoted command string; the argv
|
|
67
|
-
// form keeps branchName/worktreePath as literal positional arguments even
|
|
68
|
-
// if a future caller bypasses validateWorktreeSlug.
|
|
69
|
-
execFileSync(GIT_BIN, ["worktree", "add", "-b", branchName, worktreePath], {
|
|
70
|
-
cwd: gitRoot,
|
|
71
|
-
timeout: 30000,
|
|
72
|
-
});
|
|
73
|
-
// Symlink large directories to avoid disk bloat
|
|
74
|
-
symlinkLargeDirectories(gitRoot, worktreePath);
|
|
75
|
-
return {
|
|
76
|
-
originalCwd: cwd,
|
|
77
|
-
worktreePath,
|
|
78
|
-
worktreeName: slug,
|
|
79
|
-
worktreeBranch: branchName,
|
|
80
|
-
originalBranch,
|
|
81
|
-
sessionId,
|
|
82
|
-
createdAt: Date.now(),
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Run a project's `localEnvironment.setupScripts` once, in the freshly-created
|
|
87
|
-
* worktree's root, right after `git worktree add`. This mirrors Codex's
|
|
88
|
-
* local-environment semantics: setup belongs to the *worktree* lifecycle, not
|
|
89
|
-
* the conversation — it runs when the isolated copy is born so e.g. `bun
|
|
90
|
-
* install` or `cp .env.example .env` happens before the agent works there.
|
|
91
|
-
*
|
|
92
|
-
* Failure is non-fatal by design (Beta decision 2026-06-08, "警告但继续"): a
|
|
93
|
-
* broken setup script shouldn't strand the agent outside a worktree it already
|
|
94
|
-
* created. The caller surfaces `output` as a warning and proceeds. cleanup
|
|
95
|
-
* scripts are intentionally NOT auto-run on exit (same decision).
|
|
96
|
-
*
|
|
97
|
-
* Reuses the same sandbox + env primitives as the Bash tool so the setup
|
|
98
|
-
* command sees the project's `localEnvironment.env` and runs under the same
|
|
99
|
-
* isolation the agent's later commands will.
|
|
100
|
-
*/
|
|
101
|
-
export async function runWorktreeSetup(worktreePath, script, opts = {}) {
|
|
102
|
-
const trimmed = script?.trim();
|
|
103
|
-
if (!trimmed)
|
|
104
|
-
return { skipped: true, ok: true, output: "" };
|
|
105
|
-
const shell = defaultShellBinary();
|
|
106
|
-
const backend = opts.sandbox;
|
|
107
|
-
const baseEnv = backend && backend.name !== "off" ? buildSandboxEnv() : { ...process.env };
|
|
108
|
-
const env = mergeShellEnv(baseEnv, opts.shellEnv);
|
|
109
|
-
const result = await safeSpawnShell(trimmed, {
|
|
110
|
-
cwd: worktreePath,
|
|
111
|
-
env,
|
|
112
|
-
timeoutMs: opts.timeoutMs ?? 120_000,
|
|
113
|
-
maxOutputBytes: 1024 * 1024,
|
|
114
|
-
sandbox: backend,
|
|
115
|
-
shell,
|
|
116
|
-
signal: opts.signal,
|
|
117
|
-
});
|
|
118
|
-
const parts = [];
|
|
119
|
-
if (result.stdout)
|
|
120
|
-
parts.push(result.stdout);
|
|
121
|
-
if (result.stderr)
|
|
122
|
-
parts.push(result.stderr);
|
|
123
|
-
const output = parts.join("\n").trim();
|
|
124
|
-
if (result.aborted)
|
|
125
|
-
return { skipped: false, ok: false, output: output || "setup aborted" };
|
|
126
|
-
if (result.timedOut)
|
|
127
|
-
return { skipped: false, ok: false, output: output || "setup timed out" };
|
|
128
|
-
if (result.spawnFailed) {
|
|
129
|
-
return { skipped: false, ok: false, output: result.error ?? "failed to spawn setup script" };
|
|
130
|
-
}
|
|
131
|
-
return { skipped: false, ok: result.exitCode === 0, output, exitCode: result.exitCode };
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Remove a worktree and optionally its branch.
|
|
135
|
-
*/
|
|
136
|
-
export function removeWorktree(worktreePath, removeBranch = false) {
|
|
137
|
-
try {
|
|
138
|
-
// The MAIN repo root, not the worktree's own toplevel. `git rev-parse
|
|
139
|
-
// --show-toplevel` from inside a worktree returns the worktree path, which
|
|
140
|
-
// is about to be deleted; the branch-delete must run from the main repo,
|
|
141
|
-
// which outlives the worktree. Derive it from the common git dir.
|
|
142
|
-
const commonDir = execFileSync(GIT_BIN, ["rev-parse", "--path-format=absolute", "--git-common-dir"], { cwd: worktreePath, encoding: "utf-8", timeout: 5000 }).trim();
|
|
143
|
-
const mainRoot = dirname(commonDir); // <main>/.git → <main>
|
|
144
|
-
// Capture the worktree's branch BEFORE removing the worktree — afterwards
|
|
145
|
-
// the directory is gone and `git branch --show-current` in it would fail
|
|
146
|
-
// (silently, leaving removeBranch a no-op).
|
|
147
|
-
let branch = "";
|
|
148
|
-
if (removeBranch) {
|
|
149
|
-
try {
|
|
150
|
-
branch = execFileSync(GIT_BIN, ["branch", "--show-current"], {
|
|
151
|
-
cwd: worktreePath,
|
|
152
|
-
encoding: "utf-8",
|
|
153
|
-
timeout: 5000,
|
|
154
|
-
}).trim();
|
|
155
|
-
}
|
|
156
|
-
catch {
|
|
157
|
-
// Detached HEAD or unreadable — nothing to delete.
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
execFileSync(GIT_BIN, ["worktree", "remove", worktreePath, "--force"], {
|
|
161
|
-
cwd: mainRoot,
|
|
162
|
-
timeout: 30000,
|
|
163
|
-
});
|
|
164
|
-
if (removeBranch && branch.startsWith("worktree/")) {
|
|
165
|
-
try {
|
|
166
|
-
execFileSync(GIT_BIN, ["branch", "-D", branch], { cwd: mainRoot, timeout: 10000 });
|
|
167
|
-
}
|
|
168
|
-
catch {
|
|
169
|
-
// Branch might already be removed.
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
catch {
|
|
174
|
-
// Worktree might already be removed
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* List active worktrees.
|
|
179
|
-
*/
|
|
180
|
-
export function listWorktrees(cwd) {
|
|
181
|
-
const raw = execFileSync(GIT_BIN, ["worktree", "list", "--porcelain"], {
|
|
182
|
-
cwd,
|
|
183
|
-
encoding: "utf-8",
|
|
184
|
-
timeout: 10000,
|
|
185
|
-
}).trim();
|
|
186
|
-
if (!raw)
|
|
187
|
-
return [];
|
|
188
|
-
const entries = [];
|
|
189
|
-
let current = { path: "", branch: "", head: "" };
|
|
190
|
-
for (const line of raw.split("\n")) {
|
|
191
|
-
if (line.startsWith("worktree ")) {
|
|
192
|
-
if (current.path)
|
|
193
|
-
entries.push(current);
|
|
194
|
-
current = { path: line.slice(9), branch: "", head: "" };
|
|
195
|
-
}
|
|
196
|
-
else if (line.startsWith("HEAD ")) {
|
|
197
|
-
current.head = line.slice(5, 13);
|
|
198
|
-
}
|
|
199
|
-
else if (line.startsWith("branch ")) {
|
|
200
|
-
current.branch = line.slice(7).replace("refs/heads/", "");
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
if (current.path)
|
|
204
|
-
entries.push(current);
|
|
205
|
-
return entries;
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Symlink large directories (node_modules, .venv, etc.) from main repo to worktree.
|
|
209
|
-
*/
|
|
210
|
-
function symlinkLargeDirectories(sourceRoot, worktreePath) {
|
|
211
|
-
const largeDirs = ["node_modules", ".venv", "vendor", ".pnpm-store"];
|
|
212
|
-
// Windows directory symlinks need admin/Developer Mode and throw EPERM for a
|
|
213
|
-
// normal user; NTFS junctions don't and behave the same for our purpose
|
|
214
|
-
// (share node_modules into the worktree). Use "junction" on win32, "dir"
|
|
215
|
-
// elsewhere. Failure stays non-fatal — the worktree just doesn't share dirs.
|
|
216
|
-
const linkType = process.platform === "win32" ? "junction" : "dir";
|
|
217
|
-
for (const dir of largeDirs) {
|
|
218
|
-
const source = join(sourceRoot, dir);
|
|
219
|
-
const target = join(worktreePath, dir);
|
|
220
|
-
if (existsSync(source) && lstatSync(source).isDirectory() && !existsSync(target)) {
|
|
221
|
-
try {
|
|
222
|
-
symlinkSync(source, target, linkType);
|
|
223
|
-
}
|
|
224
|
-
catch {
|
|
225
|
-
// Symlink/junction might fail on some systems — non-fatal, the
|
|
226
|
-
// worktree just won't share this directory (more disk, still works).
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
1
|
+
// Compatibility barrel for the pre-split worktree module. The split made the
|
|
2
|
+
// query/create APIs async because they now share the async git executor; all
|
|
3
|
+
// in-repo callers await them, so this barrel intentionally does not add sync
|
|
4
|
+
// wrappers.
|
|
5
|
+
export * from "./worktree/index.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { HookHandler } from "./registry.js";
|
|
2
|
-
import type { LLMResponse } from "../types.js";
|
|
2
|
+
import type { LLMResponse, ToolResult } from "../types.js";
|
|
3
3
|
import { type GoalConfig } from "../engine/goal.js";
|
|
4
4
|
/** Narrow LLM surface the judge needs — just a one-shot completion. */
|
|
5
5
|
export interface GoalJudgeLLM {
|
|
@@ -53,6 +53,38 @@ export interface GoalStopHookOptions {
|
|
|
53
53
|
* `() => new Date()`.
|
|
54
54
|
*/
|
|
55
55
|
now?: () => Date;
|
|
56
|
+
/**
|
|
57
|
+
* Private runtime evidence supplied by TurnLoop immediately before on_stop.
|
|
58
|
+
* It deliberately lives on this closure rather than HookContext.data so
|
|
59
|
+
* third-party/public stop hooks do not gain access to tool output.
|
|
60
|
+
*/
|
|
61
|
+
getJudgeContext?: () => GoalJudgeRuntimeContext | undefined;
|
|
62
|
+
}
|
|
63
|
+
export interface GoalJudgeRuntimeContext {
|
|
64
|
+
/** Recent irreversible projections from this run, newest evidence retained by TurnLoop. */
|
|
65
|
+
toolResults: GoalJudgeToolResult[];
|
|
66
|
+
progress: {
|
|
67
|
+
turnCount: number;
|
|
68
|
+
/** One-based natural-stop/judge round for this run. */
|
|
69
|
+
stopRound: number;
|
|
70
|
+
elapsedMs: number;
|
|
71
|
+
tokensUsed: number;
|
|
72
|
+
tokenBudget?: number;
|
|
73
|
+
timeBudgetMs?: number;
|
|
74
|
+
maxTurns?: number;
|
|
75
|
+
maxStopBlocks?: number;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export interface GoalJudgeToolResult {
|
|
79
|
+
turnCount: number;
|
|
80
|
+
toolName: string;
|
|
81
|
+
status: "success" | "error";
|
|
82
|
+
/** Bounded plain text only; absent for sensitive or purely non-text results. */
|
|
83
|
+
text?: string;
|
|
84
|
+
/** True when image/binary/structured blocks were replaced with a placeholder. */
|
|
85
|
+
omittedNonText?: true;
|
|
56
86
|
}
|
|
87
|
+
/** Build the bounded, irreversible value retained beyond the current model round. */
|
|
88
|
+
export declare function projectGoalJudgeToolResult(result: ToolResult, turnCount: number): GoalJudgeToolResult;
|
|
57
89
|
export declare function createGoalStopHook(opts: GoalStopHookOptions): HookHandler;
|
|
58
90
|
export {};
|