@agentex/agent 0.0.23 → 0.0.26
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 +338 -0
- package/LICENSE +21 -0
- package/README.md +110 -0
- package/dist/derived.d.ts +5 -3
- package/dist/derived.d.ts.map +1 -1
- package/dist/derived.js +11 -7
- package/dist/derived.js.map +1 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/providers/acp/index.d.ts +1 -1
- package/dist/providers/acp/index.d.ts.map +1 -1
- package/dist/providers/acp/index.js +5 -97
- package/dist/providers/acp/index.js.map +1 -1
- package/dist/providers/acp/session.d.ts +8 -1
- package/dist/providers/acp/session.d.ts.map +1 -1
- package/dist/providers/acp/session.js +94 -0
- package/dist/providers/acp/session.js.map +1 -1
- package/dist/providers/claude/attach.d.ts +8 -0
- package/dist/providers/claude/attach.d.ts.map +1 -0
- package/dist/providers/claude/attach.js +113 -0
- package/dist/providers/claude/attach.js.map +1 -0
- package/dist/providers/claude/execute.d.ts.map +1 -1
- package/dist/providers/claude/execute.js +17 -2
- package/dist/providers/claude/execute.js.map +1 -1
- package/dist/providers/claude/goal-capability.d.ts +15 -0
- package/dist/providers/claude/goal-capability.d.ts.map +1 -0
- package/dist/providers/claude/goal-capability.js +20 -0
- package/dist/providers/claude/goal-capability.js.map +1 -0
- package/dist/providers/claude/index.d.ts.map +1 -1
- package/dist/providers/claude/index.js +8 -4
- package/dist/providers/claude/index.js.map +1 -1
- package/dist/providers/claude/session.d.ts +11 -9
- package/dist/providers/claude/session.d.ts.map +1 -1
- package/dist/providers/claude/session.js +36 -14
- package/dist/providers/claude/session.js.map +1 -1
- package/dist/providers/codex/attach.d.ts +9 -0
- package/dist/providers/codex/attach.d.ts.map +1 -0
- package/dist/providers/codex/attach.js +93 -0
- package/dist/providers/codex/attach.js.map +1 -0
- package/dist/providers/codex/execute.d.ts.map +1 -1
- package/dist/providers/codex/execute.js +17 -3
- package/dist/providers/codex/execute.js.map +1 -1
- package/dist/providers/codex/goal-capability.d.ts +13 -0
- package/dist/providers/codex/goal-capability.d.ts.map +1 -0
- package/dist/providers/codex/goal-capability.js +18 -0
- package/dist/providers/codex/goal-capability.js.map +1 -0
- package/dist/providers/codex/index.d.ts +1 -0
- package/dist/providers/codex/index.d.ts.map +1 -1
- package/dist/providers/codex/index.js +9 -6
- package/dist/providers/codex/index.js.map +1 -1
- package/dist/providers/codex/session.d.ts +11 -7
- package/dist/providers/codex/session.d.ts.map +1 -1
- package/dist/providers/codex/session.js +37 -12
- package/dist/providers/codex/session.js.map +1 -1
- package/dist/providers/codex/transcript-normalize.d.ts +28 -0
- package/dist/providers/codex/transcript-normalize.d.ts.map +1 -0
- package/dist/providers/codex/transcript-normalize.js +191 -0
- package/dist/providers/codex/transcript-normalize.js.map +1 -0
- package/dist/providers/cursor/index.d.ts.map +1 -1
- package/dist/providers/cursor/index.js +2 -2
- package/dist/providers/cursor/index.js.map +1 -1
- package/dist/providers/openclaw/index.d.ts.map +1 -1
- package/dist/providers/openclaw/index.js +2 -2
- package/dist/providers/openclaw/index.js.map +1 -1
- package/dist/providers/opencode/index.d.ts.map +1 -1
- package/dist/providers/opencode/index.js +3 -5
- package/dist/providers/opencode/index.js.map +1 -1
- package/dist/providers/pi/index.d.ts.map +1 -1
- package/dist/providers/pi/index.js +3 -5
- package/dist/providers/pi/index.js.map +1 -1
- package/dist/providers/process/index.d.ts.map +1 -1
- package/dist/providers/process/index.js +2 -2
- package/dist/providers/process/index.js.map +1 -1
- package/dist/registry.d.ts +0 -1
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +0 -4
- package/dist/registry.js.map +1 -1
- package/dist/sessions/index.d.ts +3 -0
- package/dist/sessions/index.d.ts.map +1 -0
- package/dist/sessions/index.js +2 -0
- package/dist/sessions/index.js.map +1 -0
- package/dist/sessions/record.d.ts +43 -0
- package/dist/sessions/record.d.ts.map +1 -0
- package/dist/sessions/record.js +85 -0
- package/dist/sessions/record.js.map +1 -0
- package/dist/types.d.ts +176 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/endpoint.d.ts +38 -0
- package/dist/utils/endpoint.d.ts.map +1 -0
- package/dist/utils/endpoint.js +151 -0
- package/dist/utils/endpoint.js.map +1 -0
- package/dist/utils/env.d.ts.map +1 -1
- package/dist/utils/env.js +5 -1
- package/dist/utils/env.js.map +1 -1
- package/dist/utils/uuid.d.ts +7 -1
- package/dist/utils/uuid.d.ts.map +1 -1
- package/dist/utils/uuid.js +21 -1
- package/dist/utils/uuid.js.map +1 -1
- package/package.json +64 -7
- package/src/derived.ts +311 -0
- package/src/goals/controller.ts +442 -0
- package/src/goals/index.ts +21 -0
- package/src/goals/normalize.ts +173 -0
- package/src/goals/sentinel.ts +90 -0
- package/src/index.ts +270 -0
- package/src/providers/_shared/http-agent.ts +304 -0
- package/src/providers/acp/index.ts +103 -0
- package/src/providers/acp/parse.ts +131 -0
- package/src/providers/acp/session.ts +744 -0
- package/src/providers/claude/attach.ts +147 -0
- package/src/providers/claude/codec.ts +43 -0
- package/src/providers/claude/execute.ts +300 -0
- package/src/providers/claude/goal-capability.ts +21 -0
- package/src/providers/claude/index.ts +72 -0
- package/src/providers/claude/mcp.ts +82 -0
- package/src/providers/claude/parse.ts +824 -0
- package/src/providers/claude/session.ts +1192 -0
- package/src/providers/claude/transcript.ts +555 -0
- package/src/providers/codex/attach.ts +123 -0
- package/src/providers/codex/codec.ts +50 -0
- package/src/providers/codex/execute.ts +337 -0
- package/src/providers/codex/goal-capability.ts +19 -0
- package/src/providers/codex/index.ts +57 -0
- package/src/providers/codex/modes.ts +159 -0
- package/src/providers/codex/parse.ts +691 -0
- package/src/providers/codex/plan-mode.ts +49 -0
- package/src/providers/codex/session.ts +1287 -0
- package/src/providers/codex/transcript-normalize.ts +197 -0
- package/src/providers/codex/transcript.ts +487 -0
- package/src/providers/codex/usage-scanner.ts +178 -0
- package/src/providers/copilot/index.ts +19 -0
- package/src/providers/cursor/codec.ts +44 -0
- package/src/providers/cursor/execute.ts +271 -0
- package/src/providers/cursor/index.ts +25 -0
- package/src/providers/cursor/parse.ts +288 -0
- package/src/providers/gemini/index.ts +21 -0
- package/src/providers/openclaw/codec.ts +40 -0
- package/src/providers/openclaw/execute.ts +19 -0
- package/src/providers/openclaw/index.ts +29 -0
- package/src/providers/opencode/codec.ts +50 -0
- package/src/providers/opencode/event-parse.ts +141 -0
- package/src/providers/opencode/execute.ts +251 -0
- package/src/providers/opencode/http-session.ts +427 -0
- package/src/providers/opencode/index.ts +30 -0
- package/src/providers/opencode/parse.ts +203 -0
- package/src/providers/opencode/server.ts +0 -0
- package/src/providers/pi/codec.ts +44 -0
- package/src/providers/pi/execute.ts +297 -0
- package/src/providers/pi/index.ts +30 -0
- package/src/providers/pi/parse.ts +231 -0
- package/src/providers/pi/session.ts +381 -0
- package/src/providers/process/execute.ts +148 -0
- package/src/providers/process/index.ts +52 -0
- package/src/registry.ts +40 -0
- package/src/sessions/index.ts +8 -0
- package/src/sessions/record.ts +108 -0
- package/src/types.ts +1638 -0
- package/src/utils/ask-user-question.ts +57 -0
- package/src/utils/auth.ts +661 -0
- package/src/utils/binary.ts +179 -0
- package/src/utils/endpoint.ts +172 -0
- package/src/utils/env.ts +63 -0
- package/src/utils/execute-all.ts +68 -0
- package/src/utils/exit-plan-mode.ts +40 -0
- package/src/utils/instructions.ts +427 -0
- package/src/utils/process.ts +223 -0
- package/src/utils/runtime-config.ts +100 -0
- package/src/utils/runtime-homes.ts +49 -0
- package/src/utils/skill-commands.ts +493 -0
- package/src/utils/skills.ts +500 -0
- package/src/utils/template.ts +16 -0
- package/src/utils/tool-names.ts +51 -0
- package/src/utils/uuid.ts +21 -0
- package/src/utils/workspace.ts +156 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import * as os from "node:os";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { execFile } from "node:child_process";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
import { uuidv7 } from "./uuid.js";
|
|
6
|
+
|
|
7
|
+
const exec = promisify(execFile);
|
|
8
|
+
|
|
9
|
+
export interface WorkspaceOptions {
|
|
10
|
+
/** Isolation strategy */
|
|
11
|
+
strategy: "worktree";
|
|
12
|
+
/** Base branch to create worktree from (default: current HEAD) */
|
|
13
|
+
baseBranch?: string;
|
|
14
|
+
/** Custom branch name (default: auto-generated) */
|
|
15
|
+
branchName?: string;
|
|
16
|
+
/** Custom directory for the worktree (default: os.tmpdir()) */
|
|
17
|
+
targetDir?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface DiffOptions {
|
|
21
|
+
/** Ref to compare against (default: the base branch used when creating the worktree). */
|
|
22
|
+
base?: string;
|
|
23
|
+
/**
|
|
24
|
+
* What to include in the diff:
|
|
25
|
+
* - "all" — committed + uncommitted + untracked (default)
|
|
26
|
+
* - "committed" — only changes committed to the worktree branch vs base
|
|
27
|
+
* - "uncommitted" — only staged + unstaged changes in the working tree
|
|
28
|
+
* - "untracked" — only new files not yet tracked by git
|
|
29
|
+
*/
|
|
30
|
+
scope?: "all" | "committed" | "uncommitted" | "untracked";
|
|
31
|
+
/** Return `--stat` summary instead of full patch. */
|
|
32
|
+
stat?: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface PreparedWorkspace {
|
|
36
|
+
/** Path to the worktree directory — use as `cwd` for execute() */
|
|
37
|
+
cwd: string;
|
|
38
|
+
/** Branch name created for this worktree */
|
|
39
|
+
branch: string;
|
|
40
|
+
/** The strategy that was used */
|
|
41
|
+
strategy: "worktree";
|
|
42
|
+
/** The original repo path */
|
|
43
|
+
originalCwd: string;
|
|
44
|
+
/**
|
|
45
|
+
* Get a unified diff of changes in this worktree.
|
|
46
|
+
*
|
|
47
|
+
* With no arguments, returns everything that changed (committed + uncommitted + untracked).
|
|
48
|
+
* Use `options.scope` to narrow, `options.base` to compare against a different ref,
|
|
49
|
+
* or `options.stat` for a summary.
|
|
50
|
+
*/
|
|
51
|
+
diff(options?: DiffOptions | string): Promise<string>;
|
|
52
|
+
/** Remove the worktree and optionally delete the branch */
|
|
53
|
+
cleanup(options?: { deleteBranch?: boolean }): Promise<void>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Create an isolated workspace for agent execution.
|
|
58
|
+
*
|
|
59
|
+
* Uses `git worktree add` to create a lightweight checkout on a new branch.
|
|
60
|
+
* The worktree shares git history with the original repo, so diffs, merges,
|
|
61
|
+
* and PRs all work normally.
|
|
62
|
+
*/
|
|
63
|
+
export async function prepareWorkspace(
|
|
64
|
+
cwd: string,
|
|
65
|
+
options: WorkspaceOptions,
|
|
66
|
+
): Promise<PreparedWorkspace> {
|
|
67
|
+
// Validate git repo
|
|
68
|
+
try {
|
|
69
|
+
await exec("git", ["rev-parse", "--git-dir"], { cwd });
|
|
70
|
+
} catch {
|
|
71
|
+
throw new Error(`Not a git repository: ${cwd}`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const shortId = uuidv7().slice(0, 8);
|
|
75
|
+
const branch = options.branchName ?? `agentex/${Date.now()}-${shortId}`;
|
|
76
|
+
const targetDir = options.targetDir ?? path.join(os.tmpdir(), `agentex-ws-${shortId}`);
|
|
77
|
+
|
|
78
|
+
// Create worktree
|
|
79
|
+
const worktreeArgs = ["worktree", "add", targetDir, "-b", branch];
|
|
80
|
+
if (options.baseBranch) {
|
|
81
|
+
worktreeArgs.push(options.baseBranch);
|
|
82
|
+
}
|
|
83
|
+
await exec("git", worktreeArgs, { cwd });
|
|
84
|
+
|
|
85
|
+
const baseBranch = options.baseBranch ?? "main";
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
cwd: targetDir,
|
|
89
|
+
branch,
|
|
90
|
+
strategy: "worktree",
|
|
91
|
+
originalCwd: cwd,
|
|
92
|
+
|
|
93
|
+
async diff(optionsOrBase?: DiffOptions | string): Promise<string> {
|
|
94
|
+
const opts: DiffOptions = typeof optionsOrBase === "string"
|
|
95
|
+
? { base: optionsOrBase }
|
|
96
|
+
: optionsOrBase ?? {};
|
|
97
|
+
const diffBase = opts.base ?? baseBranch;
|
|
98
|
+
const scope = opts.scope ?? "all";
|
|
99
|
+
const statFlag = opts.stat ? ["--stat"] : [];
|
|
100
|
+
|
|
101
|
+
const parts: string[] = [];
|
|
102
|
+
|
|
103
|
+
// Committed changes: base...branch (only commits on the branch)
|
|
104
|
+
if (scope === "all" || scope === "committed") {
|
|
105
|
+
const { stdout } = await exec(
|
|
106
|
+
"git", ["diff", ...statFlag, `${diffBase}...${branch}`],
|
|
107
|
+
{ cwd },
|
|
108
|
+
);
|
|
109
|
+
if (stdout.trim()) parts.push(stdout);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Uncommitted changes: staged + unstaged vs HEAD
|
|
113
|
+
if (scope === "all" || scope === "uncommitted") {
|
|
114
|
+
const { stdout } = await exec(
|
|
115
|
+
"git", ["diff", ...statFlag, "HEAD"],
|
|
116
|
+
{ cwd: targetDir },
|
|
117
|
+
);
|
|
118
|
+
if (stdout.trim()) parts.push(stdout);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Untracked files: new files not yet staged
|
|
122
|
+
if (scope === "all" || scope === "untracked") {
|
|
123
|
+
const { stdout: untrackedRaw } = await exec(
|
|
124
|
+
"git", ["ls-files", "--others", "--exclude-standard"],
|
|
125
|
+
{ cwd: targetDir },
|
|
126
|
+
);
|
|
127
|
+
const untrackedFiles = untrackedRaw.split("\n").filter(Boolean);
|
|
128
|
+
|
|
129
|
+
if (opts.stat) {
|
|
130
|
+
// Stat mode: just list filenames with (new) marker
|
|
131
|
+
for (const f of untrackedFiles) {
|
|
132
|
+
parts.push(` ${f} (new file)`);
|
|
133
|
+
}
|
|
134
|
+
} else if (untrackedFiles.length > 0) {
|
|
135
|
+
// Full diff: use git diff with --no-index against /dev/null in a single call
|
|
136
|
+
// Stage temporarily, diff, then unstage — faster than per-file diff
|
|
137
|
+
await exec("git", ["add", "--intent-to-add", ...untrackedFiles], { cwd: targetDir });
|
|
138
|
+
const { stdout } = await exec("git", ["diff", ...untrackedFiles], { cwd: targetDir });
|
|
139
|
+
await exec("git", ["reset", "HEAD", ...untrackedFiles], { cwd: targetDir });
|
|
140
|
+
if (stdout.trim()) parts.push(stdout);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return parts.join("\n");
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
async cleanup(opts?: { deleteBranch?: boolean }): Promise<void> {
|
|
148
|
+
await exec("git", ["worktree", "remove", targetDir, "--force"], { cwd });
|
|
149
|
+
if (opts?.deleteBranch) {
|
|
150
|
+
await exec("git", ["branch", "-D", branch], { cwd }).catch(() => {
|
|
151
|
+
// Branch may already be deleted or not exist
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
}
|