@av-pi-studio/server 0.0.113 → 0.0.114
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-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 +27 -2
- package/dist/agent/providers/mock/mock-provider.js +100 -0
- 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/pi/agent.d.ts +5 -1
- package/dist/agent/providers/pi/agent.js +36 -1
- 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/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
|
@@ -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,15 @@ 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
|
+
/** Builds the raw (uncapped) task list for every recipe except `help`, which `startTodoScriptTurn`
|
|
71
|
+
* handles itself. `advance` reads `currentTodos` — the only recipe whose result depends on
|
|
72
|
+
* session state — everything else is a pure `todo-script.ts` builder. */
|
|
73
|
+
private buildTodoRecipe;
|
|
62
74
|
private runUiScript;
|
|
63
75
|
/** Raises one scripted step. A dialog (`expectsResponse: true`) returns a promise that resolves
|
|
64
76
|
* once `respondToUi` is called for its (mock-minted) `requestId`. A transient
|
|
@@ -90,6 +102,12 @@ export declare class MockAgentSession implements AgentSession {
|
|
|
90
102
|
* field the caller omits. Returns the request actually emitted (its `requestId` in particular),
|
|
91
103
|
* so a test can answer it via `respondToUi` or assert against it directly. */
|
|
92
104
|
emitUiRequest(partial?: Partial<ProviderUiRequest>): ProviderUiRequest;
|
|
105
|
+
onTodos(cb: (list: AgentTodoList) => void): Unsubscribe;
|
|
106
|
+
readTodos(): AgentTodoList;
|
|
107
|
+
/** Test/dev hook (sprint-079/task-005): cap `tasks` through `capAgentTodos`, store it as the
|
|
108
|
+
* session's current list, publish it to `onTodos` subscribers and the process-less
|
|
109
|
+
* `mockTodosByHandle` map, and return what was actually emitted. */
|
|
110
|
+
emitTodos(tasks: readonly AgentTodo[]): AgentTodoList;
|
|
93
111
|
describePersistence(): PersistenceHandle | null;
|
|
94
112
|
private sessionName;
|
|
95
113
|
getSessionStats(): Promise<{
|
|
@@ -147,6 +165,7 @@ export declare class MockAgentClient implements AgentClient {
|
|
|
147
165
|
supportsRewindBoth: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
148
166
|
supportsSteering: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
149
167
|
supportsExtensionUi: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
168
|
+
supportsTodos: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
150
169
|
}, import("zod").ZodTypeAny, "passthrough">;
|
|
151
170
|
constructor(options?: MockSessionOptions);
|
|
152
171
|
createSession(config: AgentSessionConfig, _launchContext?: LaunchContext, _options?: CreateSessionOptions): Promise<AgentSession>;
|
|
@@ -159,6 +178,12 @@ export declare class MockAgentClient implements AgentClient {
|
|
|
159
178
|
thinkingLevel?: string;
|
|
160
179
|
} | null>;
|
|
161
180
|
isAvailable(): boolean;
|
|
181
|
+
/** Process-less counterpart of `MockAgentSession.readTodos` (features/agent-todos.md § Provider
|
|
182
|
+
* contract): the last list `emitTodos` published for this handle's session, from the
|
|
183
|
+
* module-level `mockTodosByHandle` map (keyed by `sessionId`) — no session is spawned. An
|
|
184
|
+
* unknown handle (never emitted, or no `sessionId`) answers an empty list, matching the
|
|
185
|
+
* "missing file is an empty list" convention the real adapter uses. */
|
|
186
|
+
readTodos(handle: PersistenceHandle): AgentTodoList;
|
|
162
187
|
importSession(args: {
|
|
163
188
|
providerHandleId: string;
|
|
164
189
|
cwd: string;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { capAgentTodos } from "../../agent-todos/todo-limits.js";
|
|
3
|
+
import { advanceTodos, blockedTodos, clearTodos, doneTodos, getTodoScriptHelpText, hugeTodos, literalTodos, manyTodos, parseTodoScript, planTodos, } from "./todo-script.js";
|
|
2
4
|
import { getUiScriptHelpText, parseUiScript } from "./ui-script.js";
|
|
3
5
|
/**
|
|
4
6
|
* In-process `mock` provider (features/agent-providers.md § Provider entry — dev/test only). It
|
|
@@ -14,7 +16,16 @@ export const MOCK_CAPABILITIES = {
|
|
|
14
16
|
supportsToolInvocations: true,
|
|
15
17
|
supportsSteering: true,
|
|
16
18
|
supportsExtensionUi: true,
|
|
19
|
+
supportsTodos: true,
|
|
17
20
|
};
|
|
21
|
+
/** Keyed by `PersistenceHandle.sessionId` (the mock session's own `id`, stable for its whole
|
|
22
|
+
* lifetime and reused verbatim by `describePersistence`/`importSession`). Lets
|
|
23
|
+
* `MockAgentClient.readTodos(handle)` answer the process-less path in-process, mirroring how a
|
|
24
|
+
* real daemon restart would re-read a provider-native file. Entries are replaced on every
|
|
25
|
+
* `emitTodos` call, never removed on `close()` — a process-less read happens AFTER the session
|
|
26
|
+
* that produced the data has closed, so clearing on close would defeat the whole point of this
|
|
27
|
+
* map. Bounded by distinct mock session ids created in the process. */
|
|
28
|
+
const mockTodosByHandle = new Map();
|
|
18
29
|
const MOCK_MODES = [
|
|
19
30
|
{ id: "default", label: "Default" },
|
|
20
31
|
{ id: "plan", label: "Plan" },
|
|
@@ -53,6 +64,11 @@ export class MockAgentSession {
|
|
|
53
64
|
// instead of) its existing `uiResponses` recording used by direct `emitUiRequest`/`respondToUi`
|
|
54
65
|
// callers.
|
|
55
66
|
pendingScriptedResponses = new Map();
|
|
67
|
+
// Agent todos (sprint-079/task-005): no `pi` process exists to script this family either, so the
|
|
68
|
+
// mock provider exposes a scripted emitter (`emitTodos`) plus `#todo ...` prompt recipes
|
|
69
|
+
// (`todo-script.ts`), mirroring the `#ui` precedent above.
|
|
70
|
+
todoSubscribers = new Set();
|
|
71
|
+
currentTodos = { tasks: [], truncated: false };
|
|
56
72
|
constructor(config, options = {}) {
|
|
57
73
|
this.config = config;
|
|
58
74
|
this.turnDelayMs = options.turnDelayMs ?? 5;
|
|
@@ -75,6 +91,9 @@ export class MockAgentSession {
|
|
|
75
91
|
const script = parseUiScript(prompt);
|
|
76
92
|
if (script !== null)
|
|
77
93
|
return this.startUiScriptTurn(script);
|
|
94
|
+
const todoRecipe = parseTodoScript(prompt);
|
|
95
|
+
if (todoRecipe !== null)
|
|
96
|
+
return this.startTodoScriptTurn(todoRecipe);
|
|
78
97
|
const turnId = randomUUID();
|
|
79
98
|
this.activeTurn = turnId;
|
|
80
99
|
this.emit({ kind: "turn_started", turnId });
|
|
@@ -120,6 +139,54 @@ export class MockAgentSession {
|
|
|
120
139
|
void this.runUiScript(turnId, steps);
|
|
121
140
|
return Promise.resolve({ turnId });
|
|
122
141
|
}
|
|
142
|
+
/** `#todo ...` prompt (sprint-079/task-005): run a recipe through `emitTodos`, then end the turn
|
|
143
|
+
* with a short assistant text confirming what was emitted (or, for `help`, the recipe list)
|
|
144
|
+
* instead of the normal echoed turn. Mirrors `startUiScriptTurn`'s shape: resolves immediately
|
|
145
|
+
* with the turn id, the emission and the echo happen after `turnDelayMs`. */
|
|
146
|
+
startTodoScriptTurn(recipe) {
|
|
147
|
+
const turnId = randomUUID();
|
|
148
|
+
this.activeTurn = turnId;
|
|
149
|
+
this.emit({ kind: "turn_started", turnId });
|
|
150
|
+
setTimeout(() => {
|
|
151
|
+
if (this.activeTurn !== turnId)
|
|
152
|
+
return;
|
|
153
|
+
let text;
|
|
154
|
+
if (recipe === "help") {
|
|
155
|
+
text = getTodoScriptHelpText();
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
const list = this.emitTodos(this.buildTodoRecipe(recipe));
|
|
159
|
+
text = `todo ${recipe}: ${list.tasks.length} task(s)${list.truncated ? " (truncated)" : ""}`;
|
|
160
|
+
}
|
|
161
|
+
this.emit({ kind: "assistant_message", messageId: randomUUID(), text, final: true });
|
|
162
|
+
this.emit({ kind: "turn_completed", turnId });
|
|
163
|
+
this.activeTurn = null;
|
|
164
|
+
}, this.turnDelayMs);
|
|
165
|
+
return Promise.resolve({ turnId });
|
|
166
|
+
}
|
|
167
|
+
/** Builds the raw (uncapped) task list for every recipe except `help`, which `startTodoScriptTurn`
|
|
168
|
+
* handles itself. `advance` reads `currentTodos` — the only recipe whose result depends on
|
|
169
|
+
* session state — everything else is a pure `todo-script.ts` builder. */
|
|
170
|
+
buildTodoRecipe(recipe) {
|
|
171
|
+
switch (recipe) {
|
|
172
|
+
case "plan":
|
|
173
|
+
return planTodos();
|
|
174
|
+
case "advance":
|
|
175
|
+
return advanceTodos(this.currentTodos.tasks);
|
|
176
|
+
case "done":
|
|
177
|
+
return doneTodos();
|
|
178
|
+
case "many":
|
|
179
|
+
return manyTodos();
|
|
180
|
+
case "blocked":
|
|
181
|
+
return blockedTodos();
|
|
182
|
+
case "literal":
|
|
183
|
+
return literalTodos();
|
|
184
|
+
case "huge":
|
|
185
|
+
return hugeTodos();
|
|
186
|
+
case "clear":
|
|
187
|
+
return clearTodos();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
123
190
|
async runUiScript(turnId, steps) {
|
|
124
191
|
const responses = await Promise.all(steps.map((step) => this.raiseScriptedDialog(step)));
|
|
125
192
|
if (this.activeTurn !== turnId)
|
|
@@ -273,6 +340,27 @@ export class MockAgentSession {
|
|
|
273
340
|
cb(req);
|
|
274
341
|
return req;
|
|
275
342
|
}
|
|
343
|
+
// Agent todos (features/agent-todos.md § Provider contract): `supportsTodos` members. The mock
|
|
344
|
+
// caps through `capAgentTodos` directly — never through `providers/pi/todos.ts`, which is a
|
|
345
|
+
// different provider's recognition logic for a different wire shape.
|
|
346
|
+
onTodos(cb) {
|
|
347
|
+
this.todoSubscribers.add(cb);
|
|
348
|
+
return () => this.todoSubscribers.delete(cb);
|
|
349
|
+
}
|
|
350
|
+
readTodos() {
|
|
351
|
+
return this.currentTodos;
|
|
352
|
+
}
|
|
353
|
+
/** Test/dev hook (sprint-079/task-005): cap `tasks` through `capAgentTodos`, store it as the
|
|
354
|
+
* session's current list, publish it to `onTodos` subscribers and the process-less
|
|
355
|
+
* `mockTodosByHandle` map, and return what was actually emitted. */
|
|
356
|
+
emitTodos(tasks) {
|
|
357
|
+
const capped = capAgentTodos(tasks);
|
|
358
|
+
this.currentTodos = capped;
|
|
359
|
+
mockTodosByHandle.set(this.id, capped);
|
|
360
|
+
for (const cb of this.todoSubscribers)
|
|
361
|
+
cb(capped);
|
|
362
|
+
return capped;
|
|
363
|
+
}
|
|
276
364
|
describePersistence() {
|
|
277
365
|
return { provider: this.provider, sessionId: this.id, nativeHandle: `mock:${this.id}` };
|
|
278
366
|
}
|
|
@@ -414,6 +502,18 @@ export class MockAgentClient {
|
|
|
414
502
|
isAvailable() {
|
|
415
503
|
return true;
|
|
416
504
|
}
|
|
505
|
+
/** Process-less counterpart of `MockAgentSession.readTodos` (features/agent-todos.md § Provider
|
|
506
|
+
* contract): the last list `emitTodos` published for this handle's session, from the
|
|
507
|
+
* module-level `mockTodosByHandle` map (keyed by `sessionId`) — no session is spawned. An
|
|
508
|
+
* unknown handle (never emitted, or no `sessionId`) answers an empty list, matching the
|
|
509
|
+
* "missing file is an empty list" convention the real adapter uses. */
|
|
510
|
+
readTodos(handle) {
|
|
511
|
+
const key = handle.sessionId;
|
|
512
|
+
return ((key !== undefined ? mockTodosByHandle.get(key) : undefined) ?? {
|
|
513
|
+
tasks: [],
|
|
514
|
+
truncated: false,
|
|
515
|
+
});
|
|
516
|
+
}
|
|
417
517
|
async importSession(args) {
|
|
418
518
|
const session = new MockAgentSession({ provider: "mock", cwd: args.cwd }, this.options);
|
|
419
519
|
return {
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { AgentTodo } from "@av-pi-studio/protocol";
|
|
2
|
+
/**
|
|
3
|
+
* Scripted todo-list trigger for the mock provider (sprint-079/task-005). Lets a browser-connected
|
|
4
|
+
* client drive every todo-panel state the web-client must render by typing a `#todo ...` prompt, so
|
|
5
|
+
* the UI work in sprint-080 has reachable triggers for every state — grouped completed tasks,
|
|
6
|
+
* blocked tasks, truncation, literal markdown, clearing — with no Pi and no model
|
|
7
|
+
* (features/agent-todos.md § Provider contract, § Acceptance A11). Mirrors s068/t001's `#ui`
|
|
8
|
+
* recipes (`ui-script.ts`): a pure, cheap-prefix-checked parser, a `help` recipe echoed verbatim by
|
|
9
|
+
* `#todo help`, and recognised-but-unknown input falling back to help rather than an ordinary echo.
|
|
10
|
+
*
|
|
11
|
+
* `advance` is the one recipe whose RESULT depends on session state (the current list), so this
|
|
12
|
+
* module keeps it pure too: `advanceTodos(current)` takes the session's current list as input and
|
|
13
|
+
* returns the next one. `MockAgentSession` is the only caller that knows what "current" means.
|
|
14
|
+
*
|
|
15
|
+
* Grammar (also echoed verbatim by `#todo help`):
|
|
16
|
+
*
|
|
17
|
+
* #todo plan 4 tasks, the first in_progress with an activeForm
|
|
18
|
+
* #todo advance completes the current task, starts the next (relative to the session's list)
|
|
19
|
+
* #todo done all tasks completed
|
|
20
|
+
* #todo many 12 tasks, 7 completed (exercises grouping and scroll)
|
|
21
|
+
* #todo blocked blockedBy including a dangling id, plus description/owner
|
|
22
|
+
* #todo literal a subject containing literal markdown/HTML, rendered verbatim
|
|
23
|
+
* #todo huge 250 tasks with over-cap fields (exercises the cap path)
|
|
24
|
+
* #todo clear empty list
|
|
25
|
+
* #todo help this list
|
|
26
|
+
*/
|
|
27
|
+
export declare const TODO_SCRIPT_RECIPES: readonly ["plan", "advance", "done", "many", "blocked", "literal", "huge", "clear", "help"];
|
|
28
|
+
export type TodoScriptRecipe = (typeof TODO_SCRIPT_RECIPES)[number];
|
|
29
|
+
export declare function getTodoScriptHelpText(): string;
|
|
30
|
+
/** Parses a `#todo ...` prompt into the recipe it names. Returns `null` when `prompt` is not a
|
|
31
|
+
* recognised script — the overwhelmingly common case, kept a cheap prefix check. A `#todo` prompt
|
|
32
|
+
* whose recipe is empty or unrecognised still names a script (so the caller must show help, not
|
|
33
|
+
* run an ordinary echoed turn) — it returns `"help"`, never `null`, for those. */
|
|
34
|
+
export declare function parseTodoScript(prompt: string): TodoScriptRecipe | null;
|
|
35
|
+
/** `#todo plan`: 4 tasks, the first `in_progress` with an `activeForm`. */
|
|
36
|
+
export declare function planTodos(): AgentTodo[];
|
|
37
|
+
/** `#todo advance`: completes the session's current `in_progress` task (if any) and starts the
|
|
38
|
+
* next `pending` one (if any), relative to `current` — never reads global state. A list with no
|
|
39
|
+
* `in_progress` and no `pending` task (e.g. `done`, or the empty list before `plan`) is returned
|
|
40
|
+
* unchanged. */
|
|
41
|
+
export declare function advanceTodos(current: readonly AgentTodo[]): AgentTodo[];
|
|
42
|
+
/** `#todo done`: all tasks completed. */
|
|
43
|
+
export declare function doneTodos(): AgentTodo[];
|
|
44
|
+
/** `#todo many`: 12 tasks, 7 completed — exercises grouping and scroll. */
|
|
45
|
+
export declare function manyTodos(): AgentTodo[];
|
|
46
|
+
/** `#todo blocked`: `blockedBy` (including a dangling id), plus `description`/`owner`. */
|
|
47
|
+
export declare function blockedTodos(): AgentTodo[];
|
|
48
|
+
/** `#todo literal`: subject containing literal markdown/HTML, rendered verbatim (never parsed). */
|
|
49
|
+
export declare function literalTodos(): AgentTodo[];
|
|
50
|
+
/** `#todo huge`: 250 tasks (over `AGENT_TODOS_MAX_TASKS`) with over-cap text fields and an
|
|
51
|
+
* over-cap `blockedBy`, so `capAgentTodos` truncates the list AND every field. */
|
|
52
|
+
export declare function hugeTodos(): AgentTodo[];
|
|
53
|
+
/** `#todo clear`: empty list. */
|
|
54
|
+
export declare function clearTodos(): AgentTodo[];
|
|
55
|
+
//# sourceMappingURL=todo-script.d.ts.map
|