@cjhyy/code-shell-core 0.7.0 → 0.7.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/dist/arena/arena.d.ts +2 -0
- package/dist/arena/arena.js +30 -1
- package/dist/arena/phases/adjudication.d.ts +2 -1
- package/dist/arena/phases/adjudication.js +2 -1
- package/dist/arena/phases/build-consensus.d.ts +2 -1
- package/dist/arena/phases/build-consensus.js +3 -1
- package/dist/arena/phases/cross-review.d.ts +3 -1
- package/dist/arena/phases/cross-review.js +8 -2
- package/dist/arena/phases/debate-rounds.d.ts +2 -1
- package/dist/arena/phases/debate-rounds.js +4 -2
- package/dist/arena/phases/participant-research.d.ts +2 -1
- package/dist/arena/phases/participant-research.js +3 -1
- package/dist/arena/phases/planning-detail-expansion.d.ts +2 -1
- package/dist/arena/phases/planning-detail-expansion.js +2 -1
- package/dist/arena/planner.d.ts +2 -1
- package/dist/arena/planner.js +2 -1
- package/dist/arena/types.d.ts +5 -1
- package/dist/cli/agent-server-tcp.js +13 -2
- package/dist/context/manager.d.ts +3 -3
- package/dist/context/manager.js +6 -6
- package/dist/context/token-counter.js +5 -3
- package/dist/context/tool-result-storage.d.ts +6 -0
- package/dist/context/tool-result-storage.js +25 -4
- package/dist/credentials/access.d.ts +10 -1
- package/dist/credentials/access.js +76 -2
- package/dist/credentials/index.d.ts +3 -2
- package/dist/credentials/index.js +2 -1
- package/dist/credentials/oauth.d.ts +6 -1
- package/dist/credentials/oauth.js +66 -1
- package/dist/credentials/store.d.ts +1 -1
- package/dist/credentials/store.js +16 -7
- package/dist/credentials/types.d.ts +38 -1
- package/dist/credentials/types.js +16 -1
- package/dist/engine/engine.d.ts +61 -32
- package/dist/engine/engine.js +289 -55
- package/dist/engine/goal.d.ts +5 -3
- package/dist/engine/session-title.d.ts +2 -1
- package/dist/engine/session-title.js +4 -1
- package/dist/engine/turn-loop.d.ts +18 -0
- package/dist/engine/turn-loop.js +202 -27
- package/dist/engine/types.d.ts +6 -2
- package/dist/git/worktree/crud.d.ts +3 -0
- package/dist/git/worktree/crud.js +32 -3
- package/dist/git/worktree/git-exec.d.ts +2 -2
- package/dist/git/worktree/git-exec.js +47 -11
- package/dist/git/worktree/query.d.ts +8 -7
- package/dist/git/worktree/query.js +27 -20
- package/dist/hooks/events.d.ts +3 -0
- package/dist/hooks/events.js +0 -3
- package/dist/hooks/goal-stop-hook.d.ts +14 -4
- package/dist/hooks/goal-stop-hook.js +626 -71
- package/dist/hooks/registry.js +3 -0
- package/dist/hooks/shell-runner.d.ts +12 -1
- package/dist/hooks/shell-runner.js +160 -9
- package/dist/index.d.ts +7 -6
- package/dist/index.js +6 -5
- package/dist/llm/client-base.js +12 -10
- package/dist/llm/types.d.ts +12 -5
- package/dist/plugins/pluginCommandHook.d.ts +4 -4
- package/dist/plugins/pluginCommandHook.js +111 -13
- package/dist/protocol/chat-session-manager.d.ts +13 -2
- package/dist/protocol/chat-session-manager.js +90 -18
- package/dist/protocol/chat-session.d.ts +12 -0
- package/dist/protocol/chat-session.js +30 -5
- package/dist/protocol/client.d.ts +5 -2
- package/dist/protocol/client.js +22 -1
- package/dist/protocol/server.d.ts +25 -11
- package/dist/protocol/server.js +290 -72
- package/dist/protocol/types.d.ts +34 -2
- package/dist/protocol/types.js +2 -0
- package/dist/services/dream-consolidation.d.ts +3 -0
- package/dist/services/dream-consolidation.js +4 -1
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +1 -1
- package/dist/services/oauth.d.ts +34 -10
- package/dist/services/oauth.js +233 -98
- package/dist/session/session-manager.d.ts +35 -6
- package/dist/session/session-manager.js +362 -26
- package/dist/session/transcript.d.ts +30 -1
- package/dist/session/transcript.js +119 -4
- package/dist/tool-system/builtin/agent.js +5 -1
- package/dist/tool-system/builtin/arena.js +1 -0
- package/dist/tool-system/builtin/background-jobs.d.ts +8 -5
- package/dist/tool-system/builtin/background-jobs.js +15 -11
- package/dist/tool-system/builtin/background-work.d.ts +6 -1
- package/dist/tool-system/builtin/background-work.js +5 -1
- package/dist/tool-system/builtin/bash.d.ts +3 -5
- package/dist/tool-system/builtin/bash.js +10 -5
- package/dist/tool-system/builtin/browser-tools.d.ts +2 -2
- package/dist/tool-system/builtin/edit.d.ts +2 -1
- package/dist/tool-system/builtin/edit.js +12 -4
- package/dist/tool-system/builtin/generate-video.d.ts +4 -0
- package/dist/tool-system/builtin/generate-video.js +138 -21
- package/dist/tool-system/builtin/glob.d.ts +2 -1
- package/dist/tool-system/builtin/glob.js +28 -3
- package/dist/tool-system/builtin/grep.d.ts +1 -0
- package/dist/tool-system/builtin/grep.js +82 -17
- package/dist/tool-system/builtin/index.d.ts +25 -11
- package/dist/tool-system/builtin/index.js +45 -2
- package/dist/tool-system/builtin/video-providers.d.ts +12 -15
- package/dist/tool-system/builtin/video-providers.js +1 -0
- package/dist/tool-system/builtin/view-image.d.ts +2 -2
- package/dist/tool-system/builtin/web-fetch.js +44 -3
- package/dist/tool-system/builtin/worktree.js +25 -7
- package/dist/tool-system/builtin/write.d.ts +2 -1
- package/dist/tool-system/builtin/write.js +14 -4
- package/dist/tool-system/context.d.ts +17 -5
- package/dist/tool-system/executor.js +24 -8
- package/dist/tool-system/mcp-manager.d.ts +6 -0
- package/dist/tool-system/mcp-manager.js +55 -5
- package/dist/tool-system/path-policy.d.ts +19 -0
- package/dist/tool-system/path-policy.js +62 -1
- package/dist/tool-system/permission.d.ts +43 -3
- package/dist/tool-system/permission.js +383 -30
- package/dist/tool-system/registry.d.ts +3 -2
- package/dist/tool-system/registry.js +52 -34
- package/dist/types.d.ts +15 -0
- package/package.json +1 -1
|
@@ -1,16 +1,50 @@
|
|
|
1
1
|
import { execFile, execFileSync } from "node:child_process";
|
|
2
|
-
import {
|
|
2
|
+
import { killChildTree } from "../../runtime/spawn-common.js";
|
|
3
3
|
import { resolveExecutable } from "../../utils/exec.js";
|
|
4
4
|
// git resolved via PATH×PATHEXT on Windows (.cmd/.exe shim); no-op on POSIX.
|
|
5
5
|
export const GIT_BIN = resolveExecutable("git");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
export async function execGit(cwd, args, timeout = 10000, signal) {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
if (signal?.aborted) {
|
|
9
|
+
reject(signal.reason);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
let settled = false;
|
|
13
|
+
const child = execFile(GIT_BIN, args, { cwd, encoding: "utf-8" }, (error, stdout, stderr) => {
|
|
14
|
+
if (settled)
|
|
15
|
+
return;
|
|
16
|
+
settled = true;
|
|
17
|
+
cleanup();
|
|
18
|
+
if (error) {
|
|
19
|
+
Object.assign(error, { stdout, stderr });
|
|
20
|
+
reject(error);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
resolve(stdout);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
const terminate = (error) => {
|
|
27
|
+
if (settled)
|
|
28
|
+
return;
|
|
29
|
+
settled = true;
|
|
30
|
+
cleanup();
|
|
31
|
+
killChildTree(child, 1000);
|
|
32
|
+
reject(error);
|
|
33
|
+
};
|
|
34
|
+
const onAbort = () => terminate(signal?.reason ?? Object.assign(new Error("Git command aborted"), { name: "AbortError" }));
|
|
35
|
+
const timer = setTimeout(() => {
|
|
36
|
+
terminate(Object.assign(new Error(`Git command timed out after ${timeout}ms`), {
|
|
37
|
+
code: "ETIMEDOUT",
|
|
38
|
+
}));
|
|
39
|
+
}, timeout);
|
|
40
|
+
const cleanup = () => {
|
|
41
|
+
clearTimeout(timer);
|
|
42
|
+
signal?.removeEventListener("abort", onAbort);
|
|
43
|
+
};
|
|
44
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
45
|
+
if (signal?.aborted)
|
|
46
|
+
onAbort();
|
|
12
47
|
});
|
|
13
|
-
return stdout;
|
|
14
48
|
}
|
|
15
49
|
export function execGitSync(cwd, args, timeout = 10000) {
|
|
16
50
|
return execFileSync(GIT_BIN, args, {
|
|
@@ -19,11 +53,13 @@ export function execGitSync(cwd, args, timeout = 10000) {
|
|
|
19
53
|
timeout,
|
|
20
54
|
});
|
|
21
55
|
}
|
|
22
|
-
export async function gitOutput(cwd, args, timeout = 10000) {
|
|
56
|
+
export async function gitOutput(cwd, args, timeout = 10000, signal) {
|
|
23
57
|
try {
|
|
24
|
-
return await execGit(cwd, args, timeout);
|
|
58
|
+
return await execGit(cwd, args, timeout, signal);
|
|
25
59
|
}
|
|
26
|
-
catch {
|
|
60
|
+
catch (error) {
|
|
61
|
+
if (signal?.aborted)
|
|
62
|
+
throw error;
|
|
27
63
|
return undefined;
|
|
28
64
|
}
|
|
29
65
|
}
|
|
@@ -9,6 +9,7 @@ export interface ListWorktreesFastOptions {
|
|
|
9
9
|
workspaceOwners?: WorktreeWorkspaceOwner[];
|
|
10
10
|
owners?: WorktreeWorkspaceOwner[];
|
|
11
11
|
prefix?: string;
|
|
12
|
+
signal?: AbortSignal;
|
|
12
13
|
}
|
|
13
14
|
export interface ListWorktreesOptions extends ListWorktreesFastOptions {
|
|
14
15
|
includeDiffSummary?: boolean;
|
|
@@ -26,13 +27,13 @@ export interface WorktreeInfo {
|
|
|
26
27
|
/**
|
|
27
28
|
* Find the canonical git root (resolves worktree -> main repo).
|
|
28
29
|
*/
|
|
29
|
-
export declare function findGitRoot(cwd: string): Promise<string>;
|
|
30
|
-
export declare function findMainWorktreeRoot(cwd: string): Promise<string>;
|
|
31
|
-
export declare function findWorktreeForBranch(cwd: string, branch: string): Promise<string | undefined>;
|
|
32
|
-
export declare function assertBranchNotCheckedOut(cwd: string, branch: string): Promise<void>;
|
|
33
|
-
export declare function branchExists(cwd: string, branch: string): Promise<boolean>;
|
|
34
|
-
export declare function isGitWorktreeRoot(cwd: string): Promise<boolean>;
|
|
35
|
-
export declare function currentBranch(cwd: string): Promise<string | undefined>;
|
|
30
|
+
export declare function findGitRoot(cwd: string, signal?: AbortSignal): Promise<string>;
|
|
31
|
+
export declare function findMainWorktreeRoot(cwd: string, signal?: AbortSignal): Promise<string>;
|
|
32
|
+
export declare function findWorktreeForBranch(cwd: string, branch: string, signal?: AbortSignal): Promise<string | undefined>;
|
|
33
|
+
export declare function assertBranchNotCheckedOut(cwd: string, branch: string, signal?: AbortSignal): Promise<void>;
|
|
34
|
+
export declare function branchExists(cwd: string, branch: string, signal?: AbortSignal): Promise<boolean>;
|
|
35
|
+
export declare function isGitWorktreeRoot(cwd: string, signal?: AbortSignal): Promise<boolean>;
|
|
36
|
+
export declare function currentBranch(cwd: string, signal?: AbortSignal): Promise<string | undefined>;
|
|
36
37
|
export declare function listWorktreesFast(cwd: string, opts?: ListWorktreesFastOptions): Promise<WorktreeInfo[]>;
|
|
37
38
|
/**
|
|
38
39
|
* List active worktrees. Kept for internal/test compatibility; use
|
|
@@ -6,51 +6,56 @@ import { isManagedWorktreeBranch } from "./slug.js";
|
|
|
6
6
|
/**
|
|
7
7
|
* Find the canonical git root (resolves worktree -> main repo).
|
|
8
8
|
*/
|
|
9
|
-
export async function findGitRoot(cwd) {
|
|
10
|
-
return await findMainWorktreeRoot(cwd);
|
|
9
|
+
export async function findGitRoot(cwd, signal) {
|
|
10
|
+
return await findMainWorktreeRoot(cwd, signal);
|
|
11
11
|
}
|
|
12
|
-
export async function findMainWorktreeRoot(cwd) {
|
|
13
|
-
const commonDir = (await execGit(cwd, ["rev-parse", "--path-format=absolute", "--git-common-dir"], 5000)).trim();
|
|
12
|
+
export async function findMainWorktreeRoot(cwd, signal) {
|
|
13
|
+
const commonDir = (await execGit(cwd, ["rev-parse", "--path-format=absolute", "--git-common-dir"], 5000, signal)).trim();
|
|
14
14
|
return dirname(commonDir);
|
|
15
15
|
}
|
|
16
|
-
export async function findWorktreeForBranch(cwd, branch) {
|
|
16
|
+
export async function findWorktreeForBranch(cwd, branch, signal) {
|
|
17
17
|
const normalized = normalizeBranchName(branch);
|
|
18
|
-
return (await listWorktreesFast(cwd)).find((entry) => entry.branch === normalized)
|
|
18
|
+
return (await listWorktreesFast(cwd, { signal })).find((entry) => entry.branch === normalized)
|
|
19
|
+
?.path;
|
|
19
20
|
}
|
|
20
|
-
export async function assertBranchNotCheckedOut(cwd, branch) {
|
|
21
|
-
const existingPath = await findWorktreeForBranch(cwd, branch);
|
|
21
|
+
export async function assertBranchNotCheckedOut(cwd, branch, signal) {
|
|
22
|
+
const existingPath = await findWorktreeForBranch(cwd, branch, signal);
|
|
22
23
|
if (existingPath) {
|
|
23
24
|
throw new Error(`branch ${normalizeBranchName(branch)} already checked out at ${existingPath}`);
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
|
-
export async function branchExists(cwd, branch) {
|
|
27
|
-
const out = await gitOutput(cwd, ["branch", "--list", normalizeBranchName(branch)], 10000);
|
|
27
|
+
export async function branchExists(cwd, branch, signal) {
|
|
28
|
+
const out = await gitOutput(cwd, ["branch", "--list", normalizeBranchName(branch)], 10000, signal);
|
|
28
29
|
return (out?.trim().length ?? 0) > 0;
|
|
29
30
|
}
|
|
30
|
-
export async function isGitWorktreeRoot(cwd) {
|
|
31
|
+
export async function isGitWorktreeRoot(cwd, signal) {
|
|
31
32
|
if (!existsSync(join(cwd, ".git")))
|
|
32
33
|
return false;
|
|
33
34
|
try {
|
|
34
|
-
const inside = (await execGit(cwd, ["rev-parse", "--is-inside-work-tree"], 5000)).trim();
|
|
35
|
+
const inside = (await execGit(cwd, ["rev-parse", "--is-inside-work-tree"], 5000, signal)).trim();
|
|
35
36
|
if (inside !== "true")
|
|
36
37
|
return false;
|
|
37
|
-
const topLevel = (await execGit(cwd, ["rev-parse", "--path-format=absolute", "--show-toplevel"], 5000)).trim();
|
|
38
|
+
const topLevel = (await execGit(cwd, ["rev-parse", "--path-format=absolute", "--show-toplevel"], 5000, signal)).trim();
|
|
38
39
|
return resolve(topLevel) === resolve(cwd);
|
|
39
40
|
}
|
|
40
|
-
catch {
|
|
41
|
+
catch (error) {
|
|
42
|
+
if (signal?.aborted)
|
|
43
|
+
throw error;
|
|
41
44
|
return false;
|
|
42
45
|
}
|
|
43
46
|
}
|
|
44
|
-
export async function currentBranch(cwd) {
|
|
45
|
-
const branch = (await gitOutput(cwd, ["branch", "--show-current"], 5000))?.trim();
|
|
47
|
+
export async function currentBranch(cwd, signal) {
|
|
48
|
+
const branch = (await gitOutput(cwd, ["branch", "--show-current"], 5000, signal))?.trim();
|
|
46
49
|
return branch || undefined;
|
|
47
50
|
}
|
|
48
51
|
export async function listWorktreesFast(cwd, opts = {}) {
|
|
49
52
|
let raw;
|
|
50
53
|
try {
|
|
51
|
-
raw = (await execGit(cwd, ["worktree", "list", "--porcelain"], 10000)).trim();
|
|
54
|
+
raw = (await execGit(cwd, ["worktree", "list", "--porcelain"], 10000, opts.signal)).trim();
|
|
52
55
|
}
|
|
53
|
-
catch {
|
|
56
|
+
catch (error) {
|
|
57
|
+
if (opts.signal?.aborted)
|
|
58
|
+
throw error;
|
|
54
59
|
return [];
|
|
55
60
|
}
|
|
56
61
|
if (!raw)
|
|
@@ -74,9 +79,11 @@ export async function listWorktreesFast(cwd, opts = {}) {
|
|
|
74
79
|
entries.push(current);
|
|
75
80
|
let mainRoot = "";
|
|
76
81
|
try {
|
|
77
|
-
mainRoot = await findMainWorktreeRoot(cwd);
|
|
82
|
+
mainRoot = await findMainWorktreeRoot(cwd, opts.signal);
|
|
78
83
|
}
|
|
79
|
-
catch {
|
|
84
|
+
catch (error) {
|
|
85
|
+
if (opts.signal?.aborted)
|
|
86
|
+
throw error;
|
|
80
87
|
mainRoot = entries[0]?.path ?? "";
|
|
81
88
|
}
|
|
82
89
|
const owners = opts.workspaceOwners ?? opts.owners ?? [];
|
package/dist/hooks/events.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hook event type definitions.
|
|
3
3
|
*/
|
|
4
|
+
import type { GoalTerminationReason } from "../engine/goal.js";
|
|
4
5
|
/**
|
|
5
6
|
* Lifecycle hooks the engine emits.
|
|
6
7
|
*
|
|
@@ -104,6 +105,8 @@ export interface HookResult {
|
|
|
104
105
|
* chain). Ignored for non-on_stop events. Bounded by maxStopBlocks.
|
|
105
106
|
*/
|
|
106
107
|
continueSession?: boolean;
|
|
108
|
+
/** For on_stop: typed Goal-run stop outcome propagated to TurnLoop/Engine. */
|
|
109
|
+
goalTermination?: GoalTerminationReason;
|
|
107
110
|
/** Modified data to pass along */
|
|
108
111
|
data?: Record<string, unknown>;
|
|
109
112
|
/** Additional messages to inject */
|
package/dist/hooks/events.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { HookHandler } from "./registry.js";
|
|
2
|
-
import type { LLMResponse, ToolResult } from "../types.js";
|
|
2
|
+
import type { LLMResponse, TokenUsage, 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 {
|
|
6
|
+
/** Main-generation request timeout; the judge derives a shorter ceiling. */
|
|
7
|
+
readonly timeout?: number;
|
|
6
8
|
createMessage(options: {
|
|
7
9
|
systemPrompt: string;
|
|
8
10
|
messages: {
|
|
@@ -11,7 +13,8 @@ export interface GoalJudgeLLM {
|
|
|
11
13
|
}[];
|
|
12
14
|
stream?: boolean;
|
|
13
15
|
maxTokens?: number;
|
|
14
|
-
|
|
16
|
+
billingEnabled?: boolean;
|
|
17
|
+
requestVisible?: boolean;
|
|
15
18
|
signal?: AbortSignal;
|
|
16
19
|
/** Reasoning control — the judge always asks for it OFF (see call site). */
|
|
17
20
|
reasoning?: import("../llm/reasoning-setting.js").ReasoningSetting;
|
|
@@ -58,7 +61,14 @@ export interface GoalStopHookOptions {
|
|
|
58
61
|
* It deliberately lives on this closure rather than HookContext.data so
|
|
59
62
|
* third-party/public stop hooks do not gain access to tool output.
|
|
60
63
|
*/
|
|
61
|
-
getJudgeContext
|
|
64
|
+
getJudgeContext: () => GoalJudgeRuntimeContext | undefined;
|
|
65
|
+
/** Dedicated judge deadline. Defaults to 15s and never exceeds the main timeout. */
|
|
66
|
+
judgeTimeoutMs?: number;
|
|
67
|
+
/**
|
|
68
|
+
* Private usage seam into TurnLoop's Goal ledger. Returning a termination
|
|
69
|
+
* reason prevents verdict side effects and lets the loop stop immediately.
|
|
70
|
+
*/
|
|
71
|
+
onJudgeUsage?: (usage: TokenUsage | undefined) => "token_budget_exhausted" | "time_budget_exhausted" | undefined;
|
|
62
72
|
}
|
|
63
73
|
export interface GoalJudgeRuntimeContext {
|
|
64
74
|
/** Recent irreversible projections from this run, newest evidence retained by TurnLoop. */
|
|
@@ -85,6 +95,6 @@ export interface GoalJudgeToolResult {
|
|
|
85
95
|
omittedNonText?: true;
|
|
86
96
|
}
|
|
87
97
|
/** Build the bounded, irreversible value retained beyond the current model round. */
|
|
88
|
-
export declare function projectGoalJudgeToolResult(result: ToolResult, turnCount: number): GoalJudgeToolResult;
|
|
98
|
+
export declare function projectGoalJudgeToolResult(result: ToolResult, turnCount: number, sensitiveByMetadata?: boolean): GoalJudgeToolResult;
|
|
89
99
|
export declare function createGoalStopHook(opts: GoalStopHookOptions): HookHandler;
|
|
90
100
|
export {};
|