frely-cli 0.13.0 → 0.13.2
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/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 +22 -84
- package/dist/index.js.map +1 -1
- package/dist/runtime/mcp.d.ts +0 -137
- package/dist/runtime/mcp.js +1 -23
- package/dist/runtime/mcp.js.map +1 -1
- package/dist/runtime/sandbox.js +9 -1
- package/dist/runtime/sandbox.js.map +1 -1
- package/dist/runtime/workspace-registry.d.ts +2 -0
- package/dist/runtime/workspace-registry.js +10 -0
- package/dist/runtime/workspace-registry.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/package.json
CHANGED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { type DiagnosticLog } from "../runtime/diagnostics.js";
|
|
2
|
-
import { AgentHostSupervisor, type HostRequest } from "./supervisor.js";
|
|
3
|
-
import { AgentStoreError, type AgentTaskRecord, type AgentTaskSource, TaskStore, type StoredAgentEvent } from "./task-store.js";
|
|
4
|
-
import { type AgentHostTaskEvent } from "./protocol.js";
|
|
5
|
-
import { branchNameForTask } from "./worktrees.js";
|
|
6
|
-
export declare class AgentServiceError extends Error {
|
|
7
|
-
readonly code: AgentServiceErrorCode;
|
|
8
|
-
constructor(code: AgentServiceErrorCode, message?: string);
|
|
9
|
-
}
|
|
10
|
-
export type AgentServiceErrorCode = "invalid_args" | "task_not_found" | "workspace_not_git_repo" | "workspace_dirty" | "too_many_tasks" | "rate_limited" | "invalid_state" | "budget_exceeded" | "remote_control_disabled" | "app_not_installed" | "host_unavailable" | "internal";
|
|
11
|
-
export type AgentRuntimeConfig = {
|
|
12
|
-
schemaVersion: 1;
|
|
13
|
-
remoteControlEnabled: boolean;
|
|
14
|
-
defaultMaxCostUsd: number;
|
|
15
|
-
maxCostUsdLimit: number;
|
|
16
|
-
maxConcurrentTasks: number;
|
|
17
|
-
};
|
|
18
|
-
export declare const DEFAULT_AGENT_CONFIG: AgentRuntimeConfig;
|
|
19
|
-
export declare function loadAgentConfig(env?: NodeJS.ProcessEnv): Promise<AgentRuntimeConfig>;
|
|
20
|
-
export declare function saveAgentConfig(config: AgentRuntimeConfig, env?: NodeJS.ProcessEnv): Promise<void>;
|
|
21
|
-
export type StartTaskInput = {
|
|
22
|
-
workspace: string;
|
|
23
|
-
goal: string;
|
|
24
|
-
model?: string;
|
|
25
|
-
maxCostUsd?: number;
|
|
26
|
-
source: AgentTaskSource;
|
|
27
|
-
};
|
|
28
|
-
export declare class AgentService {
|
|
29
|
-
private readonly deps;
|
|
30
|
-
private readonly executors;
|
|
31
|
-
private readonly scheduler;
|
|
32
|
-
private credentialsSent;
|
|
33
|
-
private budgetCancels;
|
|
34
|
-
private _supervisor;
|
|
35
|
-
constructor(deps: {
|
|
36
|
-
store: TaskStore;
|
|
37
|
-
resolveSupervisor: () => AgentHostSupervisor;
|
|
38
|
-
modelCredentials?: () => {
|
|
39
|
-
apiKey: string;
|
|
40
|
-
baseUrl: string;
|
|
41
|
-
model: string;
|
|
42
|
-
} | null;
|
|
43
|
-
config?: () => Promise<AgentRuntimeConfig>;
|
|
44
|
-
log?: DiagnosticLog;
|
|
45
|
-
});
|
|
46
|
-
supervisor(): AgentHostSupervisor;
|
|
47
|
-
startTask(input: StartTaskInput): Promise<AgentTaskRecord>;
|
|
48
|
-
listTasks(workspace?: string): Promise<AgentTaskRecord[]>;
|
|
49
|
-
getTask(id: string): Promise<AgentTaskRecord>;
|
|
50
|
-
getEvents(id: string, cursor?: number): Promise<{
|
|
51
|
-
events: StoredAgentEvent[];
|
|
52
|
-
nextCursor: number | null;
|
|
53
|
-
}>;
|
|
54
|
-
sendMessage(id: string, message: string): Promise<void>;
|
|
55
|
-
cancelTask(id: string): Promise<AgentTaskRecord>;
|
|
56
|
-
private settleCancelled;
|
|
57
|
-
getDiff(id: string, path?: string): Promise<{
|
|
58
|
-
diff: string;
|
|
59
|
-
truncated: boolean;
|
|
60
|
-
}>;
|
|
61
|
-
requestMerge(id: string, note?: string): Promise<AgentTaskRecord>;
|
|
62
|
-
approveMerge(id: string, approvedBy: "gui" | "web"): Promise<AgentTaskRecord>;
|
|
63
|
-
discardTask(id: string): Promise<AgentTaskRecord>;
|
|
64
|
-
stopHost(): Promise<void>;
|
|
65
|
-
status(): {
|
|
66
|
-
host: ReturnType<AgentHostSupervisor["status"]>;
|
|
67
|
-
};
|
|
68
|
-
private ensureHostWithCredentials;
|
|
69
|
-
private debug;
|
|
70
|
-
private eventsQueue;
|
|
71
|
-
readonly onTaskEvent: (taskId: string, event: AgentHostTaskEvent) => void;
|
|
72
|
-
private handleTaskEvent;
|
|
73
|
-
readonly onHostLost: (error?: Error) => void;
|
|
74
|
-
private failRunningTasks;
|
|
75
|
-
readonly onToolRequest: (request: HostRequest, args: Record<string, unknown>, taskId: string) => Promise<unknown>;
|
|
76
|
-
}
|
|
77
|
-
export { TaskStore, AgentStoreError, branchNameForTask };
|
|
@@ -1,348 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AgentService: orchestrates agent tasks end-to-end — validation, worktrees,
|
|
3
|
-
* the agent host process, events, budget, and the merge workflow. This is the
|
|
4
|
-
* single implementation behind the GUI, the device relay (`method: "agent"`),
|
|
5
|
-
* and the `frely app` CLI.
|
|
6
|
-
*/
|
|
7
|
-
import { randomBytes } from "node:crypto";
|
|
8
|
-
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
9
|
-
import { dirname } from "node:path";
|
|
10
|
-
import { FairRwScheduler } from "../runtime/scheduler.js";
|
|
11
|
-
import { AgentToolExecutor, toolKindFromMethod } from "./tool-executor.js";
|
|
12
|
-
import { AGENT_DEFAULT_MAX_COST_USD, AGENT_MAX_COST_USD_LIMIT, AGENT_DEFAULT_MAX_CONCURRENT_TASKS, AGENT_START_RATE_LIMIT_PER_MINUTE, AGENT_TASK_MAX_GOAL_BYTES, AgentStoreError, agentConfigPath, isTerminalStatus, nextRuntimeStatus, TaskStore, } from "./task-store.js";
|
|
13
|
-
import { newTaskId } from "./protocol.js";
|
|
14
|
-
import { branchNameForTask, createTaskWorktree, mergeTaskBranch, removeTaskWorktree, taskDiff, WorktreeError } from "./worktrees.js";
|
|
15
|
-
export class AgentServiceError extends Error {
|
|
16
|
-
code;
|
|
17
|
-
constructor(code, message) {
|
|
18
|
-
super(message ?? code);
|
|
19
|
-
this.code = code;
|
|
20
|
-
this.name = "AgentServiceError";
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
export const DEFAULT_AGENT_CONFIG = {
|
|
24
|
-
schemaVersion: 1,
|
|
25
|
-
remoteControlEnabled: false,
|
|
26
|
-
defaultMaxCostUsd: AGENT_DEFAULT_MAX_COST_USD,
|
|
27
|
-
maxCostUsdLimit: AGENT_MAX_COST_USD_LIMIT,
|
|
28
|
-
maxConcurrentTasks: AGENT_DEFAULT_MAX_CONCURRENT_TASKS,
|
|
29
|
-
};
|
|
30
|
-
export async function loadAgentConfig(env = process.env) {
|
|
31
|
-
try {
|
|
32
|
-
const raw = JSON.parse(await readFile(agentConfigPath(env), "utf8"));
|
|
33
|
-
return {
|
|
34
|
-
schemaVersion: 1,
|
|
35
|
-
remoteControlEnabled: raw.remoteControlEnabled === true,
|
|
36
|
-
defaultMaxCostUsd: boundedCost(raw.defaultMaxCostUsd, AGENT_DEFAULT_MAX_COST_USD),
|
|
37
|
-
maxCostUsdLimit: boundedCost(raw.maxCostUsdLimit, AGENT_MAX_COST_USD_LIMIT),
|
|
38
|
-
maxConcurrentTasks: boundedConcurrency(raw.maxConcurrentTasks),
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
catch {
|
|
42
|
-
return { ...DEFAULT_AGENT_CONFIG };
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
export async function saveAgentConfig(config, env = process.env) {
|
|
46
|
-
const path = agentConfigPath(env);
|
|
47
|
-
await mkdir(dirname(path), { recursive: true, mode: 0o700 });
|
|
48
|
-
const tmp = `${path}.${randomBytes(8).toString("hex")}.tmp`;
|
|
49
|
-
await writeFile(tmp, `${JSON.stringify(config, null, 2)}\n`, { encoding: "utf8", mode: 0o600 });
|
|
50
|
-
await rename(tmp, path);
|
|
51
|
-
}
|
|
52
|
-
function boundedCost(value, fallback) {
|
|
53
|
-
return typeof value === "number" && Number.isFinite(value) && value > 0 && value <= AGENT_MAX_COST_USD_LIMIT ? value : fallback;
|
|
54
|
-
}
|
|
55
|
-
function boundedConcurrency(value) {
|
|
56
|
-
return typeof value === "number" && Number.isSafeInteger(value) && value >= 1 && value <= 4 ? value : AGENT_DEFAULT_MAX_CONCURRENT_TASKS;
|
|
57
|
-
}
|
|
58
|
-
export class AgentService {
|
|
59
|
-
deps;
|
|
60
|
-
executors = new Map();
|
|
61
|
-
scheduler = new FairRwScheduler(4);
|
|
62
|
-
credentialsSent = false;
|
|
63
|
-
budgetCancels = new Set();
|
|
64
|
-
_supervisor = null;
|
|
65
|
-
constructor(deps) {
|
|
66
|
-
this.deps = deps;
|
|
67
|
-
}
|
|
68
|
-
supervisor() {
|
|
69
|
-
this._supervisor ??= this.deps.resolveSupervisor();
|
|
70
|
-
return this._supervisor;
|
|
71
|
-
}
|
|
72
|
-
async startTask(input) {
|
|
73
|
-
const goal = typeof input.goal === "string" ? input.goal.trim() : "";
|
|
74
|
-
if (goal.length === 0 || Buffer.byteLength(goal) > AGENT_TASK_MAX_GOAL_BYTES)
|
|
75
|
-
throw new AgentServiceError("invalid_args", "goal must be 1..65536 bytes.");
|
|
76
|
-
if (typeof input.workspace !== "string" || input.workspace.length === 0)
|
|
77
|
-
throw new AgentServiceError("invalid_args", "workspace is required.");
|
|
78
|
-
const config = (await this.deps.config?.()) ?? DEFAULT_AGENT_CONFIG;
|
|
79
|
-
if (input.source.kind !== "gui" && !config.remoteControlEnabled)
|
|
80
|
-
throw new AgentServiceError("remote_control_disabled", "Run `frely app remote enable` first.");
|
|
81
|
-
const maxCostUsd = boundedCost(input.maxCostUsd ?? config.defaultMaxCostUsd, config.defaultMaxCostUsd);
|
|
82
|
-
const tasks = await this.deps.store.list();
|
|
83
|
-
const now = Date.now();
|
|
84
|
-
const active = tasks.filter((task) => !isTerminalStatus(task.status));
|
|
85
|
-
if (active.length >= config.maxConcurrentTasks)
|
|
86
|
-
throw new AgentServiceError("too_many_tasks");
|
|
87
|
-
const recentStarts = tasks.filter((task) => now - Date.parse(task.createdAt) < 60_000).length;
|
|
88
|
-
if (recentStarts >= AGENT_START_RATE_LIMIT_PER_MINUTE)
|
|
89
|
-
throw new AgentServiceError("rate_limited");
|
|
90
|
-
let worktree;
|
|
91
|
-
const taskId = newTaskId();
|
|
92
|
-
try {
|
|
93
|
-
worktree = await createTaskWorktree(taskId, input.workspace);
|
|
94
|
-
}
|
|
95
|
-
catch (error) {
|
|
96
|
-
if (error instanceof WorktreeError) {
|
|
97
|
-
if (error.code === "not_a_git_repo")
|
|
98
|
-
throw new AgentServiceError("workspace_not_git_repo");
|
|
99
|
-
if (error.code === "dirty_workspace")
|
|
100
|
-
throw new AgentServiceError("workspace_dirty");
|
|
101
|
-
}
|
|
102
|
-
throw error;
|
|
103
|
-
}
|
|
104
|
-
const id = taskId;
|
|
105
|
-
const record = {
|
|
106
|
-
id,
|
|
107
|
-
source: input.source,
|
|
108
|
-
workspace: input.workspace,
|
|
109
|
-
worktreePath: worktree.path,
|
|
110
|
-
branch: worktree.branch,
|
|
111
|
-
baseBranch: worktree.baseBranch,
|
|
112
|
-
baseCommit: worktree.baseCommit,
|
|
113
|
-
goal,
|
|
114
|
-
model: input.model ?? null,
|
|
115
|
-
maxCostUsd,
|
|
116
|
-
status: "queued",
|
|
117
|
-
mergeStatus: "none",
|
|
118
|
-
usage: { inputTokens: 0, outputTokens: 0, costUsd: 0 },
|
|
119
|
-
error: null,
|
|
120
|
-
mergeRequest: null,
|
|
121
|
-
approval: null,
|
|
122
|
-
createdAt: new Date().toISOString(),
|
|
123
|
-
updatedAt: new Date().toISOString(),
|
|
124
|
-
settledAt: null,
|
|
125
|
-
};
|
|
126
|
-
await this.deps.store.create(record);
|
|
127
|
-
try {
|
|
128
|
-
const connection = await this.ensureHostWithCredentials();
|
|
129
|
-
this.executors.set(id, new AgentToolExecutor(worktree.path, this.scheduler));
|
|
130
|
-
await connection.request("task.start", {
|
|
131
|
-
taskId: id,
|
|
132
|
-
worktreePath: worktree.path,
|
|
133
|
-
goal,
|
|
134
|
-
model: input.model ?? null,
|
|
135
|
-
budgetUsd: maxCostUsd,
|
|
136
|
-
baseBranch: worktree.baseBranch,
|
|
137
|
-
baseCommit: worktree.baseCommit,
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
catch (error) {
|
|
141
|
-
this.executors.delete(id);
|
|
142
|
-
await this.deps.store.update(id, (task) => ({ ...task, status: "failed", error: error instanceof Error ? error.message : "task start failed", settledAt: new Date().toISOString() }));
|
|
143
|
-
await this.deps.store.appendEvent(id, { type: "status", status: "failed", detail: "Agent host unavailable." });
|
|
144
|
-
if (error instanceof AgentServiceError)
|
|
145
|
-
throw error;
|
|
146
|
-
throw new AgentServiceError("host_unavailable", error instanceof Error ? error.message : "agent host unavailable");
|
|
147
|
-
}
|
|
148
|
-
return (await this.deps.store.read(id));
|
|
149
|
-
}
|
|
150
|
-
async listTasks(workspace) {
|
|
151
|
-
const tasks = await this.deps.store.list();
|
|
152
|
-
return workspace ? tasks.filter((task) => task.workspace === workspace) : tasks;
|
|
153
|
-
}
|
|
154
|
-
async getTask(id) {
|
|
155
|
-
return this.deps.store.read(id);
|
|
156
|
-
}
|
|
157
|
-
async getEvents(id, cursor = 0) {
|
|
158
|
-
return this.deps.store.readEvents(id, cursor);
|
|
159
|
-
}
|
|
160
|
-
async sendMessage(id, message) {
|
|
161
|
-
if (typeof message !== "string" || message.length === 0 || message.length > 64 * 1024)
|
|
162
|
-
throw new AgentServiceError("invalid_args");
|
|
163
|
-
const task = await this.deps.store.read(id);
|
|
164
|
-
if (task.status !== "running" && task.status !== "waiting_input")
|
|
165
|
-
throw new AgentServiceError("invalid_state", `Cannot send a message to a ${task.status} task.`);
|
|
166
|
-
const connection = await this.supervisor().ensureHost();
|
|
167
|
-
await connection.request("task.message", { taskId: id, message });
|
|
168
|
-
}
|
|
169
|
-
async cancelTask(id) {
|
|
170
|
-
const task = await this.deps.store.read(id);
|
|
171
|
-
if (isTerminalStatus(task.status))
|
|
172
|
-
return task;
|
|
173
|
-
if (task.status === "queued" && !this.executors.has(id)) {
|
|
174
|
-
return this.settleCancelled(id, "Cancelled before start.");
|
|
175
|
-
}
|
|
176
|
-
try {
|
|
177
|
-
const connection = await this.supervisor().ensureHost();
|
|
178
|
-
await connection.request("task.cancel", { taskId: id, reason: "User requested cancellation." }, 10_000);
|
|
179
|
-
}
|
|
180
|
-
catch (error) {
|
|
181
|
-
this.debug("agent.task.cancel_failed", id, error);
|
|
182
|
-
return this.settleCancelled(id, "Cancelled (host unreachable).");
|
|
183
|
-
}
|
|
184
|
-
return this.deps.store.read(id);
|
|
185
|
-
}
|
|
186
|
-
async settleCancelled(id, detail) {
|
|
187
|
-
this.executors.delete(id);
|
|
188
|
-
const record = await this.deps.store.update(id, (task) => ({ ...task, status: "cancelled", settledAt: new Date().toISOString() }));
|
|
189
|
-
await this.deps.store.appendEvent(id, { type: "status", status: "cancelled", detail });
|
|
190
|
-
return record;
|
|
191
|
-
}
|
|
192
|
-
async getDiff(id, path) {
|
|
193
|
-
const task = await this.deps.store.read(id);
|
|
194
|
-
try {
|
|
195
|
-
return await taskDiff(id, task.workspace, path);
|
|
196
|
-
}
|
|
197
|
-
catch (error) {
|
|
198
|
-
if (error instanceof WorktreeError && error.code === "not_a_git_repo")
|
|
199
|
-
throw new AgentServiceError("workspace_not_git_repo");
|
|
200
|
-
throw new AgentServiceError("internal", error instanceof Error ? error.message : "diff failed");
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
async requestMerge(id, note) {
|
|
204
|
-
const task = await this.deps.store.read(id);
|
|
205
|
-
if (task.status !== "completed")
|
|
206
|
-
throw new AgentServiceError("invalid_state", "Only completed tasks can request a merge.");
|
|
207
|
-
if (task.mergeStatus !== "none")
|
|
208
|
-
throw new AgentServiceError("invalid_state", `Merge already ${task.mergeStatus}.`);
|
|
209
|
-
return this.deps.store.update(id, (record) => ({
|
|
210
|
-
...record,
|
|
211
|
-
mergeStatus: "merge_requested",
|
|
212
|
-
mergeRequest: { requestedAt: new Date().toISOString(), ...(note !== undefined && note.length > 0 ? { note: note.slice(0, 2048) } : {}) },
|
|
213
|
-
}));
|
|
214
|
-
}
|
|
215
|
-
async approveMerge(id, approvedBy) {
|
|
216
|
-
const task = await this.deps.store.read(id);
|
|
217
|
-
if (task.mergeStatus !== "merge_requested")
|
|
218
|
-
throw new AgentServiceError("invalid_state", `Merge state is ${task.mergeStatus}.`);
|
|
219
|
-
const approved = await this.deps.store.update(id, (record) => ({
|
|
220
|
-
...record,
|
|
221
|
-
mergeStatus: "approved",
|
|
222
|
-
approval: { approvedAt: new Date().toISOString(), approvedBy },
|
|
223
|
-
}));
|
|
224
|
-
const outcome = await mergeTaskBranch(id, task.workspace);
|
|
225
|
-
if (outcome.status === "merged") {
|
|
226
|
-
await removeTaskWorktree(id, task.workspace).catch(() => undefined);
|
|
227
|
-
return this.deps.store.update(id, (record) => ({ ...record, mergeStatus: "merged" }));
|
|
228
|
-
}
|
|
229
|
-
return this.deps.store.update(id, (record) => ({ ...record, mergeStatus: "merge_conflict", error: outcome.detail }));
|
|
230
|
-
}
|
|
231
|
-
async discardTask(id) {
|
|
232
|
-
const task = await this.deps.store.read(id);
|
|
233
|
-
if (task.mergeStatus === "merged" || task.mergeStatus === "discarded")
|
|
234
|
-
throw new AgentServiceError("invalid_state", `Task already ${task.mergeStatus}.`);
|
|
235
|
-
await removeTaskWorktree(id, task.workspace).catch(() => undefined);
|
|
236
|
-
this.executors.delete(id);
|
|
237
|
-
return this.deps.store.update(id, (record) => ({ ...record, mergeStatus: "discarded" }));
|
|
238
|
-
}
|
|
239
|
-
async stopHost() {
|
|
240
|
-
for (const executor of this.executors.values())
|
|
241
|
-
executor.dispose();
|
|
242
|
-
this.executors.clear();
|
|
243
|
-
await this.supervisor().stop();
|
|
244
|
-
}
|
|
245
|
-
status() {
|
|
246
|
-
return { host: this.supervisor().status() };
|
|
247
|
-
}
|
|
248
|
-
// --- host wiring ---------------------------------------------------------
|
|
249
|
-
async ensureHostWithCredentials() {
|
|
250
|
-
const connection = await this.supervisor().ensureHost();
|
|
251
|
-
if (!this.credentialsSent) {
|
|
252
|
-
const credentials = this.deps.modelCredentials?.();
|
|
253
|
-
if (credentials)
|
|
254
|
-
connection.notify("model.credentials", credentials);
|
|
255
|
-
this.credentialsSent = true;
|
|
256
|
-
}
|
|
257
|
-
return connection;
|
|
258
|
-
}
|
|
259
|
-
debug(event, taskId, error) {
|
|
260
|
-
this.deps.log?.(JSON.stringify({ timestamp: new Date().toISOString(), pid: process.pid, event, taskId, ...(error ? { error: error instanceof Error ? error.message : String(error) } : {}) }));
|
|
261
|
-
}
|
|
262
|
-
eventsQueue = Promise.resolve();
|
|
263
|
-
onTaskEvent = (taskId, event) => {
|
|
264
|
-
// Hosts may burst events in a single tick (e.g. running+completed); apply them
|
|
265
|
-
// strictly in arrival order so a late non-terminal write cannot overwrite a terminal one.
|
|
266
|
-
this.eventsQueue = this.eventsQueue
|
|
267
|
-
.then(() => this.handleTaskEvent(taskId, event))
|
|
268
|
-
.catch((error) => this.debug("agent.event_apply_failed", taskId, error));
|
|
269
|
-
};
|
|
270
|
-
async handleTaskEvent(taskId, event) {
|
|
271
|
-
if (event.type === "status") {
|
|
272
|
-
const current = await this.deps.store.read(taskId).catch(() => null);
|
|
273
|
-
if (!current)
|
|
274
|
-
return;
|
|
275
|
-
const next = nextRuntimeStatus(current.status, event);
|
|
276
|
-
if (next === null) {
|
|
277
|
-
this.debug("agent.task.status_rejected", taskId);
|
|
278
|
-
return;
|
|
279
|
-
}
|
|
280
|
-
await this.deps.store.update(taskId, (task) => ({
|
|
281
|
-
...task,
|
|
282
|
-
status: next,
|
|
283
|
-
error: next === "failed" ? event.detail ?? "Task failed." : task.error,
|
|
284
|
-
settledAt: isTerminalStatus(next) ? new Date().toISOString() : task.settledAt,
|
|
285
|
-
}));
|
|
286
|
-
if (isTerminalStatus(next)) {
|
|
287
|
-
this.executors.get(taskId)?.dispose();
|
|
288
|
-
this.executors.delete(taskId);
|
|
289
|
-
void this.supervisor().ensureHost().then((connection) => connection.request("session.dispose", { taskId }, 5_000)).catch(() => undefined);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
if (event.type === "usage") {
|
|
293
|
-
const task = await this.deps.store.read(taskId).catch(() => null);
|
|
294
|
-
if (!task)
|
|
295
|
-
return;
|
|
296
|
-
await this.deps.store.update(taskId, (record) => ({
|
|
297
|
-
...record,
|
|
298
|
-
usage: {
|
|
299
|
-
inputTokens: record.usage.inputTokens + event.inputTokens,
|
|
300
|
-
outputTokens: record.usage.outputTokens + event.outputTokens,
|
|
301
|
-
costUsd: Math.max(record.usage.costUsd, event.costUsd),
|
|
302
|
-
},
|
|
303
|
-
}));
|
|
304
|
-
const latest = await this.deps.store.read(taskId);
|
|
305
|
-
if (latest.usage.costUsd >= latest.maxCostUsd && !isTerminalStatus(latest.status) && !this.budgetCancels.has(taskId)) {
|
|
306
|
-
this.budgetCancels.add(taskId);
|
|
307
|
-
void this.supervisor()
|
|
308
|
-
.ensureHost()
|
|
309
|
-
.then((connection) => connection.request("task.cancel", { taskId, reason: "Budget limit reached." }, 10_000))
|
|
310
|
-
.catch(() => this.settleCancelled(taskId, "Budget limit reached (host unreachable)."));
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
await this.deps.store.appendEvent(taskId, event);
|
|
314
|
-
}
|
|
315
|
-
onHostLost = (error) => {
|
|
316
|
-
this.credentialsSent = false;
|
|
317
|
-
this.budgetCancels.clear();
|
|
318
|
-
void this.failRunningTasks(error).catch(() => undefined);
|
|
319
|
-
};
|
|
320
|
-
async failRunningTasks(error) {
|
|
321
|
-
const detail = error ? `Agent host exited unexpectedly: ${error.message}` : "Agent host exited unexpectedly.";
|
|
322
|
-
for (const task of await this.deps.store.list()) {
|
|
323
|
-
if (isTerminalStatus(task.status))
|
|
324
|
-
continue;
|
|
325
|
-
this.executors.delete(task.id);
|
|
326
|
-
await this.deps.store.update(task.id, (record) => ({ ...record, status: "failed", error: detail, settledAt: new Date().toISOString() }));
|
|
327
|
-
await this.deps.store.appendEvent(task.id, { type: "status", status: "failed", detail });
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
onToolRequest = async (request, args, taskId) => {
|
|
331
|
-
const kind = toolKindFromMethod(request.method);
|
|
332
|
-
if (!kind)
|
|
333
|
-
throw new Error(`Unsupported tool method: ${request.method}`);
|
|
334
|
-
const executor = this.executors.get(taskId);
|
|
335
|
-
if (!executor) {
|
|
336
|
-
const task = await this.deps.store.read(taskId).catch(() => null);
|
|
337
|
-
if (!task)
|
|
338
|
-
throw new Error("Unknown task.");
|
|
339
|
-
throw new Error(`Task ${taskId} is ${task.status}; tools are unavailable.`);
|
|
340
|
-
}
|
|
341
|
-
const result = await executor.execute(kind, args);
|
|
342
|
-
if (!result.ok)
|
|
343
|
-
throw new Error(result.error.message);
|
|
344
|
-
return result.result;
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
|
-
export { TaskStore, AgentStoreError, branchNameForTask };
|
|
348
|
-
//# sourceMappingURL=agent-service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"agent-service.js","sourceRoot":"","sources":["../../src/agent/agent-service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,C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AAC;QAC9E,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAClD,IAAI,CAAC,MAAM,CAAC,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACtD,OAAO,MAAM,CAAC,MAAM,CAAC;IACvB,CAAC,CAAC;CACH;AAED,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,iBAAiB,EAAE,CAAC"}
|
package/dist/agent/app-key.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export declare const DEFAULT_LIFETIME_USD = 50;
|
|
2
|
-
export declare const MAX_LIFETIME_USD = 500;
|
|
3
|
-
export declare class AppKeyError extends Error {
|
|
4
|
-
readonly code: string;
|
|
5
|
-
readonly status: number;
|
|
6
|
-
constructor(code: string, status: number, message: string);
|
|
7
|
-
}
|
|
8
|
-
export interface ProvisionedAppKey {
|
|
9
|
-
keyId: string;
|
|
10
|
-
rawKey: string;
|
|
11
|
-
name: string;
|
|
12
|
-
lifetimeUsd: number | null;
|
|
13
|
-
}
|
|
14
|
-
export declare function provisionAgentKey(lifetimeUsd?: number): Promise<ProvisionedAppKey>;
|
package/dist/agent/app-key.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `frely app key`: provision a device-scoped Frely API key for agent tasks
|
|
3
|
-
* (plan frely-app-agent-toolset §9.3). The key is shown once and never stored
|
|
4
|
-
* by the CLI; it is bound to a device the caller owns and capped at a
|
|
5
|
-
* lifetime spend limit enforced by the relay backend.
|
|
6
|
-
*/
|
|
7
|
-
import { requireLogin } from "../auth.js";
|
|
8
|
-
import { ensureDevice, relayFetch } from "../device/control.js";
|
|
9
|
-
const ENDPOINT = "/api/user/device-relay/agent-key";
|
|
10
|
-
export const DEFAULT_LIFETIME_USD = 50;
|
|
11
|
-
export const MAX_LIFETIME_USD = 500;
|
|
12
|
-
export class AppKeyError extends Error {
|
|
13
|
-
code;
|
|
14
|
-
status;
|
|
15
|
-
constructor(code, status, message) {
|
|
16
|
-
super(message);
|
|
17
|
-
this.code = code;
|
|
18
|
-
this.status = status;
|
|
19
|
-
this.name = "AppKeyError";
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
export async function provisionAgentKey(lifetimeUsd = DEFAULT_LIFETIME_USD) {
|
|
23
|
-
if (!Number.isFinite(lifetimeUsd) || lifetimeUsd <= 0 || lifetimeUsd > MAX_LIFETIME_USD) {
|
|
24
|
-
throw new Error(`--lifetime-usd must be a positive amount of at most ${MAX_LIFETIME_USD}.`);
|
|
25
|
-
}
|
|
26
|
-
const auth = await requireLogin();
|
|
27
|
-
const device = await ensureDevice();
|
|
28
|
-
const response = await relayFetch(auth.config.relayUrl, auth.credential, ENDPOINT, {
|
|
29
|
-
method: "POST",
|
|
30
|
-
body: JSON.stringify({ deviceId: device.deviceId, lifetimeUsd }),
|
|
31
|
-
});
|
|
32
|
-
if (!response.ok) {
|
|
33
|
-
const body = await response.json().catch(() => null);
|
|
34
|
-
throw new AppKeyError(body?.error?.code ?? "agent_key_failed", response.status, body?.error?.message ?? `Agent key provisioning failed (${response.status}).`);
|
|
35
|
-
}
|
|
36
|
-
const created = await response.json();
|
|
37
|
-
if (typeof created.apiKey?.id !== "string" || typeof created.rawKey !== "string" || created.rawKey.length === 0)
|
|
38
|
-
throw new AppKeyError("agent_key_invalid", response.status, "Agent key response was invalid.");
|
|
39
|
-
return {
|
|
40
|
-
keyId: created.apiKey.id,
|
|
41
|
-
rawKey: created.rawKey,
|
|
42
|
-
name: created.apiKey.name ?? `frely-app ${device.deviceId.slice(-8)}`,
|
|
43
|
-
lifetimeUsd: created.limits?.lifetimeAmount ?? null,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
//# sourceMappingURL=app-key.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"app-key.js","sourceRo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MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAA2D,CAAC;QAC/G,MAAM,IAAI,WAAW,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,IAAI,kBAAkB,EAAE,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,IAAI,kCAAkC,QAAQ,CAAC,MAAM,IAAI,CAAC,CAAC;IACjK,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,IAAI,EAA+G,CAAC;IACnJ,IAAI,OAAO,OAAO,CAAC,MAAM,EAAE,EAAE,KAAK,QAAQ,IAAI,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,WAAW,CAAC,mBAAmB,EAAE,QAAQ,CAAC,MAAM,EAAE,iCAAiC,CAAC,CAAC;IAChN,OAAO;QACL,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE;QACxB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,IAAI,aAAa,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;QACrE,WAAW,EAAE,OAAO,CAAC,MAAM,EAAE,cAAc,IAAI,IAAI;KACpD,CAAC;AACJ,CAAC"}
|
package/dist/agent/compose.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Composition root for the agent stack: builds an AgentService wired to the
|
|
3
|
-
* real app install, capsule verification, and the agent host supervisor.
|
|
4
|
-
* Failures (e.g. app not installed) surface lazily on first host use so the
|
|
5
|
-
* device relay daemon keeps serving MCP traffic.
|
|
6
|
-
*/
|
|
7
|
-
import { AgentService } from "./agent-service.js";
|
|
8
|
-
import { TaskStore } from "./task-store.js";
|
|
9
|
-
import type { DiagnosticLog } from "../runtime/diagnostics.js";
|
|
10
|
-
export type CreateAgentServiceOptions = {
|
|
11
|
-
log?: DiagnosticLog;
|
|
12
|
-
env?: NodeJS.ProcessEnv;
|
|
13
|
-
defaultWorkspace: string;
|
|
14
|
-
modelCredentials?: () => {
|
|
15
|
-
apiKey: string;
|
|
16
|
-
baseUrl: string;
|
|
17
|
-
model: string;
|
|
18
|
-
} | null;
|
|
19
|
-
fullIntegrityVerification?: boolean;
|
|
20
|
-
store?: TaskStore;
|
|
21
|
-
};
|
|
22
|
-
export declare function createAgentService(options: CreateAgentServiceOptions): AgentService;
|
|
23
|
-
export { AgentService };
|
package/dist/agent/compose.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Composition root for the agent stack: builds an AgentService wired to the
|
|
3
|
-
* real app install, capsule verification, and the agent host supervisor.
|
|
4
|
-
* Failures (e.g. app not installed) surface lazily on first host use so the
|
|
5
|
-
* device relay daemon keeps serving MCP traffic.
|
|
6
|
-
*/
|
|
7
|
-
import { AgentService } from "./agent-service.js";
|
|
8
|
-
import { readAppInstall, verifyCapsule } from "./app-install.js";
|
|
9
|
-
import { AgentHostSupervisor } from "./supervisor.js";
|
|
10
|
-
import { TaskStore } from "./task-store.js";
|
|
11
|
-
export function createAgentService(options) {
|
|
12
|
-
const env = options.env ?? process.env;
|
|
13
|
-
const store = options.store ?? TaskStore.open(undefined, env);
|
|
14
|
-
const resolveFacts = async () => {
|
|
15
|
-
const install = await readAppInstall(undefined, env);
|
|
16
|
-
return verifyCapsule(install);
|
|
17
|
-
};
|
|
18
|
-
let service = null;
|
|
19
|
-
const supervisor = new AgentHostSupervisor({
|
|
20
|
-
resolveFacts,
|
|
21
|
-
fullIntegrityVerification: options.fullIntegrityVerification ?? true,
|
|
22
|
-
appInstall: () => readAppInstall(undefined, env),
|
|
23
|
-
isIdle: () => {
|
|
24
|
-
if (!service)
|
|
25
|
-
return true;
|
|
26
|
-
return service.listTasks().then((tasks) => tasks.every((task) => task.status !== "queued" && task.status !== "running" && task.status !== "waiting_input")).catch(() => true);
|
|
27
|
-
},
|
|
28
|
-
onEvent: (taskId, event) => service?.onTaskEvent(taskId, event),
|
|
29
|
-
onToolRequest: (request, args, taskId) => service.onToolRequest(request, args, taskId),
|
|
30
|
-
onHostLost: (error) => service?.onHostLost(error),
|
|
31
|
-
log: options.log,
|
|
32
|
-
});
|
|
33
|
-
service = new AgentService({
|
|
34
|
-
store,
|
|
35
|
-
resolveSupervisor: () => supervisor,
|
|
36
|
-
...(options.modelCredentials ? { modelCredentials: options.modelCredentials } : {}),
|
|
37
|
-
...(options.log ? { log: options.log } : {}),
|
|
38
|
-
});
|
|
39
|
-
return service;
|
|
40
|
-
}
|
|
41
|
-
export { AgentService };
|
|
42
|
-
//# sourceMappingURL=compose.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compose.js","sourceRoot":"","sources":["../../src/agent/compose.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAqB,MAAM,kBAAkB,CAAC;AACpF,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAY5C,MAAM,UAAU,kBAAkB,CAAC,OAAkC;IACnE,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC;IACvC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,SAAS,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;IAC9D,MAAM,YAAY,GAAG,KAAK,IAA2B,EAAE;QACrD,MAAM,OAAO,GAAG,MAAM,cAAc,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;QACrD,OAAO,aAAa,CAAC,OAAO,CAAC,CAAC;I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CAAC;QACnF,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC7C,CAAC,CAAC;IACH,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { AgentService } from "./agent-service.js";
|
|
2
|
-
export interface AgentOpsServer {
|
|
3
|
-
path: string;
|
|
4
|
-
close: () => Promise<void>;
|
|
5
|
-
}
|
|
6
|
-
export interface AgentOpsServerOptions {
|
|
7
|
-
workspace: string;
|
|
8
|
-
socketPath?: string;
|
|
9
|
-
env?: NodeJS.ProcessEnv;
|
|
10
|
-
pollIntervalMs?: number;
|
|
11
|
-
log?: (message: string) => void;
|
|
12
|
-
}
|
|
13
|
-
export declare function startAgentOpsServer(agent: AgentService, options: AgentOpsServerOptions): Promise<AgentOpsServer>;
|
|
14
|
-
export declare function pingAgentOpsSocket(socketPath: string, timeoutMs: number): Promise<{
|
|
15
|
-
running: boolean;
|
|
16
|
-
pid?: number | undefined;
|
|
17
|
-
version?: string | undefined;
|
|
18
|
-
}>;
|