frely-cli 0.13.1 → 0.13.3
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/agent/app-install.d.ts +6 -3
- package/dist/agent/app-install.js +18 -6
- package/dist/agent/app-install.js.map +1 -1
- package/dist/agent/pi-node-supervisor.d.ts +59 -0
- package/dist/agent/pi-node-supervisor.js +250 -0
- package/dist/agent/pi-node-supervisor.js.map +1 -0
- package/dist/agent-help.d.ts +2 -86
- package/dist/agent-help.js +1 -8
- package/dist/agent-help.js.map +1 -1
- package/dist/app-manager.js +2 -2
- package/dist/app-manager.js.map +1 -1
- package/dist/auth.d.ts +1 -0
- package/dist/auth.js +52 -19
- package/dist/auth.js.map +1 -1
- package/dist/device/protocol.d.ts +1 -1
- package/dist/device/protocol.js +1 -1
- package/dist/device/protocol.js.map +1 -1
- package/dist/device/relay-client.d.ts +1 -8
- package/dist/device/relay-client.js +8 -20
- package/dist/device/relay-client.js.map +1 -1
- package/dist/diagnostics.js +3 -5
- package/dist/diagnostics.js.map +1 -1
- package/dist/index.js +20 -84
- package/dist/index.js.map +1 -1
- package/dist/runtime/diagnostics.js +1 -0
- package/dist/runtime/diagnostics.js.map +1 -1
- package/dist/runtime/mcp.d.ts +0 -137
- package/dist/runtime/mcp.js +0 -22
- package/dist/runtime/mcp.js.map +1 -1
- package/dist/skill/access.js +7 -2
- package/dist/skill/access.js.map +1 -1
- package/package.json +1 -1
- package/dist/agent/agent-service.d.ts +0 -77
- package/dist/agent/agent-service.js +0 -348
- package/dist/agent/agent-service.js.map +0 -1
- package/dist/agent/app-key.d.ts +0 -14
- package/dist/agent/app-key.js +0 -46
- package/dist/agent/app-key.js.map +0 -1
- package/dist/agent/compose.d.ts +0 -23
- package/dist/agent/compose.js +0 -42
- package/dist/agent/compose.js.map +0 -1
- package/dist/agent/ops-server.d.ts +0 -18
- package/dist/agent/ops-server.js +0 -175
- package/dist/agent/ops-server.js.map +0 -1
- package/dist/agent/ops-stdio.d.ts +0 -5
- package/dist/agent/ops-stdio.js +0 -47
- package/dist/agent/ops-stdio.js.map +0 -1
- package/dist/agent/ops.d.ts +0 -25
- package/dist/agent/ops.js +0 -82
- package/dist/agent/ops.js.map +0 -1
- package/dist/agent/protocol.d.ts +0 -72
- package/dist/agent/protocol.js +0 -195
- package/dist/agent/protocol.js.map +0 -1
- package/dist/agent/supervisor.d.ts +0 -80
- package/dist/agent/supervisor.js +0 -281
- package/dist/agent/supervisor.js.map +0 -1
- package/dist/agent/task-store.d.ts +0 -82
- package/dist/agent/task-store.js +0 -220
- package/dist/agent/task-store.js.map +0 -1
- package/dist/agent/tool-executor.d.ts +0 -28
- package/dist/agent/tool-executor.js +0 -113
- package/dist/agent/tool-executor.js.map +0 -1
- package/dist/agent/worktrees.d.ts +0 -35
- package/dist/agent/worktrees.js +0 -143
- package/dist/agent/worktrees.js.map +0 -1
- package/dist/runtime/relay-agent.d.ts +0 -25
- package/dist/runtime/relay-agent.js +0 -63
- package/dist/runtime/relay-agent.js.map +0 -1
package/dist/agent/task-store.js
DELETED
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent task store: one directory per task under the frely state directory
|
|
3
|
-
* (`<state>/agent/tasks/<taskId>/`), with `task.json` for the record and
|
|
4
|
-
* `events.jsonl` for the append-only event log.
|
|
5
|
-
*/
|
|
6
|
-
import { createHash, randomBytes } from "node:crypto";
|
|
7
|
-
import { homedir } from "node:os";
|
|
8
|
-
import { mkdir, readFile, readdir, rename, writeFile } from "node:fs/promises";
|
|
9
|
-
import { join } from "node:path";
|
|
10
|
-
import { isValidTaskId } from "./protocol.js";
|
|
11
|
-
export const AGENT_TASK_EVENTS_PAGE_SIZE = 100;
|
|
12
|
-
export const AGENT_TASK_MAX_GOAL_BYTES = 64 * 1024;
|
|
13
|
-
export const AGENT_DEFAULT_MAX_COST_USD = 2;
|
|
14
|
-
export const AGENT_MAX_COST_USD_LIMIT = 50;
|
|
15
|
-
export const AGENT_DEFAULT_MAX_CONCURRENT_TASKS = 2;
|
|
16
|
-
export const AGENT_START_RATE_LIMIT_PER_MINUTE = 5;
|
|
17
|
-
export class AgentStoreError extends Error {
|
|
18
|
-
code;
|
|
19
|
-
constructor(code) {
|
|
20
|
-
super(code);
|
|
21
|
-
this.code = code;
|
|
22
|
-
this.name = "AgentStoreError";
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
export function agentStateDir(env = process.env) {
|
|
26
|
-
return join(env.XDG_STATE_HOME || join(homedir(), ".local", "state"), "frely", "agent");
|
|
27
|
-
}
|
|
28
|
-
export function agentConfigPath(env = process.env) {
|
|
29
|
-
return join(env.XDG_CONFIG_HOME || join(homedir(), ".config"), "frely", "agent.json");
|
|
30
|
-
}
|
|
31
|
-
export function agentDataDir(env = process.env) {
|
|
32
|
-
return join(env.XDG_DATA_HOME || join(homedir(), ".local", "share"), "frely");
|
|
33
|
-
}
|
|
34
|
-
export function workspaceStorageKey(workspaceRoot) {
|
|
35
|
-
return createHash("sha256").update(workspaceRoot).digest("hex").slice(0, 16);
|
|
36
|
-
}
|
|
37
|
-
/** Serialize + validate the runtime/merge state machine transitions. */
|
|
38
|
-
export function nextRuntimeStatus(current, event) {
|
|
39
|
-
if (event.type !== "status")
|
|
40
|
-
return null;
|
|
41
|
-
switch (current) {
|
|
42
|
-
case "queued":
|
|
43
|
-
// Host events may race ahead of CLI bookkeeping right after task.start,
|
|
44
|
-
// so any authoritative host status is accepted from queued.
|
|
45
|
-
return event.status === "running" || event.status === "waiting_input" || event.status === "completed" || event.status === "failed" || event.status === "cancelled"
|
|
46
|
-
? event.status
|
|
47
|
-
: null;
|
|
48
|
-
case "running":
|
|
49
|
-
return event.status === "waiting_input" || event.status === "completed" || event.status === "failed" || event.status === "cancelled" || event.status === "running"
|
|
50
|
-
? event.status
|
|
51
|
-
: null;
|
|
52
|
-
case "waiting_input":
|
|
53
|
-
return event.status === "running" || event.status === "completed" || event.status === "failed" || event.status === "cancelled" ? event.status : null;
|
|
54
|
-
default:
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
export function isTerminalStatus(status) {
|
|
59
|
-
return status === "completed" || status === "failed" || status === "cancelled";
|
|
60
|
-
}
|
|
61
|
-
export class TaskStore {
|
|
62
|
-
rootDir;
|
|
63
|
-
constructor(rootDir) {
|
|
64
|
-
this.rootDir = rootDir;
|
|
65
|
-
}
|
|
66
|
-
static open(rootDir, env = process.env) {
|
|
67
|
-
return new TaskStore(rootDir ?? join(agentStateDir(env), "tasks"));
|
|
68
|
-
}
|
|
69
|
-
async create(record) {
|
|
70
|
-
if (!isValidTaskId(record.id))
|
|
71
|
-
throw new AgentStoreError("invalid_task");
|
|
72
|
-
const dir = this.taskDir(record.id);
|
|
73
|
-
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
74
|
-
if (await this.read(record.id).then(() => true, () => false))
|
|
75
|
-
throw new AgentStoreError("task_exists");
|
|
76
|
-
await this.persist(record);
|
|
77
|
-
}
|
|
78
|
-
async read(id) {
|
|
79
|
-
if (!isValidTaskId(id))
|
|
80
|
-
throw new AgentStoreError("invalid_task");
|
|
81
|
-
let raw;
|
|
82
|
-
try {
|
|
83
|
-
raw = await readFile(join(this.taskDir(id), "task.json"), "utf8");
|
|
84
|
-
}
|
|
85
|
-
catch {
|
|
86
|
-
throw new AgentStoreError("task_not_found");
|
|
87
|
-
}
|
|
88
|
-
let value;
|
|
89
|
-
try {
|
|
90
|
-
value = JSON.parse(raw);
|
|
91
|
-
}
|
|
92
|
-
catch {
|
|
93
|
-
throw new AgentStoreError("store_corrupt");
|
|
94
|
-
}
|
|
95
|
-
return validateTaskRecord(value);
|
|
96
|
-
}
|
|
97
|
-
async update(id, mutate) {
|
|
98
|
-
const current = await this.read(id);
|
|
99
|
-
const next = validateTaskRecord(mutate(structuredClone(current)));
|
|
100
|
-
if (next.id !== current.id)
|
|
101
|
-
throw new AgentStoreError("invalid_task");
|
|
102
|
-
await this.persist(next);
|
|
103
|
-
return next;
|
|
104
|
-
}
|
|
105
|
-
async list() {
|
|
106
|
-
let entries;
|
|
107
|
-
try {
|
|
108
|
-
entries = await readdir(this.rootDir);
|
|
109
|
-
}
|
|
110
|
-
catch {
|
|
111
|
-
return [];
|
|
112
|
-
}
|
|
113
|
-
const records = [];
|
|
114
|
-
for (const entry of entries.sort()) {
|
|
115
|
-
if (!isValidTaskId(entry))
|
|
116
|
-
continue;
|
|
117
|
-
const record = await this.read(entry).catch(() => null);
|
|
118
|
-
if (record)
|
|
119
|
-
records.push(record);
|
|
120
|
-
}
|
|
121
|
-
return records;
|
|
122
|
-
}
|
|
123
|
-
async appendEvent(id, event) {
|
|
124
|
-
const dir = this.taskDir(id);
|
|
125
|
-
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
126
|
-
const last = await this.lastEventSeq(id);
|
|
127
|
-
const stored = { ...event, seq: last + 1, at: new Date().toISOString() };
|
|
128
|
-
const { appendFile } = await import("node:fs/promises");
|
|
129
|
-
await appendFile(join(dir, "events.jsonl"), `${JSON.stringify(stored)}\n`, { encoding: "utf8", mode: 0o600 });
|
|
130
|
-
return stored;
|
|
131
|
-
}
|
|
132
|
-
async readEvents(id, cursor, limit = AGENT_TASK_EVENTS_PAGE_SIZE) {
|
|
133
|
-
let raw;
|
|
134
|
-
try {
|
|
135
|
-
raw = await readFile(join(this.taskDir(id), "events.jsonl"), "utf8");
|
|
136
|
-
}
|
|
137
|
-
catch {
|
|
138
|
-
if (await this.read(id).then(() => true, () => false))
|
|
139
|
-
return { events: [], nextCursor: null };
|
|
140
|
-
throw new AgentStoreError("task_not_found");
|
|
141
|
-
}
|
|
142
|
-
const events = [];
|
|
143
|
-
let nextCursor = null;
|
|
144
|
-
for (const line of raw.split("\n")) {
|
|
145
|
-
if (!line)
|
|
146
|
-
continue;
|
|
147
|
-
let parsed;
|
|
148
|
-
try {
|
|
149
|
-
parsed = JSON.parse(line);
|
|
150
|
-
}
|
|
151
|
-
catch {
|
|
152
|
-
continue;
|
|
153
|
-
}
|
|
154
|
-
if (parsed.seq > cursor) {
|
|
155
|
-
events.push(parsed);
|
|
156
|
-
if (events.length > limit) {
|
|
157
|
-
events.pop();
|
|
158
|
-
nextCursor = parsed.seq - 1;
|
|
159
|
-
break;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
return { events, nextCursor };
|
|
164
|
-
}
|
|
165
|
-
async lastEventSeq(id) {
|
|
166
|
-
let raw;
|
|
167
|
-
try {
|
|
168
|
-
raw = await readFile(join(this.taskDir(id), "events.jsonl"), "utf8");
|
|
169
|
-
}
|
|
170
|
-
catch {
|
|
171
|
-
return 0;
|
|
172
|
-
}
|
|
173
|
-
const lines = raw.trimEnd().split("\n");
|
|
174
|
-
const last = lines[lines.length - 1];
|
|
175
|
-
if (!last)
|
|
176
|
-
return 0;
|
|
177
|
-
try {
|
|
178
|
-
const parsed = JSON.parse(last);
|
|
179
|
-
return typeof parsed.seq === "number" ? parsed.seq : 0;
|
|
180
|
-
}
|
|
181
|
-
catch {
|
|
182
|
-
return 0;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
taskDir(id) {
|
|
186
|
-
return join(this.rootDir, id);
|
|
187
|
-
}
|
|
188
|
-
async persist(record) {
|
|
189
|
-
record.updatedAt = new Date().toISOString();
|
|
190
|
-
const dir = this.taskDir(record.id);
|
|
191
|
-
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
192
|
-
const tmp = join(dir, `task.json.${process.pid}.${randomBytes(4).toString("hex")}.tmp`);
|
|
193
|
-
await writeFile(tmp, `${JSON.stringify(record, null, 2)}\n`, { encoding: "utf8", mode: 0o600 });
|
|
194
|
-
await rename(tmp, join(dir, "task.json"));
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
export function validateTaskRecord(value) {
|
|
198
|
-
if (!value || typeof value !== "object")
|
|
199
|
-
throw new AgentStoreError("store_corrupt");
|
|
200
|
-
const r = value;
|
|
201
|
-
const id = r.id;
|
|
202
|
-
if (typeof id !== "string" || !isValidTaskId(id))
|
|
203
|
-
throw new AgentStoreError("store_corrupt");
|
|
204
|
-
const runtimeStatuses = ["queued", "running", "waiting_input", "completed", "failed", "cancelled"];
|
|
205
|
-
const mergeStatuses = ["none", "merge_requested", "approved", "merged", "merge_conflict", "discarded"];
|
|
206
|
-
if (!runtimeStatuses.includes(r.status))
|
|
207
|
-
throw new AgentStoreError("store_corrupt");
|
|
208
|
-
if (!mergeStatuses.includes(r.mergeStatus))
|
|
209
|
-
throw new AgentStoreError("store_corrupt");
|
|
210
|
-
for (const key of ["workspace", "worktreePath", "branch", "baseBranch", "baseCommit", "goal", "createdAt", "updatedAt"]) {
|
|
211
|
-
if (typeof r[key] !== "string")
|
|
212
|
-
throw new AgentStoreError("store_corrupt");
|
|
213
|
-
}
|
|
214
|
-
for (const key of ["maxCostUsd"]) {
|
|
215
|
-
if (typeof r[key] !== "number" || !Number.isFinite(r[key]) || r[key] <= 0)
|
|
216
|
-
throw new AgentStoreError("store_corrupt");
|
|
217
|
-
}
|
|
218
|
-
return value;
|
|
219
|
-
}
|
|
220
|
-
//# sourceMappingURL=task-store.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"task-store.js","sourceRoot":"","sources":["../../src/agent/task-store.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,aAAa,EAA2B,MAAM,eAAe,CAAC;AAiCvE,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAAG,CAAC;AAC/C,MAAM,CAAC,MAAM,y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
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent tool executor: executes `tool.*` requests from the agent host inside
|
|
3
|
-
* the task's worktree through the shared `Workspace` implementation (path
|
|
4
|
-
* containment + srt sandbox for commands) under a fair read/write scheduler.
|
|
5
|
-
*/
|
|
6
|
-
import { FairRwScheduler } from "../runtime/scheduler.js";
|
|
7
|
-
export type AgentToolResult = {
|
|
8
|
-
ok: true;
|
|
9
|
-
result: unknown;
|
|
10
|
-
} | {
|
|
11
|
-
ok: false;
|
|
12
|
-
error: {
|
|
13
|
-
code: "tool_failed" | "not_found" | "invalid_args";
|
|
14
|
-
message: string;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
export type AgentToolKind = "read" | "write" | "bash" | "grep" | "find" | "ls" | "edit";
|
|
18
|
-
/** Single active executor per task; created when the task starts running. */
|
|
19
|
-
export declare class AgentToolExecutor {
|
|
20
|
-
private readonly scheduler;
|
|
21
|
-
private readonly workspace;
|
|
22
|
-
private disposed;
|
|
23
|
-
constructor(worktreeRoot: string, scheduler: FairRwScheduler);
|
|
24
|
-
execute(kind: AgentToolKind, args: Record<string, unknown>): Promise<AgentToolResult>;
|
|
25
|
-
private dispatch;
|
|
26
|
-
dispose(): void;
|
|
27
|
-
}
|
|
28
|
-
export declare function toolKindFromMethod(method: string): AgentToolKind | null;
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { Workspace } from "../runtime/workspace.js";
|
|
2
|
-
/** Single active executor per task; created when the task starts running. */
|
|
3
|
-
export class AgentToolExecutor {
|
|
4
|
-
scheduler;
|
|
5
|
-
workspace;
|
|
6
|
-
disposed = false;
|
|
7
|
-
constructor(worktreeRoot, scheduler) {
|
|
8
|
-
this.scheduler = scheduler;
|
|
9
|
-
this.workspace = Workspace.open(worktreeRoot);
|
|
10
|
-
}
|
|
11
|
-
async execute(kind, args) {
|
|
12
|
-
if (this.disposed)
|
|
13
|
-
return failure("tool_failed", "Task session is disposed.");
|
|
14
|
-
try {
|
|
15
|
-
const result = await this.dispatch(kind, args);
|
|
16
|
-
return { ok: true, result };
|
|
17
|
-
}
|
|
18
|
-
catch (error) {
|
|
19
|
-
return failure("tool_failed", error instanceof Error ? error.message : "tool failed");
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
async dispatch(kind, args) {
|
|
23
|
-
const workspace = await this.workspace;
|
|
24
|
-
switch (kind) {
|
|
25
|
-
case "read": {
|
|
26
|
-
const path = stringArg(args, "path");
|
|
27
|
-
return this.scheduler.read(() => workspace.readFile(path));
|
|
28
|
-
}
|
|
29
|
-
case "write": {
|
|
30
|
-
const path = stringArg(args, "path");
|
|
31
|
-
const content = stringArg(args, "content");
|
|
32
|
-
const overwrite = args.overwrite === true;
|
|
33
|
-
return this.scheduler.write(() => workspace.writeFile(path, content, overwrite));
|
|
34
|
-
}
|
|
35
|
-
case "edit": {
|
|
36
|
-
const path = stringArg(args, "path");
|
|
37
|
-
const edits = args.edits;
|
|
38
|
-
if (!Array.isArray(edits))
|
|
39
|
-
throw new Error("edits must be an array.");
|
|
40
|
-
const expectedSha256 = typeof args.expectedSha256 === "string" ? args.expectedSha256 : undefined;
|
|
41
|
-
return this.scheduler.write(() => workspace.applyPatch(path, edits, expectedSha256));
|
|
42
|
-
}
|
|
43
|
-
case "bash": {
|
|
44
|
-
const command = stringArg(args, "command");
|
|
45
|
-
const cwd = typeof args.cwd === "string" ? args.cwd : ".";
|
|
46
|
-
const timeoutMs = numberArg(args, "timeoutMs", 30_000);
|
|
47
|
-
return this.scheduler.write(() => workspace.runCommand(command, cwd, timeoutMs));
|
|
48
|
-
}
|
|
49
|
-
case "grep": {
|
|
50
|
-
const query = stringArg(args, "query");
|
|
51
|
-
const path = typeof args.path === "string" ? args.path : ".";
|
|
52
|
-
return this.scheduler.read(() => workspace.searchFiles(path, query, {
|
|
53
|
-
regex: args.regex === true,
|
|
54
|
-
caseSensitive: args.caseSensitive === true,
|
|
55
|
-
maxResults: numberArg(args, "maxResults", 100),
|
|
56
|
-
contextLines: numberArg(args, "contextLines", 0),
|
|
57
|
-
}));
|
|
58
|
-
}
|
|
59
|
-
case "find": {
|
|
60
|
-
const pattern = stringArg(args, "pattern");
|
|
61
|
-
const path = typeof args.path === "string" ? args.path : ".";
|
|
62
|
-
return this.scheduler.read(() => workspace.findFiles(path, pattern, numberArg(args, "maxResults", 100)));
|
|
63
|
-
}
|
|
64
|
-
case "ls": {
|
|
65
|
-
const path = typeof args.path === "string" ? args.path : ".";
|
|
66
|
-
return this.scheduler.read(() => workspace.listDirectory(path));
|
|
67
|
-
}
|
|
68
|
-
default:
|
|
69
|
-
throw new Error(`Unknown tool kind: ${kind}`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
dispose() {
|
|
73
|
-
this.disposed = true;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
export function toolKindFromMethod(method) {
|
|
77
|
-
switch (method) {
|
|
78
|
-
case "tool.read":
|
|
79
|
-
return "read";
|
|
80
|
-
case "tool.write":
|
|
81
|
-
return "write";
|
|
82
|
-
case "tool.edit":
|
|
83
|
-
return "edit";
|
|
84
|
-
case "tool.bash":
|
|
85
|
-
return "bash";
|
|
86
|
-
case "tool.grep":
|
|
87
|
-
return "grep";
|
|
88
|
-
case "tool.find":
|
|
89
|
-
return "find";
|
|
90
|
-
case "tool.ls":
|
|
91
|
-
return "ls";
|
|
92
|
-
default:
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
function stringArg(args, key) {
|
|
97
|
-
const value = args[key];
|
|
98
|
-
if (typeof value !== "string" || value.length === 0)
|
|
99
|
-
throw new Error(`${key} must be a non-empty string.`);
|
|
100
|
-
return value;
|
|
101
|
-
}
|
|
102
|
-
function numberArg(args, key, fallback) {
|
|
103
|
-
const value = args[key];
|
|
104
|
-
if (value === undefined)
|
|
105
|
-
return fallback;
|
|
106
|
-
if (typeof value !== "number" || !Number.isSafeInteger(value))
|
|
107
|
-
throw new Error(`${key} must be an integer.`);
|
|
108
|
-
return value;
|
|
109
|
-
}
|
|
110
|
-
function failure(code, message) {
|
|
111
|
-
return { ok: false, error: { code, message: message.slice(0, 512) } };
|
|
112
|
-
}
|
|
113
|
-
//# sourceMappingURL=tool-executor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tool-executor.js","sourceRoot":"","sources":["../../src/agent/tool-executor.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAQpD,6EAA6E;AAC7E,MAAM,OAAO,iBAAiB;IAMT;IALF,SAAS,CAAqB;IACvC,QAAQ,GAAG,KAAK,CAAC;IAEzB,YACE,YAAoB,EACH,SAA0B;QAA1B,cAAS,GAAT,SAAS,CAAiB;QAE3C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAChD,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAmB,EAAE,IAA6B;QAC9D,IAAI,IAAI,CAAC,QAAQ;YAAE,OAAO,OAAO,CAAC,aAAa,EAAE,2BAA2B,CAAC,CAAC;QAC9E,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAC/C,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC9B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,OAAO,CAAC,aAAa,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC;QACxF,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,QAAQ,CAAC,IAAmB,EAAE,IAA6B;QACvE,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC;QACvC,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,MAAM,CAAC,CAA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,CAAC,GAAG,GAAG,8BAA8B,CAAC,CAAC;IAC3G,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,SAAS,CAAC,IAA6B,EAAE,GAAW,EAAE,QAAgB;IAC7E,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;IACxB,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAC;IACzC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,GAAG,sBAAsB,CAAC,CAAC;IAC7G,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,OAAO,CAAC,IAAkD,EAAE,OAAe;IAClF,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC;AACxE,CAAC"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export declare class WorktreeError extends Error {
|
|
2
|
-
readonly code: "not_a_git_repo" | "dirty_workspace" | "git_failed" | "merge_conflict" | "not_found" | "invalid_state";
|
|
3
|
-
constructor(code: "not_a_git_repo" | "dirty_workspace" | "git_failed" | "merge_conflict" | "not_found" | "invalid_state");
|
|
4
|
-
}
|
|
5
|
-
export type WorktreeInfo = {
|
|
6
|
-
path: string;
|
|
7
|
-
branch: string;
|
|
8
|
-
baseBranch: string;
|
|
9
|
-
baseCommit: string;
|
|
10
|
-
};
|
|
11
|
-
export declare function branchNameForTask(taskId: string): string;
|
|
12
|
-
export declare function worktreePathForTask(taskId: string, workspaceRoot: string, env?: NodeJS.ProcessEnv): string;
|
|
13
|
-
/** Verify a workspace is a clean git repository and return its base facts. */
|
|
14
|
-
export declare function inspectWorkspace(workspaceRoot: string): Promise<{
|
|
15
|
-
baseBranch: string;
|
|
16
|
-
baseCommit: string;
|
|
17
|
-
root: string;
|
|
18
|
-
}>;
|
|
19
|
-
export declare function createTaskWorktree(taskId: string, workspaceRoot: string, baseRef?: string): Promise<WorktreeInfo>;
|
|
20
|
-
export declare function removeTaskWorktree(taskId: string, workspaceRoot: string): Promise<void>;
|
|
21
|
-
export type MergeOutcome = {
|
|
22
|
-
status: "merged";
|
|
23
|
-
} | {
|
|
24
|
-
status: "merge_conflict";
|
|
25
|
-
detail: string;
|
|
26
|
-
};
|
|
27
|
-
/** Rebase the task branch (inside its worktree) onto the current baseline, then merge --no-ff. */
|
|
28
|
-
export declare function mergeTaskBranch(taskId: string, workspaceRoot: string): Promise<MergeOutcome>;
|
|
29
|
-
/** List of changed files (vs base) with bounded diff output. */
|
|
30
|
-
export declare function taskChangedFiles(taskId: string, workspaceRoot: string): Promise<string[]>;
|
|
31
|
-
/** Bounded unified diff of the task worktree vs its merge-base (committed + uncommitted changes). */
|
|
32
|
-
export declare function taskDiff(taskId: string, workspaceRoot: string, path?: string, maxBytes?: number): Promise<{
|
|
33
|
-
diff: string;
|
|
34
|
-
truncated: boolean;
|
|
35
|
-
}>;
|
package/dist/agent/worktrees.js
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Git worktree lifecycle for agent tasks (plan §4.4): task changes land in an
|
|
3
|
-
* isolated worktree outside the user workspace, merge back with --no-ff after
|
|
4
|
-
* approval, and rebase first when the baseline branch advanced.
|
|
5
|
-
*/
|
|
6
|
-
import { execFile } from "node:child_process";
|
|
7
|
-
import { mkdir, rm } from "node:fs/promises";
|
|
8
|
-
import { dirname, join } from "node:path";
|
|
9
|
-
import { promisify } from "node:util";
|
|
10
|
-
import { agentDataDir, workspaceStorageKey } from "./task-store.js";
|
|
11
|
-
const exec = promisify(execFile);
|
|
12
|
-
export class WorktreeError extends Error {
|
|
13
|
-
code;
|
|
14
|
-
constructor(code) {
|
|
15
|
-
super(code);
|
|
16
|
-
this.code = code;
|
|
17
|
-
this.name = "WorktreeError";
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
export function branchNameForTask(taskId) {
|
|
21
|
-
return `frely/task/${taskId}`;
|
|
22
|
-
}
|
|
23
|
-
export function worktreePathForTask(taskId, workspaceRoot, env = process.env) {
|
|
24
|
-
return join(agentDataDir(env), "worktrees", workspaceStorageKey(workspaceRoot), taskId);
|
|
25
|
-
}
|
|
26
|
-
/** Verify a workspace is a clean git repository and return its base facts. */
|
|
27
|
-
export async function inspectWorkspace(workspaceRoot) {
|
|
28
|
-
let root;
|
|
29
|
-
try {
|
|
30
|
-
const out = await git(workspaceRoot, ["rev-parse", "--show-toplevel"]);
|
|
31
|
-
root = out.trim();
|
|
32
|
-
}
|
|
33
|
-
catch {
|
|
34
|
-
throw new WorktreeError("not_a_git_repo");
|
|
35
|
-
}
|
|
36
|
-
let status;
|
|
37
|
-
try {
|
|
38
|
-
status = (await git(root, ["status", "--porcelain"])).trim();
|
|
39
|
-
}
|
|
40
|
-
catch {
|
|
41
|
-
throw new WorktreeError("git_failed");
|
|
42
|
-
}
|
|
43
|
-
if (status.length > 0)
|
|
44
|
-
throw new WorktreeError("dirty_workspace");
|
|
45
|
-
const baseCommit = (await git(root, ["rev-parse", "HEAD"])).trim();
|
|
46
|
-
if (!/^[0-9a-f]{7,40}$/u.test(baseCommit))
|
|
47
|
-
throw new WorktreeError("git_failed");
|
|
48
|
-
let baseBranch;
|
|
49
|
-
try {
|
|
50
|
-
baseBranch = (await git(root, ["symbolic-ref", "--short", "HEAD"])).trim();
|
|
51
|
-
}
|
|
52
|
-
catch {
|
|
53
|
-
baseBranch = baseCommit; // detached HEAD: baseline is the commit itself
|
|
54
|
-
}
|
|
55
|
-
return { baseBranch: baseBranch || baseCommit, baseCommit, root };
|
|
56
|
-
}
|
|
57
|
-
export async function createTaskWorktree(taskId, workspaceRoot, baseRef) {
|
|
58
|
-
const facts = await inspectWorkspace(workspaceRoot);
|
|
59
|
-
const path = worktreePathForTask(taskId, facts.root);
|
|
60
|
-
await mkdir(dirname(path), { recursive: true, mode: 0o700 });
|
|
61
|
-
const branch = branchNameForTask(taskId);
|
|
62
|
-
try {
|
|
63
|
-
await git(facts.root, ["worktree", "add", "-b", branch, path, baseRef ?? facts.baseCommit]);
|
|
64
|
-
}
|
|
65
|
-
catch {
|
|
66
|
-
await rm(path, { recursive: true, force: true }).catch(() => undefined);
|
|
67
|
-
throw new WorktreeError("git_failed");
|
|
68
|
-
}
|
|
69
|
-
return { path, branch, baseBranch: facts.baseBranch, baseCommit: facts.baseCommit };
|
|
70
|
-
}
|
|
71
|
-
export async function removeTaskWorktree(taskId, workspaceRoot) {
|
|
72
|
-
const facts = await inspectWorkspace(workspaceRoot).catch(() => null);
|
|
73
|
-
const root = facts?.root ?? workspaceRoot;
|
|
74
|
-
const path = worktreePathForTask(taskId, root);
|
|
75
|
-
const branch = branchNameForTask(taskId);
|
|
76
|
-
await git(root, ["worktree", "remove", "--force", path]).catch(() => undefined);
|
|
77
|
-
await rm(path, { recursive: true, force: true }).catch(() => undefined);
|
|
78
|
-
await git(root, ["branch", "-D", branch]).catch(() => undefined);
|
|
79
|
-
}
|
|
80
|
-
/** Rebase the task branch (inside its worktree) onto the current baseline, then merge --no-ff. */
|
|
81
|
-
export async function mergeTaskBranch(taskId, workspaceRoot) {
|
|
82
|
-
const facts = await inspectWorkspace(workspaceRoot);
|
|
83
|
-
const branch = branchNameForTask(taskId);
|
|
84
|
-
const worktree = worktreePathForTask(taskId, facts.root);
|
|
85
|
-
const baseTip = (await git(facts.root, ["rev-parse", facts.baseBranch])).trim();
|
|
86
|
-
// Uncommitted agent edits are committed first: merges only carry commits.
|
|
87
|
-
const dirty = (await git(worktree, ["status", "--porcelain"])).trim();
|
|
88
|
-
if (dirty.length > 0) {
|
|
89
|
-
await git(worktree, ["add", "-A"]);
|
|
90
|
-
await git(worktree, ["-c", "user.email=agent@frely.invalid", "-c", "user.name=frely agent", "commit", "-m", `Agent changes for ${taskId}`]);
|
|
91
|
-
}
|
|
92
|
-
// Rebase the task branch onto the current baseline tip inside its own worktree.
|
|
93
|
-
let rebaseFailed = false;
|
|
94
|
-
await git(worktree, ["rebase", baseTip]).catch(() => {
|
|
95
|
-
rebaseFailed = true;
|
|
96
|
-
});
|
|
97
|
-
if (rebaseFailed) {
|
|
98
|
-
await git(worktree, ["rebase", "--abort"]).catch(() => undefined);
|
|
99
|
-
return { status: "merge_conflict", detail: "Task branch cannot be rebased onto the current baseline." };
|
|
100
|
-
}
|
|
101
|
-
if (facts.baseBranch === facts.baseCommit) {
|
|
102
|
-
// Detached baseline: nothing to merge into; treat as conflict to force an explicit decision.
|
|
103
|
-
return { status: "merge_conflict", detail: "Workspace baseline is a detached commit." };
|
|
104
|
-
}
|
|
105
|
-
try {
|
|
106
|
-
await git(facts.root, ["merge", "--no-ff", branch, "-m", `Merge ${branch}`]);
|
|
107
|
-
return { status: "merged" };
|
|
108
|
-
}
|
|
109
|
-
catch (error) {
|
|
110
|
-
await git(facts.root, ["merge", "--abort"]).catch(() => undefined);
|
|
111
|
-
return { status: "merge_conflict", detail: error instanceof Error ? error.message.slice(0, 512) : "merge failed" };
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
/** List of changed files (vs base) with bounded diff output. */
|
|
115
|
-
export async function taskChangedFiles(taskId, workspaceRoot) {
|
|
116
|
-
const facts = await inspectWorkspace(workspaceRoot);
|
|
117
|
-
const branch = branchNameForTask(taskId);
|
|
118
|
-
const base = (await git(facts.root, ["merge-base", branch, facts.baseBranch]).catch(() => null))?.trim() ?? facts.baseCommit;
|
|
119
|
-
const out = await git(facts.root, ["diff", "--name-only", `${base}..${branch}`]);
|
|
120
|
-
return out.split("\n").map((line) => line.trim()).filter((line) => line.length > 0);
|
|
121
|
-
}
|
|
122
|
-
/** Bounded unified diff of the task worktree vs its merge-base (committed + uncommitted changes). */
|
|
123
|
-
export async function taskDiff(taskId, workspaceRoot, path, maxBytes = 256 * 1024) {
|
|
124
|
-
const facts = await inspectWorkspace(workspaceRoot);
|
|
125
|
-
const branch = branchNameForTask(taskId);
|
|
126
|
-
const worktree = worktreePathForTask(taskId, facts.root);
|
|
127
|
-
const base = (await git(facts.root, ["merge-base", branch, facts.baseBranch]).catch(() => null))?.trim() ?? facts.baseCommit;
|
|
128
|
-
// Include brand-new (untracked) files in the diff via intent-to-add markers.
|
|
129
|
-
await git(worktree, ["add", "--intent-to-add", "-A"]).catch(() => undefined);
|
|
130
|
-
const args = ["diff", base];
|
|
131
|
-
if (path)
|
|
132
|
-
args.push("--", path);
|
|
133
|
-
const out = await git(worktree, args, { maxBuffer: 16 * 1024 * 1024 });
|
|
134
|
-
const buffer = Buffer.from(out, "utf8");
|
|
135
|
-
if (buffer.byteLength <= maxBytes)
|
|
136
|
-
return { diff: out, truncated: false };
|
|
137
|
-
return { diff: buffer.subarray(0, maxBytes).toString("utf8"), truncated: true };
|
|
138
|
-
}
|
|
139
|
-
async function git(cwd, args, options) {
|
|
140
|
-
const { stdout } = await exec("git", args, { cwd, maxBuffer: options?.maxBuffer ?? 4 * 1024 * 1024 });
|
|
141
|
-
return stdout;
|
|
142
|
-
}
|
|
143
|
-
//# sourceMappingURL=worktrees.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worktrees.js","sourceRoot":"","sources":["../../src/agent/worktrees.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEpE,MAAM,IAAI,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAEjC,MAAM,OAAO,aAAc,SAAQ,KAA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,CAAC,CAAC;IACvE,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACxC,IAAI,MAAM,CAAC,UAAU,IAAI,QAAQ;QAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;IAC1E,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AAClF,CAAC;AAED,KAAK,UAAU,GAAG,CAAC,GAAW,EAAE,IAAc,EAAE,OAAgC;IAC9E,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI,EAAE,CAAC,CAAC;IACtG,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Device Relay `method: "agent"` bridge: translates `{op, args}` payloads
|
|
3
|
-
* (plan §5) into AgentService calls for remote-control clients (web UI).
|
|
4
|
-
* Remote sources are gated by `frely app remote enable` inside the service.
|
|
5
|
-
*
|
|
6
|
-
* Op dispatch lives in `../agent/ops.ts` (shared with the MCP toolset bridge
|
|
7
|
-
* and the local GUI ops socket). This module keeps the relay-facing error
|
|
8
|
-
* type and strips local-only task fields (source, worktreePath, approval)
|
|
9
|
-
* before anything leaves the device.
|
|
10
|
-
*/
|
|
11
|
-
import type { DeviceRelayRequest } from "../device/protocol.js";
|
|
12
|
-
import type { AgentService } from "../agent/agent-service.js";
|
|
13
|
-
export { AGENT_OPS, isAgentOp } from "../agent/ops.js";
|
|
14
|
-
export type { AgentOp } from "../agent/ops.js";
|
|
15
|
-
export declare class RelayAgentError extends Error {
|
|
16
|
-
readonly code: string;
|
|
17
|
-
constructor(code: string, message?: string);
|
|
18
|
-
}
|
|
19
|
-
/** MCP toolset bridge: expose agent ops as agent_* tools (plan §5) when the frely-app toolset is enabled. */
|
|
20
|
-
export declare function createAgentCallBridge(agent: AgentService, defaults: {
|
|
21
|
-
workspace: string;
|
|
22
|
-
}): (op: string, args: Record<string, unknown>) => Promise<unknown>;
|
|
23
|
-
export declare function executeAgentRequest(request: DeviceRelayRequest, agent: AgentService, defaults: {
|
|
24
|
-
workspace: string;
|
|
25
|
-
}): Promise<unknown>;
|