@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.
Files changed (177) hide show
  1. package/CHANGELOG.md +338 -0
  2. package/LICENSE +21 -0
  3. package/README.md +110 -0
  4. package/dist/derived.d.ts +5 -3
  5. package/dist/derived.d.ts.map +1 -1
  6. package/dist/derived.js +11 -7
  7. package/dist/derived.js.map +1 -1
  8. package/dist/index.d.ts +7 -1
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +4 -0
  11. package/dist/index.js.map +1 -1
  12. package/dist/providers/acp/index.d.ts +1 -1
  13. package/dist/providers/acp/index.d.ts.map +1 -1
  14. package/dist/providers/acp/index.js +5 -97
  15. package/dist/providers/acp/index.js.map +1 -1
  16. package/dist/providers/acp/session.d.ts +8 -1
  17. package/dist/providers/acp/session.d.ts.map +1 -1
  18. package/dist/providers/acp/session.js +94 -0
  19. package/dist/providers/acp/session.js.map +1 -1
  20. package/dist/providers/claude/attach.d.ts +8 -0
  21. package/dist/providers/claude/attach.d.ts.map +1 -0
  22. package/dist/providers/claude/attach.js +113 -0
  23. package/dist/providers/claude/attach.js.map +1 -0
  24. package/dist/providers/claude/execute.d.ts.map +1 -1
  25. package/dist/providers/claude/execute.js +17 -2
  26. package/dist/providers/claude/execute.js.map +1 -1
  27. package/dist/providers/claude/goal-capability.d.ts +15 -0
  28. package/dist/providers/claude/goal-capability.d.ts.map +1 -0
  29. package/dist/providers/claude/goal-capability.js +20 -0
  30. package/dist/providers/claude/goal-capability.js.map +1 -0
  31. package/dist/providers/claude/index.d.ts.map +1 -1
  32. package/dist/providers/claude/index.js +8 -4
  33. package/dist/providers/claude/index.js.map +1 -1
  34. package/dist/providers/claude/session.d.ts +11 -9
  35. package/dist/providers/claude/session.d.ts.map +1 -1
  36. package/dist/providers/claude/session.js +36 -14
  37. package/dist/providers/claude/session.js.map +1 -1
  38. package/dist/providers/codex/attach.d.ts +9 -0
  39. package/dist/providers/codex/attach.d.ts.map +1 -0
  40. package/dist/providers/codex/attach.js +93 -0
  41. package/dist/providers/codex/attach.js.map +1 -0
  42. package/dist/providers/codex/execute.d.ts.map +1 -1
  43. package/dist/providers/codex/execute.js +17 -3
  44. package/dist/providers/codex/execute.js.map +1 -1
  45. package/dist/providers/codex/goal-capability.d.ts +13 -0
  46. package/dist/providers/codex/goal-capability.d.ts.map +1 -0
  47. package/dist/providers/codex/goal-capability.js +18 -0
  48. package/dist/providers/codex/goal-capability.js.map +1 -0
  49. package/dist/providers/codex/index.d.ts +1 -0
  50. package/dist/providers/codex/index.d.ts.map +1 -1
  51. package/dist/providers/codex/index.js +9 -6
  52. package/dist/providers/codex/index.js.map +1 -1
  53. package/dist/providers/codex/session.d.ts +11 -7
  54. package/dist/providers/codex/session.d.ts.map +1 -1
  55. package/dist/providers/codex/session.js +37 -12
  56. package/dist/providers/codex/session.js.map +1 -1
  57. package/dist/providers/codex/transcript-normalize.d.ts +28 -0
  58. package/dist/providers/codex/transcript-normalize.d.ts.map +1 -0
  59. package/dist/providers/codex/transcript-normalize.js +191 -0
  60. package/dist/providers/codex/transcript-normalize.js.map +1 -0
  61. package/dist/providers/cursor/index.d.ts.map +1 -1
  62. package/dist/providers/cursor/index.js +2 -2
  63. package/dist/providers/cursor/index.js.map +1 -1
  64. package/dist/providers/openclaw/index.d.ts.map +1 -1
  65. package/dist/providers/openclaw/index.js +2 -2
  66. package/dist/providers/openclaw/index.js.map +1 -1
  67. package/dist/providers/opencode/index.d.ts.map +1 -1
  68. package/dist/providers/opencode/index.js +3 -5
  69. package/dist/providers/opencode/index.js.map +1 -1
  70. package/dist/providers/pi/index.d.ts.map +1 -1
  71. package/dist/providers/pi/index.js +3 -5
  72. package/dist/providers/pi/index.js.map +1 -1
  73. package/dist/providers/process/index.d.ts.map +1 -1
  74. package/dist/providers/process/index.js +2 -2
  75. package/dist/providers/process/index.js.map +1 -1
  76. package/dist/registry.d.ts +0 -1
  77. package/dist/registry.d.ts.map +1 -1
  78. package/dist/registry.js +0 -4
  79. package/dist/registry.js.map +1 -1
  80. package/dist/sessions/index.d.ts +3 -0
  81. package/dist/sessions/index.d.ts.map +1 -0
  82. package/dist/sessions/index.js +2 -0
  83. package/dist/sessions/index.js.map +1 -0
  84. package/dist/sessions/record.d.ts +43 -0
  85. package/dist/sessions/record.d.ts.map +1 -0
  86. package/dist/sessions/record.js +85 -0
  87. package/dist/sessions/record.js.map +1 -0
  88. package/dist/types.d.ts +176 -0
  89. package/dist/types.d.ts.map +1 -1
  90. package/dist/types.js.map +1 -1
  91. package/dist/utils/endpoint.d.ts +38 -0
  92. package/dist/utils/endpoint.d.ts.map +1 -0
  93. package/dist/utils/endpoint.js +151 -0
  94. package/dist/utils/endpoint.js.map +1 -0
  95. package/dist/utils/env.d.ts.map +1 -1
  96. package/dist/utils/env.js +5 -1
  97. package/dist/utils/env.js.map +1 -1
  98. package/dist/utils/uuid.d.ts +7 -1
  99. package/dist/utils/uuid.d.ts.map +1 -1
  100. package/dist/utils/uuid.js +21 -1
  101. package/dist/utils/uuid.js.map +1 -1
  102. package/package.json +64 -7
  103. package/src/derived.ts +311 -0
  104. package/src/goals/controller.ts +442 -0
  105. package/src/goals/index.ts +21 -0
  106. package/src/goals/normalize.ts +173 -0
  107. package/src/goals/sentinel.ts +90 -0
  108. package/src/index.ts +270 -0
  109. package/src/providers/_shared/http-agent.ts +304 -0
  110. package/src/providers/acp/index.ts +103 -0
  111. package/src/providers/acp/parse.ts +131 -0
  112. package/src/providers/acp/session.ts +744 -0
  113. package/src/providers/claude/attach.ts +147 -0
  114. package/src/providers/claude/codec.ts +43 -0
  115. package/src/providers/claude/execute.ts +300 -0
  116. package/src/providers/claude/goal-capability.ts +21 -0
  117. package/src/providers/claude/index.ts +72 -0
  118. package/src/providers/claude/mcp.ts +82 -0
  119. package/src/providers/claude/parse.ts +824 -0
  120. package/src/providers/claude/session.ts +1192 -0
  121. package/src/providers/claude/transcript.ts +555 -0
  122. package/src/providers/codex/attach.ts +123 -0
  123. package/src/providers/codex/codec.ts +50 -0
  124. package/src/providers/codex/execute.ts +337 -0
  125. package/src/providers/codex/goal-capability.ts +19 -0
  126. package/src/providers/codex/index.ts +57 -0
  127. package/src/providers/codex/modes.ts +159 -0
  128. package/src/providers/codex/parse.ts +691 -0
  129. package/src/providers/codex/plan-mode.ts +49 -0
  130. package/src/providers/codex/session.ts +1287 -0
  131. package/src/providers/codex/transcript-normalize.ts +197 -0
  132. package/src/providers/codex/transcript.ts +487 -0
  133. package/src/providers/codex/usage-scanner.ts +178 -0
  134. package/src/providers/copilot/index.ts +19 -0
  135. package/src/providers/cursor/codec.ts +44 -0
  136. package/src/providers/cursor/execute.ts +271 -0
  137. package/src/providers/cursor/index.ts +25 -0
  138. package/src/providers/cursor/parse.ts +288 -0
  139. package/src/providers/gemini/index.ts +21 -0
  140. package/src/providers/openclaw/codec.ts +40 -0
  141. package/src/providers/openclaw/execute.ts +19 -0
  142. package/src/providers/openclaw/index.ts +29 -0
  143. package/src/providers/opencode/codec.ts +50 -0
  144. package/src/providers/opencode/event-parse.ts +141 -0
  145. package/src/providers/opencode/execute.ts +251 -0
  146. package/src/providers/opencode/http-session.ts +427 -0
  147. package/src/providers/opencode/index.ts +30 -0
  148. package/src/providers/opencode/parse.ts +203 -0
  149. package/src/providers/opencode/server.ts +0 -0
  150. package/src/providers/pi/codec.ts +44 -0
  151. package/src/providers/pi/execute.ts +297 -0
  152. package/src/providers/pi/index.ts +30 -0
  153. package/src/providers/pi/parse.ts +231 -0
  154. package/src/providers/pi/session.ts +381 -0
  155. package/src/providers/process/execute.ts +148 -0
  156. package/src/providers/process/index.ts +52 -0
  157. package/src/registry.ts +40 -0
  158. package/src/sessions/index.ts +8 -0
  159. package/src/sessions/record.ts +108 -0
  160. package/src/types.ts +1638 -0
  161. package/src/utils/ask-user-question.ts +57 -0
  162. package/src/utils/auth.ts +661 -0
  163. package/src/utils/binary.ts +179 -0
  164. package/src/utils/endpoint.ts +172 -0
  165. package/src/utils/env.ts +63 -0
  166. package/src/utils/execute-all.ts +68 -0
  167. package/src/utils/exit-plan-mode.ts +40 -0
  168. package/src/utils/instructions.ts +427 -0
  169. package/src/utils/process.ts +223 -0
  170. package/src/utils/runtime-config.ts +100 -0
  171. package/src/utils/runtime-homes.ts +49 -0
  172. package/src/utils/skill-commands.ts +493 -0
  173. package/src/utils/skills.ts +500 -0
  174. package/src/utils/template.ts +16 -0
  175. package/src/utils/tool-names.ts +51 -0
  176. package/src/utils/uuid.ts +21 -0
  177. 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
+ }