@av-pi-studio/server 0.0.113 → 0.0.115
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/agent-service.d.ts +5 -0
- package/dist/agent/agent-service.js +12 -0
- package/dist/agent/agent-todos/agent-todos-rpc.d.ts +16 -0
- package/dist/agent/agent-todos/agent-todos-rpc.js +20 -0
- package/dist/agent/agent-todos/agent-todos-service.d.ts +68 -0
- package/dist/agent/agent-todos/agent-todos-service.js +155 -0
- package/dist/agent/agent-todos/todo-limits.d.ts +9 -0
- package/dist/agent/agent-todos/todo-limits.js +50 -0
- package/dist/agent/provider-contract.d.ts +24 -1
- package/dist/agent/providers/mock/mock-provider.d.ts +31 -2
- package/dist/agent/providers/mock/mock-provider.js +134 -1
- package/dist/agent/providers/mock/todo-script.d.ts +55 -0
- package/dist/agent/providers/mock/todo-script.js +168 -0
- package/dist/agent/providers/mock/tool-script.d.ts +28 -0
- package/dist/agent/providers/mock/tool-script.js +72 -0
- package/dist/agent/providers/pi/agent.d.ts +5 -1
- package/dist/agent/providers/pi/agent.js +51 -1
- package/dist/agent/providers/pi/event-mapper.d.ts +15 -12
- package/dist/agent/providers/pi/event-mapper.js +33 -15
- package/dist/agent/providers/pi/session-hydration.d.ts +9 -0
- package/dist/agent/providers/pi/session-hydration.js +12 -0
- package/dist/agent/providers/pi/todos.d.ts +65 -0
- package/dist/agent/providers/pi/todos.js +122 -0
- package/dist/agent/providers/pi/tool-output-coalescer.d.ts +58 -0
- package/dist/agent/providers/pi/tool-output-coalescer.js +121 -0
- package/dist/agent/slash-command-operations.d.ts +7 -0
- package/dist/agent/slash-command-operations.js +1 -0
- package/dist/daemon/bootstrap.js +19 -1
- package/dist/daemon/dev-bootstrap.js +20 -1
- package/package.json +8 -3
|
@@ -42,6 +42,11 @@ export declare function resetTimeline(agentId: string, rows: import("./timeline-
|
|
|
42
42
|
* Record `event` on `agentId`'s timeline and broadcast it as an `agent_stream` frame carrying the
|
|
43
43
|
* daemon-owned seq/timestamp. The one append-and-broadcast path for stream events: `runTurn`'s
|
|
44
44
|
* subscription and any operation that subscribes outside a turn (today: compaction) both use it.
|
|
45
|
+
*
|
|
46
|
+
* Two kinds are EPHEMERAL (live-stream-only, see timeline-streaming.md § Timeline model): a partial
|
|
47
|
+
* `tool_call` (a superseded in-flight output snapshot) and `queue_update` (a snapshot of the
|
|
48
|
+
* pending steer/follow-up queues). They are broadcast with a daemon-owned `timestamp` but NO `seq`,
|
|
49
|
+
* and are never appended to the timeline, so they never appear in fetched history.
|
|
45
50
|
*/
|
|
46
51
|
export declare function appendStreamEvent(agentId: string, event: AgentStreamEvent, broadcast: (sessions: Iterable<Session>, message: unknown) => void, sessions: Iterable<Session>): void;
|
|
47
52
|
/**
|
|
@@ -43,8 +43,20 @@ export function resetTimeline(agentId, rows) {
|
|
|
43
43
|
* Record `event` on `agentId`'s timeline and broadcast it as an `agent_stream` frame carrying the
|
|
44
44
|
* daemon-owned seq/timestamp. The one append-and-broadcast path for stream events: `runTurn`'s
|
|
45
45
|
* subscription and any operation that subscribes outside a turn (today: compaction) both use it.
|
|
46
|
+
*
|
|
47
|
+
* Two kinds are EPHEMERAL (live-stream-only, see timeline-streaming.md § Timeline model): a partial
|
|
48
|
+
* `tool_call` (a superseded in-flight output snapshot) and `queue_update` (a snapshot of the
|
|
49
|
+
* pending steer/follow-up queues). They are broadcast with a daemon-owned `timestamp` but NO `seq`,
|
|
50
|
+
* and are never appended to the timeline, so they never appear in fetched history.
|
|
46
51
|
*/
|
|
47
52
|
export function appendStreamEvent(agentId, event, broadcast, sessions) {
|
|
53
|
+
if ((event.kind === "tool_call" && event.partial) || event.kind === "queue_update") {
|
|
54
|
+
broadcast(sessions, {
|
|
55
|
+
type: "session",
|
|
56
|
+
message: { type: "agent_stream", agentId, timestamp: new Date().toISOString(), event },
|
|
57
|
+
});
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
48
60
|
const row = getOrCreateTimeline(agentId).append(event);
|
|
49
61
|
broadcast(sessions, {
|
|
50
62
|
type: "session",
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HandlerRegistry } from "../../ws/router.js";
|
|
2
|
+
import type { AgentTodosService } from "./agent-todos-service.js";
|
|
3
|
+
/**
|
|
4
|
+
* Wires `agent_todos_list_request` (swe/features/agent-todos.md § Wire family) onto
|
|
5
|
+
* `AgentTodosService`: a thin adapter that stamps no policy of its own. The answer is flat — a
|
|
6
|
+
* success carries `snapshot` (and no `ok`), a refusal carries `ok: false` + an open-string `error`
|
|
7
|
+
* (`not_found`). An unreadable session file is already an empty snapshot inside the service, so
|
|
8
|
+
* this handler never raises `rpc_error` for it. `requestId` is stamped by the router.
|
|
9
|
+
*
|
|
10
|
+
* Registered in **both** bootstraps: the mock provider is this family's scripted producer, so the
|
|
11
|
+
* dev daemon has to serve it.
|
|
12
|
+
*/
|
|
13
|
+
export declare function registerAgentTodosHandlers(registry: HandlerRegistry, deps: {
|
|
14
|
+
service: AgentTodosService;
|
|
15
|
+
}): void;
|
|
16
|
+
//# sourceMappingURL=agent-todos-rpc.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wires `agent_todos_list_request` (swe/features/agent-todos.md § Wire family) onto
|
|
3
|
+
* `AgentTodosService`: a thin adapter that stamps no policy of its own. The answer is flat — a
|
|
4
|
+
* success carries `snapshot` (and no `ok`), a refusal carries `ok: false` + an open-string `error`
|
|
5
|
+
* (`not_found`). An unreadable session file is already an empty snapshot inside the service, so
|
|
6
|
+
* this handler never raises `rpc_error` for it. `requestId` is stamped by the router.
|
|
7
|
+
*
|
|
8
|
+
* Registered in **both** bootstraps: the mock provider is this family's scripted producer, so the
|
|
9
|
+
* dev daemon has to serve it.
|
|
10
|
+
*/
|
|
11
|
+
export function registerAgentTodosHandlers(registry, deps) {
|
|
12
|
+
registry.register("agent_todos_list_request", (ctx) => {
|
|
13
|
+
const agentId = typeof ctx.message.agentId === "string" ? ctx.message.agentId : "";
|
|
14
|
+
const result = deps.service.list(agentId);
|
|
15
|
+
return result.ok
|
|
16
|
+
? { type: "agent_todos_list_response", snapshot: result.snapshot }
|
|
17
|
+
: { type: "agent_todos_list_response", ok: false, error: result.error };
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=agent-todos-rpc.js.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { AgentTodosSnapshot } from "@av-pi-studio/protocol";
|
|
2
|
+
import type { Logger } from "../../logging/logger.js";
|
|
3
|
+
import type { Session } from "../../ws/session.js";
|
|
4
|
+
import type { ManagedAgent } from "../agent-manager.js";
|
|
5
|
+
import type { AgentClient, AgentSession } from "../provider-contract.js";
|
|
6
|
+
export interface AgentTodosServiceDeps {
|
|
7
|
+
broadcast: (sessions: Iterable<Session>, message: unknown) => void;
|
|
8
|
+
getActiveSessions: () => Iterable<Session>;
|
|
9
|
+
/** The agent record plus its live session, if any (`AgentManager.get`). */
|
|
10
|
+
getAgent: (agentId: string) => ManagedAgent | undefined;
|
|
11
|
+
resolveClient: (provider: string) => AgentClient;
|
|
12
|
+
logger?: Logger;
|
|
13
|
+
}
|
|
14
|
+
export type AgentTodosListResult = {
|
|
15
|
+
ok: true;
|
|
16
|
+
snapshot: AgentTodosSnapshot;
|
|
17
|
+
} | {
|
|
18
|
+
ok: false;
|
|
19
|
+
error: "not_found";
|
|
20
|
+
};
|
|
21
|
+
export declare class AgentTodosService {
|
|
22
|
+
private readonly broadcastFn;
|
|
23
|
+
private readonly getActiveSessions;
|
|
24
|
+
private readonly getAgent;
|
|
25
|
+
private readonly resolveClient;
|
|
26
|
+
private readonly logger;
|
|
27
|
+
private readonly entries;
|
|
28
|
+
constructor(deps: AgentTodosServiceDeps);
|
|
29
|
+
/**
|
|
30
|
+
* `AgentManager.onSessionAttached` hook. Drops the previous session's subscriptions (a respawn
|
|
31
|
+
* leaves the old process's emissions meaningless), then watches the new one and seeds from its
|
|
32
|
+
* session file. The retained list is NOT cleared first: if the seed is equal nothing is
|
|
33
|
+
* broadcast, so a respawn never flickers the panel.
|
|
34
|
+
*/
|
|
35
|
+
attach(agentId: string, session: AgentSession): void;
|
|
36
|
+
/**
|
|
37
|
+
* Re-derive from the session's CURRENT file and publish the difference (settled turn,
|
|
38
|
+
* compaction, fork/rebind). With no live session there is nothing to compare against: drop the
|
|
39
|
+
* cache so the next `list` reads the file again.
|
|
40
|
+
*/
|
|
41
|
+
reconcile(agentId: string): void;
|
|
42
|
+
/**
|
|
43
|
+
* The current snapshot for any known agent, live or process-less. Never an error for an
|
|
44
|
+
* unreadable session file: that is an empty snapshot plus a `warn`.
|
|
45
|
+
*/
|
|
46
|
+
list(agentId: string): AgentTodosListResult;
|
|
47
|
+
/**
|
|
48
|
+
* Archive / delete / any terminal event for the agent. Broadcasts an empty snapshot (with `seq`
|
|
49
|
+
* + 1) only if there was a list to clear, and keeps the counter so a later attach continues
|
|
50
|
+
* upward.
|
|
51
|
+
*/
|
|
52
|
+
sweep(agentId: string): void;
|
|
53
|
+
private entry;
|
|
54
|
+
private unsubscribe;
|
|
55
|
+
/**
|
|
56
|
+
* Run a provider read; a throw is logged (agent id + message, no task text) and changes nothing,
|
|
57
|
+
* leaving `loaded` as it was so the next `list` retries a transient failure.
|
|
58
|
+
*/
|
|
59
|
+
private read;
|
|
60
|
+
/**
|
|
61
|
+
* Make `list` the agent's current list. An equal list is a no-op; otherwise `seq` advances and,
|
|
62
|
+
* when `broadcast` is set, every active session hears it. `broadcast: false` is the first load
|
|
63
|
+
* behind a `list` RPC: the answer carries the new `seq`, nobody else needs it.
|
|
64
|
+
*/
|
|
65
|
+
private publish;
|
|
66
|
+
private snapshotOf;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=agent-todos-service.d.ts.map
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from "node:util";
|
|
2
|
+
const EMPTY = { tasks: [], truncated: false };
|
|
3
|
+
function hasTodoMembers(session) {
|
|
4
|
+
return typeof session.onTodos === "function" && typeof session.readTodos === "function";
|
|
5
|
+
}
|
|
6
|
+
export class AgentTodosService {
|
|
7
|
+
broadcastFn;
|
|
8
|
+
getActiveSessions;
|
|
9
|
+
getAgent;
|
|
10
|
+
resolveClient;
|
|
11
|
+
logger;
|
|
12
|
+
entries = new Map();
|
|
13
|
+
constructor(deps) {
|
|
14
|
+
this.broadcastFn = deps.broadcast;
|
|
15
|
+
this.getActiveSessions = deps.getActiveSessions;
|
|
16
|
+
this.getAgent = deps.getAgent;
|
|
17
|
+
this.resolveClient = deps.resolveClient;
|
|
18
|
+
this.logger = deps.logger;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* `AgentManager.onSessionAttached` hook. Drops the previous session's subscriptions (a respawn
|
|
22
|
+
* leaves the old process's emissions meaningless), then watches the new one and seeds from its
|
|
23
|
+
* session file. The retained list is NOT cleared first: if the seed is equal nothing is
|
|
24
|
+
* broadcast, so a respawn never flickers the panel.
|
|
25
|
+
*/
|
|
26
|
+
attach(agentId, session) {
|
|
27
|
+
this.unsubscribe(agentId);
|
|
28
|
+
if (!hasTodoMembers(session))
|
|
29
|
+
return;
|
|
30
|
+
const entry = this.entry(agentId);
|
|
31
|
+
entry.unsubscribes.push(session.onTodos((list) => this.publish(agentId, list, true)), session.subscribe((event) => {
|
|
32
|
+
if (event.kind === "turn_completed" ||
|
|
33
|
+
event.kind === "turn_failed" ||
|
|
34
|
+
event.kind === "turn_canceled" ||
|
|
35
|
+
(event.kind === "compaction" && event.phase === "completed")) {
|
|
36
|
+
this.reconcile(agentId);
|
|
37
|
+
}
|
|
38
|
+
}));
|
|
39
|
+
this.read(agentId, () => session.readTodos(), true);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Re-derive from the session's CURRENT file and publish the difference (settled turn,
|
|
43
|
+
* compaction, fork/rebind). With no live session there is nothing to compare against: drop the
|
|
44
|
+
* cache so the next `list` reads the file again.
|
|
45
|
+
*/
|
|
46
|
+
reconcile(agentId) {
|
|
47
|
+
const session = this.getAgent(agentId)?.session;
|
|
48
|
+
if (session && hasTodoMembers(session)) {
|
|
49
|
+
this.read(agentId, () => session.readTodos(), true);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const entry = this.entries.get(agentId);
|
|
53
|
+
if (entry)
|
|
54
|
+
entry.loaded = false;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The current snapshot for any known agent, live or process-less. Never an error for an
|
|
58
|
+
* unreadable session file: that is an empty snapshot plus a `warn`.
|
|
59
|
+
*/
|
|
60
|
+
list(agentId) {
|
|
61
|
+
const managed = this.getAgent(agentId);
|
|
62
|
+
if (!managed)
|
|
63
|
+
return { ok: false, error: "not_found" };
|
|
64
|
+
const existing = this.entries.get(agentId);
|
|
65
|
+
if (!existing?.loaded) {
|
|
66
|
+
const session = managed.session;
|
|
67
|
+
if (session && hasTodoMembers(session)) {
|
|
68
|
+
this.read(agentId, () => session.readTodos(), false);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
const handle = managed.record.persistence;
|
|
72
|
+
const client = this.resolveClient(managed.record.provider);
|
|
73
|
+
if (handle && client.readTodos) {
|
|
74
|
+
this.read(agentId, () => client.readTodos(handle), false);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return { ok: true, snapshot: this.snapshotOf(agentId) };
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Archive / delete / any terminal event for the agent. Broadcasts an empty snapshot (with `seq`
|
|
82
|
+
* + 1) only if there was a list to clear, and keeps the counter so a later attach continues
|
|
83
|
+
* upward.
|
|
84
|
+
*/
|
|
85
|
+
sweep(agentId) {
|
|
86
|
+
this.unsubscribe(agentId);
|
|
87
|
+
const entry = this.entries.get(agentId);
|
|
88
|
+
if (!entry)
|
|
89
|
+
return;
|
|
90
|
+
this.publish(agentId, EMPTY, true);
|
|
91
|
+
entry.loaded = false;
|
|
92
|
+
}
|
|
93
|
+
entry(agentId) {
|
|
94
|
+
let entry = this.entries.get(agentId);
|
|
95
|
+
if (!entry) {
|
|
96
|
+
entry = { seq: 0, list: EMPTY, loaded: false, unsubscribes: [] };
|
|
97
|
+
this.entries.set(agentId, entry);
|
|
98
|
+
}
|
|
99
|
+
return entry;
|
|
100
|
+
}
|
|
101
|
+
unsubscribe(agentId) {
|
|
102
|
+
const entry = this.entries.get(agentId);
|
|
103
|
+
if (!entry)
|
|
104
|
+
return;
|
|
105
|
+
for (const off of entry.unsubscribes)
|
|
106
|
+
off();
|
|
107
|
+
entry.unsubscribes = [];
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Run a provider read; a throw is logged (agent id + message, no task text) and changes nothing,
|
|
111
|
+
* leaving `loaded` as it was so the next `list` retries a transient failure.
|
|
112
|
+
*/
|
|
113
|
+
read(agentId, source, broadcast) {
|
|
114
|
+
let list;
|
|
115
|
+
try {
|
|
116
|
+
list = source();
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
this.logger?.warn({ agentId, err: err instanceof Error ? err.message : String(err) }, "agent-todos: reading the session todo list failed");
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
this.publish(agentId, list, broadcast);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Make `list` the agent's current list. An equal list is a no-op; otherwise `seq` advances and,
|
|
126
|
+
* when `broadcast` is set, every active session hears it. `broadcast: false` is the first load
|
|
127
|
+
* behind a `list` RPC: the answer carries the new `seq`, nobody else needs it.
|
|
128
|
+
*/
|
|
129
|
+
publish(agentId, list, broadcast) {
|
|
130
|
+
const entry = this.entry(agentId);
|
|
131
|
+
entry.loaded = true;
|
|
132
|
+
if (isDeepStrictEqual(entry.list, list))
|
|
133
|
+
return;
|
|
134
|
+
entry.list = list;
|
|
135
|
+
entry.seq += 1;
|
|
136
|
+
if (!broadcast)
|
|
137
|
+
return;
|
|
138
|
+
this.broadcastFn(this.getActiveSessions(), {
|
|
139
|
+
type: "session",
|
|
140
|
+
message: { type: "agent_todos_update", snapshot: this.snapshotOf(agentId) },
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
snapshotOf(agentId) {
|
|
144
|
+
const entry = this.entries.get(agentId);
|
|
145
|
+
const seq = entry?.seq ?? 0;
|
|
146
|
+
const list = entry?.list ?? EMPTY;
|
|
147
|
+
return {
|
|
148
|
+
agentId,
|
|
149
|
+
seq,
|
|
150
|
+
tasks: list.tasks,
|
|
151
|
+
...(list.truncated ? { truncated: true } : {}),
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=agent-todos-service.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type AgentTodo } from "@av-pi-studio/protocol";
|
|
2
|
+
import type { AgentTodoList } from "../provider-contract.js";
|
|
3
|
+
/**
|
|
4
|
+
* Sort by id (stable: duplicate ids keep their input order), keep the first
|
|
5
|
+
* `AGENT_TODOS_MAX_TASKS` and cap every text field and `blockedBy`. Over-long values are truncated
|
|
6
|
+
* with `…`, never rejected. The input is not mutated; unknown fields are dropped.
|
|
7
|
+
*/
|
|
8
|
+
export declare function capAgentTodos(tasks: readonly AgentTodo[]): AgentTodoList;
|
|
9
|
+
//# sourceMappingURL=todo-limits.d.ts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { AGENT_TODO_MAX_ACTIVE_FORM_CHARS, AGENT_TODO_MAX_BLOCKED_BY, AGENT_TODO_MAX_DESCRIPTION_CHARS, AGENT_TODO_MAX_OWNER_CHARS, AGENT_TODO_MAX_SUBJECT_CHARS, AGENT_TODOS_MAX_TASKS, } from "@av-pi-studio/protocol";
|
|
2
|
+
/**
|
|
3
|
+
* Provider-neutral limits for an agent's todo list (features/agent-todos.md § Limits). Every
|
|
4
|
+
* provider that reports todos (the Pi adapter, the mock) runs its tasks through here so the wire
|
|
5
|
+
* never carries more than the protocol's documented caps, whichever producer made them.
|
|
6
|
+
*/
|
|
7
|
+
const ELLIPSIS = "…";
|
|
8
|
+
/** Truncate to at most `max` UTF-16 units, ending in `…`, without splitting a surrogate pair. */
|
|
9
|
+
function capText(value, max) {
|
|
10
|
+
if (value.length <= max)
|
|
11
|
+
return value;
|
|
12
|
+
let end = max - 1;
|
|
13
|
+
const last = value.charCodeAt(end - 1);
|
|
14
|
+
if (last >= 0xd800 && last <= 0xdbff)
|
|
15
|
+
end -= 1;
|
|
16
|
+
return value.slice(0, end) + ELLIPSIS;
|
|
17
|
+
}
|
|
18
|
+
function capTask(task) {
|
|
19
|
+
const capped = {
|
|
20
|
+
id: task.id,
|
|
21
|
+
subject: capText(task.subject, AGENT_TODO_MAX_SUBJECT_CHARS),
|
|
22
|
+
status: task.status,
|
|
23
|
+
};
|
|
24
|
+
if (task.activeForm !== undefined) {
|
|
25
|
+
capped.activeForm = capText(task.activeForm, AGENT_TODO_MAX_ACTIVE_FORM_CHARS);
|
|
26
|
+
}
|
|
27
|
+
if (task.description !== undefined) {
|
|
28
|
+
capped.description = capText(task.description, AGENT_TODO_MAX_DESCRIPTION_CHARS);
|
|
29
|
+
}
|
|
30
|
+
if (task.owner !== undefined)
|
|
31
|
+
capped.owner = capText(task.owner, AGENT_TODO_MAX_OWNER_CHARS);
|
|
32
|
+
if (task.blockedBy !== undefined) {
|
|
33
|
+
capped.blockedBy = task.blockedBy.slice(0, AGENT_TODO_MAX_BLOCKED_BY);
|
|
34
|
+
}
|
|
35
|
+
return capped;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Sort by id (stable: duplicate ids keep their input order), keep the first
|
|
39
|
+
* `AGENT_TODOS_MAX_TASKS` and cap every text field and `blockedBy`. Over-long values are truncated
|
|
40
|
+
* with `…`, never rejected. The input is not mutated; unknown fields are dropped.
|
|
41
|
+
*/
|
|
42
|
+
export function capAgentTodos(tasks) {
|
|
43
|
+
const sorted = tasks.toSorted((a, b) => a.id - b.id);
|
|
44
|
+
const truncated = sorted.length > AGENT_TODOS_MAX_TASKS;
|
|
45
|
+
return {
|
|
46
|
+
tasks: (truncated ? sorted.slice(0, AGENT_TODOS_MAX_TASKS) : sorted).map(capTask),
|
|
47
|
+
truncated,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=todo-limits.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgentCapabilityFlags, AgentSessionConfig, AgentStreamEvent, ImageAttachment } from "@av-pi-studio/protocol";
|
|
1
|
+
import type { AgentCapabilityFlags, AgentSessionConfig, AgentStreamEvent, AgentTodo, ImageAttachment } from "@av-pi-studio/protocol";
|
|
2
2
|
import type { AgentFeature } from "../persistence/entity-schemas.js";
|
|
3
3
|
import type { TimelineRow } from "./timeline-store.js";
|
|
4
4
|
/**
|
|
@@ -126,6 +126,15 @@ export interface PendingPermission {
|
|
|
126
126
|
toolName?: string;
|
|
127
127
|
detail?: unknown;
|
|
128
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* One agent's todo list as a provider reports it: already sorted by id and capped to the protocol
|
|
131
|
+
* limits (`capAgentTodos`), so `truncated` has to travel with the tasks. The service adds the
|
|
132
|
+
* agent id and `seq` to make the wire `AgentTodosSnapshot`.
|
|
133
|
+
*/
|
|
134
|
+
export interface AgentTodoList {
|
|
135
|
+
tasks: AgentTodo[];
|
|
136
|
+
truncated: boolean;
|
|
137
|
+
}
|
|
129
138
|
/**
|
|
130
139
|
* A provider UI request translated onto the generic channel (features/extension-ui-rpc.md § Provider
|
|
131
140
|
* contract extension). All Pi-specific knowledge (which methods block, surface-key namespacing,
|
|
@@ -264,6 +273,14 @@ export interface AgentSession {
|
|
|
264
273
|
onUiRequest?(cb: (req: ProviderUiRequest) => void): Unsubscribe;
|
|
265
274
|
/** Answer a dialog by its provider-scoped `requestId` (never the daemon's minted wire id). */
|
|
266
275
|
respondToUi?(providerRequestId: string, response: ProviderUiResponse): void;
|
|
276
|
+
/** Subscribe to live snapshots of the agent's whole todo list (last-value-wins). */
|
|
277
|
+
onTodos?(cb: (list: AgentTodoList) => void): Unsubscribe;
|
|
278
|
+
/**
|
|
279
|
+
* Re-derive the list from the session's CURRENT native session file (re-read each call, so it
|
|
280
|
+
* follows a fork/new_session rebind). Throws on an unreadable file so the caller can log it with
|
|
281
|
+
* the agent id; a missing file is an empty list.
|
|
282
|
+
*/
|
|
283
|
+
readTodos?(): AgentTodoList;
|
|
267
284
|
}
|
|
268
285
|
/** A provider client: creates/resumes sessions and exposes discovery. */
|
|
269
286
|
export interface AgentClient {
|
|
@@ -311,5 +328,11 @@ export interface AgentClient {
|
|
|
311
328
|
* (`session-hydration.ts`). Providers without durable native history omit this.
|
|
312
329
|
*/
|
|
313
330
|
hydrateTimeline?(handle: PersistenceHandle): TimelineRow[];
|
|
331
|
+
/**
|
|
332
|
+
* Process-less counterpart of `AgentSession.readTodos`: derive the list from a provider-native
|
|
333
|
+
* resume handle without spawning anything (the `hydrateTimeline` precedent), for a record that
|
|
334
|
+
* has no live session after a daemon restart. Throws on an unreadable file.
|
|
335
|
+
*/
|
|
336
|
+
readTodos?(handle: PersistenceHandle): AgentTodoList;
|
|
314
337
|
}
|
|
315
338
|
//# sourceMappingURL=provider-contract.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AgentCapabilityFlags, AgentSessionConfig, AgentStreamEvent } from "@av-pi-studio/protocol";
|
|
2
|
-
import type { AgentClient, AgentCommandDefinition, AgentCompactResult, AgentModeDefinition, AgentModelDefinition, AgentSession, CreateSessionOptions, LaunchContext, PendingPermission, PersistenceHandle, ProviderRuntimeInfo, ProviderUiRequest, ProviderUiResponse, Unsubscribe } from "../../provider-contract.js";
|
|
1
|
+
import type { AgentCapabilityFlags, AgentSessionConfig, AgentStreamEvent, AgentTodo } from "@av-pi-studio/protocol";
|
|
2
|
+
import type { AgentClient, AgentCommandDefinition, AgentCompactResult, AgentModeDefinition, AgentModelDefinition, AgentSession, AgentTodoList, CreateSessionOptions, LaunchContext, PendingPermission, PersistenceHandle, ProviderRuntimeInfo, ProviderUiRequest, ProviderUiResponse, Unsubscribe } from "../../provider-contract.js";
|
|
3
3
|
/**
|
|
4
4
|
* In-process `mock` provider (features/agent-providers.md § Provider entry — dev/test only). It
|
|
5
5
|
* implements the `AgentClient`/`AgentSession` contracts in memory and emits a scripted turn. Never
|
|
@@ -31,6 +31,7 @@ export declare class MockAgentSession implements AgentSession {
|
|
|
31
31
|
supportsRewindBoth: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
32
32
|
supportsSteering: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
33
33
|
supportsExtensionUi: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
34
|
+
supportsTodos: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
34
35
|
}, import("zod").ZodTypeAny, "passthrough">;
|
|
35
36
|
private readonly subscribers;
|
|
36
37
|
private readonly history;
|
|
@@ -47,6 +48,8 @@ export declare class MockAgentSession implements AgentSession {
|
|
|
47
48
|
response: ProviderUiResponse;
|
|
48
49
|
}[];
|
|
49
50
|
private readonly pendingScriptedResponses;
|
|
51
|
+
private readonly todoSubscribers;
|
|
52
|
+
private currentTodos;
|
|
50
53
|
constructor(config: AgentSessionConfig, options?: MockSessionOptions);
|
|
51
54
|
private emit;
|
|
52
55
|
subscribe(cb: (event: AgentStreamEvent) => void): Unsubscribe;
|
|
@@ -59,6 +62,19 @@ export declare class MockAgentSession implements AgentSession {
|
|
|
59
62
|
* turn id, exactly like the normal path — the dialog(s) and the eventual echo/`turn_completed`
|
|
60
63
|
* happen asynchronously as `runUiScript` progresses. */
|
|
61
64
|
private startUiScriptTurn;
|
|
65
|
+
/** `#todo ...` prompt (sprint-079/task-005): run a recipe through `emitTodos`, then end the turn
|
|
66
|
+
* with a short assistant text confirming what was emitted (or, for `help`, the recipe list)
|
|
67
|
+
* instead of the normal echoed turn. Mirrors `startUiScriptTurn`'s shape: resolves immediately
|
|
68
|
+
* with the turn id, the emission and the echo happen after `turnDelayMs`. */
|
|
69
|
+
private startTodoScriptTurn;
|
|
70
|
+
/** `#tool ...` prompt (sprint-058/task-004): after `turnDelayMs`, emit the scripted tool-call
|
|
71
|
+
* lifecycle (start, 3 partials, end) synchronously — no timers between tool events — then the
|
|
72
|
+
* usual echo and `turn_completed`. `help` emits the recipe list and no tool events. */
|
|
73
|
+
private startToolScriptTurn;
|
|
74
|
+
/** Builds the raw (uncapped) task list for every recipe except `help`, which `startTodoScriptTurn`
|
|
75
|
+
* handles itself. `advance` reads `currentTodos` — the only recipe whose result depends on
|
|
76
|
+
* session state — everything else is a pure `todo-script.ts` builder. */
|
|
77
|
+
private buildTodoRecipe;
|
|
62
78
|
private runUiScript;
|
|
63
79
|
/** Raises one scripted step. A dialog (`expectsResponse: true`) returns a promise that resolves
|
|
64
80
|
* once `respondToUi` is called for its (mock-minted) `requestId`. A transient
|
|
@@ -90,6 +106,12 @@ export declare class MockAgentSession implements AgentSession {
|
|
|
90
106
|
* field the caller omits. Returns the request actually emitted (its `requestId` in particular),
|
|
91
107
|
* so a test can answer it via `respondToUi` or assert against it directly. */
|
|
92
108
|
emitUiRequest(partial?: Partial<ProviderUiRequest>): ProviderUiRequest;
|
|
109
|
+
onTodos(cb: (list: AgentTodoList) => void): Unsubscribe;
|
|
110
|
+
readTodos(): AgentTodoList;
|
|
111
|
+
/** Test/dev hook (sprint-079/task-005): cap `tasks` through `capAgentTodos`, store it as the
|
|
112
|
+
* session's current list, publish it to `onTodos` subscribers and the process-less
|
|
113
|
+
* `mockTodosByHandle` map, and return what was actually emitted. */
|
|
114
|
+
emitTodos(tasks: readonly AgentTodo[]): AgentTodoList;
|
|
93
115
|
describePersistence(): PersistenceHandle | null;
|
|
94
116
|
private sessionName;
|
|
95
117
|
getSessionStats(): Promise<{
|
|
@@ -147,6 +169,7 @@ export declare class MockAgentClient implements AgentClient {
|
|
|
147
169
|
supportsRewindBoth: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
148
170
|
supportsSteering: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
149
171
|
supportsExtensionUi: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
172
|
+
supportsTodos: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
150
173
|
}, import("zod").ZodTypeAny, "passthrough">;
|
|
151
174
|
constructor(options?: MockSessionOptions);
|
|
152
175
|
createSession(config: AgentSessionConfig, _launchContext?: LaunchContext, _options?: CreateSessionOptions): Promise<AgentSession>;
|
|
@@ -159,6 +182,12 @@ export declare class MockAgentClient implements AgentClient {
|
|
|
159
182
|
thinkingLevel?: string;
|
|
160
183
|
} | null>;
|
|
161
184
|
isAvailable(): boolean;
|
|
185
|
+
/** Process-less counterpart of `MockAgentSession.readTodos` (features/agent-todos.md § Provider
|
|
186
|
+
* contract): the last list `emitTodos` published for this handle's session, from the
|
|
187
|
+
* module-level `mockTodosByHandle` map (keyed by `sessionId`) — no session is spawned. An
|
|
188
|
+
* unknown handle (never emitted, or no `sessionId`) answers an empty list, matching the
|
|
189
|
+
* "missing file is an empty list" convention the real adapter uses. */
|
|
190
|
+
readTodos(handle: PersistenceHandle): AgentTodoList;
|
|
162
191
|
importSession(args: {
|
|
163
192
|
providerHandleId: string;
|
|
164
193
|
cwd: string;
|