@peer-agent/protocol 0.1.0-beta.2 → 0.1.0-beta.4
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/delegation.d.ts +47 -5
- package/dist/delegation.js +113 -3
- package/dist/goal.d.ts +6 -0
- package/dist/memory.d.ts +98 -1
- package/dist/memory.js +2 -0
- package/dist/model-routing.d.ts +29 -0
- package/dist/model-routing.js +24 -0
- package/dist/objectives.d.ts +109 -9
- package/dist/objectives.js +4 -13
- package/dist/project.d.ts +31 -2
- package/dist/project.js +14 -10
- package/package.json +1 -1
package/dist/delegation.d.ts
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { ModelSelectionSnapshot } from './model-routing.ts';
|
|
6
6
|
import { type GoalPlanProjectionSnapshot, type TaskOverviewItem } from './task-overview.ts';
|
|
7
|
-
export type WorkSessionStatus = 'queued' | 'starting' | 'running' | 'waiting_user' | 'verifying' | 'result_ready' | 'accepted' | 'failed' | 'cancelled' | 'superseded';
|
|
7
|
+
export type WorkSessionStatus = 'paused' | 'queued' | 'starting' | 'running' | 'waiting_user' | 'verifying' | 'result_ready' | 'accepted' | 'failed' | 'cancelled' | 'superseded';
|
|
8
|
+
export declare const WORK_SESSION_STATUSES: readonly ["paused", "queued", "starting", "running", "waiting_user", "verifying", "result_ready", "accepted", "failed", "cancelled", "superseded"];
|
|
8
9
|
export type InputSurface = 'desktop' | 'quick_chat' | 'tui' | 'remote';
|
|
9
10
|
export interface DelegationOrigin {
|
|
10
11
|
readonly anchorMessageId: string;
|
|
@@ -12,11 +13,28 @@ export interface DelegationOrigin {
|
|
|
12
13
|
readonly surface: InputSurface;
|
|
13
14
|
readonly memorySnapshotId: string;
|
|
14
15
|
readonly objectiveId?: string;
|
|
16
|
+
readonly objectiveActionId?: string;
|
|
17
|
+
readonly priority?: 'high' | 'normal' | 'low';
|
|
18
|
+
readonly isolation?: 'auto' | 'none' | 'worktree';
|
|
19
|
+
readonly isolationBlock?: 'disk_space' | 'isolation_failed' | null;
|
|
20
|
+
readonly isolationRetainedAt?: string;
|
|
21
|
+
readonly supersededBy?: string;
|
|
22
|
+
readonly supersededAt?: string;
|
|
23
|
+
readonly lastResumeAnchorMessageId?: string;
|
|
24
|
+
readonly handoffAuthorizedAt?: string;
|
|
25
|
+
readonly handoffDeferredAt?: string;
|
|
15
26
|
readonly modelSelection: ModelSelectionSnapshot;
|
|
16
27
|
readonly parentSessionId?: string;
|
|
17
28
|
readonly depth: number;
|
|
18
29
|
}
|
|
19
|
-
export interface
|
|
30
|
+
export interface SessionQueueFacts {
|
|
31
|
+
readonly queuedBehind?: readonly {
|
|
32
|
+
readonly sessionId: string;
|
|
33
|
+
readonly title: string;
|
|
34
|
+
}[];
|
|
35
|
+
readonly queueReason?: 'dependencies' | 'dependency_missing' | 'dependency_failed' | 'read_slot' | 'write_slot' | 'disk_space' | 'isolation_failed' | null;
|
|
36
|
+
}
|
|
37
|
+
export interface WorkSessionConversationMeta extends SessionQueueFacts {
|
|
20
38
|
readonly sessionId?: string;
|
|
21
39
|
readonly conversationId?: string;
|
|
22
40
|
readonly workspaceId: string;
|
|
@@ -26,9 +44,9 @@ export interface WorkSessionConversationMeta {
|
|
|
26
44
|
readonly acceptance?: 'auto' | 'confirm';
|
|
27
45
|
readonly accepted?: boolean;
|
|
28
46
|
readonly verifying?: boolean;
|
|
29
|
-
readonly phase?: 'starting' | 'verifying';
|
|
47
|
+
readonly phase?: 'starting' | 'verifying' | 'paused';
|
|
30
48
|
}
|
|
31
|
-
export interface WorkSession {
|
|
49
|
+
export interface WorkSession extends SessionQueueFacts {
|
|
32
50
|
readonly sessionId: string;
|
|
33
51
|
readonly workspaceId: string;
|
|
34
52
|
readonly title: string;
|
|
@@ -62,18 +80,30 @@ export type JsonValue = null | string | number | boolean | readonly JsonValue[]
|
|
|
62
80
|
export interface DelegationEvent {
|
|
63
81
|
readonly eventId: string;
|
|
64
82
|
readonly kind: DelegationEventKind;
|
|
65
|
-
readonly sessionId
|
|
83
|
+
readonly sessionId?: string;
|
|
84
|
+
readonly workspaceId?: string;
|
|
85
|
+
readonly objectiveId?: string;
|
|
86
|
+
readonly watchId?: string;
|
|
87
|
+
readonly executionKey?: string;
|
|
66
88
|
readonly at: string;
|
|
67
89
|
readonly payload: JsonValue;
|
|
68
90
|
}
|
|
69
91
|
export interface AgentReplyMeta {
|
|
92
|
+
/** Host generated factual delivery keys; model input cannot set them. */
|
|
93
|
+
readonly reportFactKeys?: readonly string[];
|
|
70
94
|
readonly replyTo: readonly string[];
|
|
71
95
|
readonly sources: readonly string[];
|
|
72
96
|
readonly verdictRef?: string;
|
|
97
|
+
/** Host snapshot; accepted only when resultAcceptance has been persisted. */
|
|
98
|
+
readonly sessionStates?: readonly ReplySessionState[];
|
|
73
99
|
readonly memoryUsed: readonly string[];
|
|
74
100
|
readonly memoryLearned: readonly string[];
|
|
75
101
|
readonly surfacing: 'interrupt' | 'message' | 'digest' | 'silent';
|
|
76
102
|
}
|
|
103
|
+
export interface ReplySessionState {
|
|
104
|
+
readonly sessionId: string;
|
|
105
|
+
readonly status: WorkSessionStatus;
|
|
106
|
+
}
|
|
77
107
|
export type MessageDisposition = {
|
|
78
108
|
readonly kind: 'answered';
|
|
79
109
|
readonly messageId: string;
|
|
@@ -224,6 +254,18 @@ export declare function createDelegationEvent(input: {
|
|
|
224
254
|
* A paused plan has no delegation status of its own; it is queued, and the visible conclusion stays paused.
|
|
225
255
|
*/
|
|
226
256
|
export declare function projectWorkSession(plan: GoalPlanProjectionSnapshot, conversationMeta: WorkSessionConversationMeta): WorkSession;
|
|
257
|
+
export interface DispositionToolCall {
|
|
258
|
+
readonly name?: string;
|
|
259
|
+
/** Arbitrary tool input. A disposition field here is ignored. */
|
|
260
|
+
readonly input?: Readonly<Record<string, unknown>> | null;
|
|
261
|
+
readonly result?: unknown;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Derive disposition events from one turn's tool calls.
|
|
265
|
+
* Answer is not an event: only post_reply, projected later from the assistant reply.
|
|
266
|
+
* A model-supplied disposition field is ignored.
|
|
267
|
+
*/
|
|
268
|
+
export declare function dispositionEventsFromToolCalls(anchorMessageId: string, toolCalls: readonly DispositionToolCall[]): DispositionEvent[];
|
|
227
269
|
/**
|
|
228
270
|
* Dispositions are a projection of anchor events plus replies.
|
|
229
271
|
* The assistant text answers the last user message in the turn unless replyTo says otherwise.
|
package/dist/delegation.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* The user-visible conclusion of a work session is projectGoalPlan's conclusion.
|
|
4
4
|
*/
|
|
5
5
|
import { projectGoalPlan, } from "./task-overview.js";
|
|
6
|
+
export const WORK_SESSION_STATUSES = ['paused', 'queued', 'starting', 'running', 'waiting_user', 'verifying',
|
|
7
|
+
'result_ready', 'accepted', 'failed', 'cancelled', 'superseded'];
|
|
6
8
|
function fnv1a(text) {
|
|
7
9
|
let hash = 0x811c9dc5;
|
|
8
10
|
for (let index = 0; index < text.length; index += 1) {
|
|
@@ -42,8 +44,6 @@ export function createDelegationEvent(input) {
|
|
|
42
44
|
};
|
|
43
45
|
}
|
|
44
46
|
function delegationStatus(snapshot, meta, projected) {
|
|
45
|
-
if (meta.supersededBy)
|
|
46
|
-
return 'superseded';
|
|
47
47
|
if (snapshot.status === 'failed')
|
|
48
48
|
return 'failed';
|
|
49
49
|
if (snapshot.status === 'cancelled')
|
|
@@ -55,9 +55,16 @@ function delegationStatus(snapshot, meta, projected) {
|
|
|
55
55
|
return 'result_ready';
|
|
56
56
|
return 'accepted';
|
|
57
57
|
}
|
|
58
|
+
if (meta.supersededBy)
|
|
59
|
+
return 'superseded';
|
|
60
|
+
if (meta.phase === 'paused')
|
|
61
|
+
return 'paused';
|
|
62
|
+
// 复核进行中盖过「需要你」。草稿、待批准、等回答的计划在独立复核时都显示 verifying。
|
|
63
|
+
if (meta.verifying || meta.phase === 'verifying')
|
|
64
|
+
return 'verifying';
|
|
58
65
|
if (projected.actionRight === 'needs_you')
|
|
59
66
|
return 'waiting_user';
|
|
60
|
-
if (snapshot.runnerStatus === 'exploring'
|
|
67
|
+
if (snapshot.runnerStatus === 'exploring')
|
|
61
68
|
return 'verifying';
|
|
62
69
|
if (meta.phase === 'starting')
|
|
63
70
|
return 'starting';
|
|
@@ -90,6 +97,8 @@ export function projectWorkSession(plan, conversationMeta) {
|
|
|
90
97
|
spawnedAt: conversationMeta.spawnedAt ?? plan.updatedAt ?? '',
|
|
91
98
|
...(conversationMeta.conversationId ? { conversationId: conversationMeta.conversationId } : {}),
|
|
92
99
|
origin: conversationMeta.origin,
|
|
100
|
+
...(conversationMeta.queuedBehind ? { queuedBehind: conversationMeta.queuedBehind.map(item => ({ ...item })) } : {}),
|
|
101
|
+
...(conversationMeta.queueReason ? { queueReason: conversationMeta.queueReason } : {}),
|
|
93
102
|
...(conversationMeta.supersededBy ? { supersededBy: conversationMeta.supersededBy } : {}),
|
|
94
103
|
};
|
|
95
104
|
}
|
|
@@ -132,6 +141,107 @@ function dispositionFor(message, event) {
|
|
|
132
141
|
return { kind: 'parallel', messageId: message.id, sessionIds: event.sessionIds ?? (sessionId ? [sessionId] : []) };
|
|
133
142
|
}
|
|
134
143
|
}
|
|
144
|
+
function toolRecord(value) {
|
|
145
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
146
|
+
return null;
|
|
147
|
+
return value;
|
|
148
|
+
}
|
|
149
|
+
function toolBody(result) {
|
|
150
|
+
const record = toolRecord(result);
|
|
151
|
+
if (!record)
|
|
152
|
+
return null;
|
|
153
|
+
const nested = toolRecord(record.output);
|
|
154
|
+
if (nested && typeof record.sessionId !== 'string' && (typeof nested.sessionId === 'string' || typeof nested.error === 'string' || nested.ok === false)) {
|
|
155
|
+
return nested;
|
|
156
|
+
}
|
|
157
|
+
return record;
|
|
158
|
+
}
|
|
159
|
+
function toolFailed(body) {
|
|
160
|
+
if (!body)
|
|
161
|
+
return true;
|
|
162
|
+
if (typeof body.error === 'string' && body.error.trim())
|
|
163
|
+
return true;
|
|
164
|
+
return body.ok === false;
|
|
165
|
+
}
|
|
166
|
+
function toolSessionId(body, fallback) {
|
|
167
|
+
if (body && typeof body.sessionId === 'string' && body.sessionId.trim())
|
|
168
|
+
return body.sessionId.trim();
|
|
169
|
+
return typeof fallback === 'string' ? fallback.trim() : '';
|
|
170
|
+
}
|
|
171
|
+
function toolQueued(body) {
|
|
172
|
+
return body.status === 'queued' || body.queued === true;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Derive disposition events from one turn's tool calls.
|
|
176
|
+
* Answer is not an event: only post_reply, projected later from the assistant reply.
|
|
177
|
+
* A model-supplied disposition field is ignored.
|
|
178
|
+
*/
|
|
179
|
+
export function dispositionEventsFromToolCalls(anchorMessageId, toolCalls) {
|
|
180
|
+
const anchor = anchorMessageId.trim();
|
|
181
|
+
if (!anchor)
|
|
182
|
+
return [];
|
|
183
|
+
const events = [];
|
|
184
|
+
for (const call of toolCalls) {
|
|
185
|
+
const name = call?.name;
|
|
186
|
+
const input = call?.input ?? null;
|
|
187
|
+
const body = toolBody(call?.result);
|
|
188
|
+
if (toolFailed(body))
|
|
189
|
+
continue;
|
|
190
|
+
if (name === 'message_session' && fieldText(input, 'intent') === 'amend') {
|
|
191
|
+
const sessionId = toolSessionId(body, fieldText(input, 'sessionId'));
|
|
192
|
+
if (!sessionId)
|
|
193
|
+
continue;
|
|
194
|
+
events.push({ kind: 'merge', anchorMessageId: anchor, sessionId });
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (name === 'cancel_session') {
|
|
198
|
+
const sessionId = toolSessionId(body, fieldText(input, 'sessionId'));
|
|
199
|
+
if (!sessionId)
|
|
200
|
+
continue;
|
|
201
|
+
events.push({
|
|
202
|
+
kind: 'stop',
|
|
203
|
+
anchorMessageId: anchor,
|
|
204
|
+
sessionId,
|
|
205
|
+
sessionIds: [sessionId],
|
|
206
|
+
reason: fieldText(input, 'reason'),
|
|
207
|
+
});
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
if (name !== 'spawn_session')
|
|
211
|
+
continue;
|
|
212
|
+
const sessionId = toolSessionId(body, '');
|
|
213
|
+
if (!sessionId || !body)
|
|
214
|
+
continue;
|
|
215
|
+
const supersedes = fieldText(input, 'supersedes');
|
|
216
|
+
if (supersedes) {
|
|
217
|
+
events.push({
|
|
218
|
+
kind: 'supersede',
|
|
219
|
+
anchorMessageId: anchor,
|
|
220
|
+
sessionId,
|
|
221
|
+
oldSessionId: supersedes,
|
|
222
|
+
newSessionId: sessionId,
|
|
223
|
+
reason: '',
|
|
224
|
+
});
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
if (toolQueued(body)) {
|
|
228
|
+
const depends = input?.dependsOn;
|
|
229
|
+
events.push({
|
|
230
|
+
kind: 'queue',
|
|
231
|
+
anchorMessageId: anchor,
|
|
232
|
+
sessionId,
|
|
233
|
+
dependsOn: Array.isArray(depends) ? depends.filter((item) => typeof item === 'string') : [],
|
|
234
|
+
});
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
events.push({ kind: 'parallel', anchorMessageId: anchor, sessionId, sessionIds: [sessionId] });
|
|
238
|
+
}
|
|
239
|
+
return events;
|
|
240
|
+
}
|
|
241
|
+
function fieldText(record, key) {
|
|
242
|
+
const value = record?.[key];
|
|
243
|
+
return typeof value === 'string' ? value.trim() : '';
|
|
244
|
+
}
|
|
135
245
|
/**
|
|
136
246
|
* Dispositions are a projection of anchor events plus replies.
|
|
137
247
|
* The assistant text answers the last user message in the turn unless replyTo says otherwise.
|
package/dist/goal.d.ts
CHANGED
|
@@ -164,6 +164,12 @@ export interface EvidenceIndexRecord {
|
|
|
164
164
|
readonly toolName?: string;
|
|
165
165
|
readonly createdAt: string;
|
|
166
166
|
readonly artifactRefs?: readonly string[];
|
|
167
|
+
/** Redacted, bounded execution-time snapshot of a successful file Tool Result. */
|
|
168
|
+
readonly bodyPreview?: {
|
|
169
|
+
readonly kind: 'file';
|
|
170
|
+
readonly text: string;
|
|
171
|
+
readonly truncated: boolean;
|
|
172
|
+
};
|
|
167
173
|
}
|
|
168
174
|
/** 批准事实(Evidence)。 */
|
|
169
175
|
export interface GoalApproval {
|
package/dist/memory.d.ts
CHANGED
|
@@ -5,7 +5,21 @@ import type { MessageDisposition } from './delegation.ts';
|
|
|
5
5
|
export type MemoryKind = 'fact' | 'preference' | 'decision' | 'procedure' | 'responsibility';
|
|
6
6
|
export type MemoryTrust = 'verified' | 'stated' | 'inferred';
|
|
7
7
|
export type MemoryStatus = 'active' | 'forgotten' | 'expired' | 'conflicted';
|
|
8
|
-
export interface
|
|
8
|
+
export interface MemoryValidityFields {
|
|
9
|
+
readonly expiresAt?: string;
|
|
10
|
+
readonly topicKey?: string;
|
|
11
|
+
readonly topicValue?: string;
|
|
12
|
+
readonly conflictId?: string;
|
|
13
|
+
readonly conflictsWith?: readonly string[];
|
|
14
|
+
readonly supersededBy?: string;
|
|
15
|
+
readonly needsReverify?: boolean;
|
|
16
|
+
readonly fileAnchors?: readonly {
|
|
17
|
+
readonly path: string;
|
|
18
|
+
readonly contentHash: string;
|
|
19
|
+
readonly commit: string | null;
|
|
20
|
+
}[];
|
|
21
|
+
}
|
|
22
|
+
export interface MemoryItem extends MemoryValidityFields {
|
|
9
23
|
readonly id: string;
|
|
10
24
|
readonly scope: 'project' | 'user';
|
|
11
25
|
readonly workspaceId?: string;
|
|
@@ -36,6 +50,89 @@ export interface MemorySnapshot {
|
|
|
36
50
|
readonly itemIds: readonly string[];
|
|
37
51
|
readonly createdAt: string;
|
|
38
52
|
}
|
|
53
|
+
/** 记忆页跨进程载荷。渲染层不读存储。 */
|
|
54
|
+
export interface ProjectMemoryRecord extends MemoryValidityFields {
|
|
55
|
+
readonly id: string;
|
|
56
|
+
readonly scope: 'project' | 'user';
|
|
57
|
+
readonly workspaceId?: string;
|
|
58
|
+
readonly kind: MemoryKind;
|
|
59
|
+
readonly text: string;
|
|
60
|
+
readonly trust: MemoryTrust;
|
|
61
|
+
readonly sourceRefs: readonly string[];
|
|
62
|
+
readonly pinned: boolean;
|
|
63
|
+
readonly status: MemoryStatus;
|
|
64
|
+
readonly confirmedCount: number;
|
|
65
|
+
readonly createdAt: string;
|
|
66
|
+
readonly updatedAt: string;
|
|
67
|
+
readonly lastUsedAt?: string;
|
|
68
|
+
readonly anchorMessageId?: string;
|
|
69
|
+
readonly forgetReason?: string;
|
|
70
|
+
}
|
|
71
|
+
export interface ProjectMemorySwitches {
|
|
72
|
+
readonly memoryEnabled: boolean;
|
|
73
|
+
readonly useMemory: boolean;
|
|
74
|
+
readonly learnPreferences: boolean;
|
|
75
|
+
}
|
|
76
|
+
export interface ProjectMemoryListRequest {
|
|
77
|
+
readonly workspaceId: string;
|
|
78
|
+
readonly kind?: MemoryKind;
|
|
79
|
+
readonly trust?: MemoryTrust;
|
|
80
|
+
readonly status?: MemoryStatus;
|
|
81
|
+
readonly ids?: readonly string[];
|
|
82
|
+
}
|
|
83
|
+
export interface ProjectMemoryListResult {
|
|
84
|
+
readonly ok: boolean;
|
|
85
|
+
readonly code?: string;
|
|
86
|
+
readonly items?: readonly ProjectMemoryRecord[];
|
|
87
|
+
readonly switches?: ProjectMemorySwitches;
|
|
88
|
+
}
|
|
89
|
+
export interface ProjectMemoryPinRequest {
|
|
90
|
+
readonly workspaceId: string;
|
|
91
|
+
readonly id: string;
|
|
92
|
+
readonly pinned: boolean;
|
|
93
|
+
}
|
|
94
|
+
export interface ProjectMemoryForgetRequest {
|
|
95
|
+
readonly workspaceId: string;
|
|
96
|
+
readonly id: string;
|
|
97
|
+
readonly reason?: string;
|
|
98
|
+
}
|
|
99
|
+
export interface ProjectMemoryRestoreRequest {
|
|
100
|
+
readonly workspaceId: string;
|
|
101
|
+
readonly id: string;
|
|
102
|
+
readonly resolveConflict?: boolean;
|
|
103
|
+
}
|
|
104
|
+
export interface ProjectMemoryEditRequest {
|
|
105
|
+
readonly workspaceId: string;
|
|
106
|
+
readonly id: string;
|
|
107
|
+
readonly text: string;
|
|
108
|
+
}
|
|
109
|
+
export interface ProjectMemoryItemResult {
|
|
110
|
+
readonly ok: boolean;
|
|
111
|
+
readonly code?: string;
|
|
112
|
+
readonly item?: ProjectMemoryRecord;
|
|
113
|
+
readonly revokedId?: string;
|
|
114
|
+
}
|
|
115
|
+
export interface ProjectMemoryExportRequest {
|
|
116
|
+
readonly workspaceId: string;
|
|
117
|
+
readonly format: 'json' | 'markdown';
|
|
118
|
+
}
|
|
119
|
+
export interface ProjectMemoryExportResult {
|
|
120
|
+
readonly ok: boolean;
|
|
121
|
+
readonly code?: string;
|
|
122
|
+
readonly path?: string;
|
|
123
|
+
readonly format?: 'json' | 'markdown';
|
|
124
|
+
}
|
|
125
|
+
export interface ProjectMemorySetSwitchesRequest {
|
|
126
|
+
readonly workspaceId: string;
|
|
127
|
+
readonly memoryEnabled?: boolean;
|
|
128
|
+
readonly useMemory?: boolean;
|
|
129
|
+
readonly learnPreferences?: boolean;
|
|
130
|
+
}
|
|
131
|
+
export interface ProjectMemorySetSwitchesResult {
|
|
132
|
+
readonly ok: boolean;
|
|
133
|
+
readonly code?: string;
|
|
134
|
+
readonly switches?: ProjectMemorySwitches;
|
|
135
|
+
}
|
|
39
136
|
export type MemoryAdmission = {
|
|
40
137
|
readonly ok: true;
|
|
41
138
|
} | {
|
package/dist/memory.js
CHANGED
|
@@ -15,6 +15,8 @@ export function assessMemoryCandidate(item, options = {}) {
|
|
|
15
15
|
}
|
|
16
16
|
if (item.status === 'conflicted')
|
|
17
17
|
return { ok: false, reason: 'conflicted' };
|
|
18
|
+
if (item.needsReverify === true)
|
|
19
|
+
return { ok: false, reason: 'needs_reverify' };
|
|
18
20
|
if (SECRET.test(item.text))
|
|
19
21
|
return { ok: false, reason: 'sensitive' };
|
|
20
22
|
if (LOOSENING.test(item.text))
|
package/dist/model-routing.d.ts
CHANGED
|
@@ -53,6 +53,35 @@ export interface ModelSelectionSnapshot {
|
|
|
53
53
|
readonly autoReason?: string;
|
|
54
54
|
readonly resolvedAt: string;
|
|
55
55
|
}
|
|
56
|
+
/** Model row shown in the routing menu. Shared by main projection and the renderer. */
|
|
57
|
+
export interface ModelRoutingMenuOption {
|
|
58
|
+
readonly id: string;
|
|
59
|
+
readonly label: string;
|
|
60
|
+
readonly providerName: string;
|
|
61
|
+
readonly groupId: string;
|
|
62
|
+
readonly model: string;
|
|
63
|
+
readonly authMethod: string;
|
|
64
|
+
readonly supportsVision: boolean;
|
|
65
|
+
readonly supportsTools: boolean;
|
|
66
|
+
readonly supportsStructured: boolean;
|
|
67
|
+
readonly contextTokens: number;
|
|
68
|
+
}
|
|
69
|
+
/** Project one configured provider into the routing menu contract. */
|
|
70
|
+
export declare function projectModelRoutingMenuOption(provider: {
|
|
71
|
+
readonly id?: unknown;
|
|
72
|
+
readonly groupId?: unknown;
|
|
73
|
+
readonly name?: unknown;
|
|
74
|
+
readonly model?: unknown;
|
|
75
|
+
readonly modelLabel?: unknown;
|
|
76
|
+
readonly authMethod?: unknown;
|
|
77
|
+
readonly supportsVision?: unknown;
|
|
78
|
+
readonly supportsTools?: unknown;
|
|
79
|
+
readonly supportsStructured?: unknown;
|
|
80
|
+
readonly capabilities?: {
|
|
81
|
+
readonly toolUse?: unknown;
|
|
82
|
+
} | null;
|
|
83
|
+
readonly contextWindow?: unknown;
|
|
84
|
+
} | null | undefined): ModelRoutingMenuOption | null;
|
|
56
85
|
export interface CatalogModel {
|
|
57
86
|
readonly modelProviderId: string;
|
|
58
87
|
readonly providerId: string;
|
package/dist/model-routing.js
CHANGED
|
@@ -2,6 +2,30 @@
|
|
|
2
2
|
* Role and tier model routing. Resolution is pure; hosts apply the result.
|
|
3
3
|
* Order and filters follow ADR 83. An empty candidate set is an error, not a silent downgrade.
|
|
4
4
|
*/
|
|
5
|
+
/** Project one configured provider into the routing menu contract. */
|
|
6
|
+
export function projectModelRoutingMenuOption(provider) {
|
|
7
|
+
if (!provider || typeof provider.id !== 'string' || !provider.id.trim())
|
|
8
|
+
return null;
|
|
9
|
+
const id = provider.id.trim();
|
|
10
|
+
const groupId = typeof provider.groupId === 'string' && provider.groupId.trim()
|
|
11
|
+
? provider.groupId.trim()
|
|
12
|
+
: id;
|
|
13
|
+
const label = [provider.modelLabel, provider.model, provider.name, id]
|
|
14
|
+
.find((value) => typeof value === 'string' && value.trim());
|
|
15
|
+
const context = Number(provider.contextWindow);
|
|
16
|
+
return {
|
|
17
|
+
id,
|
|
18
|
+
label: typeof label === 'string' ? label.trim() : id,
|
|
19
|
+
providerName: typeof provider.name === 'string' ? provider.name.trim() : '',
|
|
20
|
+
groupId,
|
|
21
|
+
model: typeof provider.model === 'string' ? provider.model.trim() : '',
|
|
22
|
+
authMethod: typeof provider.authMethod === 'string' ? provider.authMethod.trim() : '',
|
|
23
|
+
supportsVision: provider.supportsVision === true,
|
|
24
|
+
supportsTools: provider.supportsTools !== false && provider.capabilities?.toolUse !== false,
|
|
25
|
+
supportsStructured: provider.supportsStructured !== false,
|
|
26
|
+
contextTokens: Number.isFinite(context) && context > 0 ? context : 128_000,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
5
29
|
const EXPLORER_MIN_CONTEXT = 8_000;
|
|
6
30
|
function roleNeeds(input) {
|
|
7
31
|
const context = input.requiredContextTokens ?? 0;
|
package/dist/objectives.d.ts
CHANGED
|
@@ -1,13 +1,75 @@
|
|
|
1
|
-
|
|
1
|
+
import type { AutomationSchedule } from './automation.ts';
|
|
2
2
|
export type ObjectiveAutonomy = 'report_only' | 'propose' | 'act';
|
|
3
|
-
export type WatchTrigger = 'schedule' | 'git' | 'file' | 'ci';
|
|
4
3
|
export type ObjectiveStatus = 'active' | 'paused' | 'achieved' | 'abandoned';
|
|
5
|
-
export
|
|
4
|
+
export type WatchSeverity = 'info' | 'notable' | 'urgent';
|
|
5
|
+
export type ObjectiveProbe = {
|
|
6
|
+
readonly type: 'deterministic';
|
|
7
|
+
readonly check: 'git_ref';
|
|
8
|
+
readonly spec: {
|
|
9
|
+
readonly ref: string;
|
|
10
|
+
};
|
|
11
|
+
} | {
|
|
12
|
+
readonly type: 'deterministic';
|
|
13
|
+
readonly check: 'file_hash';
|
|
14
|
+
readonly spec: {
|
|
15
|
+
readonly path: string;
|
|
16
|
+
};
|
|
17
|
+
} | {
|
|
18
|
+
readonly type: 'deterministic';
|
|
19
|
+
readonly check: 'command';
|
|
20
|
+
readonly spec: {
|
|
21
|
+
readonly command: 'gh_run_list';
|
|
22
|
+
readonly workflow?: string;
|
|
23
|
+
};
|
|
24
|
+
} | {
|
|
25
|
+
readonly type: 'agent';
|
|
26
|
+
readonly question: string;
|
|
27
|
+
};
|
|
28
|
+
export type WatchEventSource = {
|
|
29
|
+
readonly type: 'task_event';
|
|
30
|
+
readonly filter: 'failed' | 'ended' | 'verified';
|
|
31
|
+
} | {
|
|
32
|
+
readonly type: 'git';
|
|
33
|
+
readonly ref: string;
|
|
34
|
+
readonly on: 'new_commits' | 'new_tag';
|
|
35
|
+
} | {
|
|
36
|
+
readonly type: 'files';
|
|
37
|
+
readonly paths: readonly string[];
|
|
38
|
+
readonly debounceMs?: 5000;
|
|
39
|
+
};
|
|
40
|
+
export type ObjectiveWatch = ({
|
|
41
|
+
readonly watchId: string;
|
|
42
|
+
readonly kind: 'schedule';
|
|
43
|
+
readonly schedule: AutomationSchedule;
|
|
44
|
+
readonly probe: ObjectiveProbe;
|
|
45
|
+
} | {
|
|
6
46
|
readonly watchId: string;
|
|
7
|
-
readonly
|
|
8
|
-
readonly
|
|
9
|
-
readonly
|
|
10
|
-
|
|
47
|
+
readonly kind: 'event';
|
|
48
|
+
readonly source: WatchEventSource;
|
|
49
|
+
readonly probe?: ObjectiveProbe;
|
|
50
|
+
}) & {
|
|
51
|
+
readonly notificationPolicy?: 'changes' | 'failure_only';
|
|
52
|
+
readonly lastScheduledAt?: string;
|
|
53
|
+
readonly nextRunAt?: string;
|
|
54
|
+
readonly unavailableReason?: string;
|
|
55
|
+
};
|
|
56
|
+
export interface ObjectiveSignal {
|
|
57
|
+
readonly signalId: string;
|
|
58
|
+
readonly watchId: string;
|
|
59
|
+
readonly operator: 'equals' | 'contains' | 'succeeded';
|
|
60
|
+
readonly value?: string;
|
|
61
|
+
}
|
|
62
|
+
export interface ObjectiveMilestone {
|
|
63
|
+
readonly id: string;
|
|
64
|
+
readonly title: string;
|
|
65
|
+
readonly sessionIds: readonly string[];
|
|
66
|
+
readonly status: 'pending' | 'active' | 'done' | 'dropped';
|
|
67
|
+
}
|
|
68
|
+
export interface ObjectiveBudget {
|
|
69
|
+
readonly maxAutoSessionsPerDay: number;
|
|
70
|
+
readonly maxProbeRunsPerDay: number;
|
|
71
|
+
/** Reject this optional policy until the host can enforce a token hard limit. */
|
|
72
|
+
readonly maxTokensPerDay?: number;
|
|
11
73
|
}
|
|
12
74
|
export interface ProjectObjective {
|
|
13
75
|
readonly objectiveId: string;
|
|
@@ -16,15 +78,21 @@ export interface ProjectObjective {
|
|
|
16
78
|
readonly originMessageId: string;
|
|
17
79
|
readonly title: string;
|
|
18
80
|
readonly outcome: string;
|
|
81
|
+
readonly successSignals: readonly ObjectiveSignal[];
|
|
82
|
+
readonly milestones: readonly ObjectiveMilestone[];
|
|
19
83
|
readonly autonomy: ObjectiveAutonomy;
|
|
20
84
|
readonly watches: readonly ObjectiveWatch[];
|
|
85
|
+
readonly budget: ObjectiveBudget;
|
|
21
86
|
readonly status: ObjectiveStatus;
|
|
22
87
|
readonly createdBy: 'user_request' | 'agent_proposal';
|
|
88
|
+
readonly pendingConfirmation?: boolean;
|
|
89
|
+
readonly autoAccept?: boolean;
|
|
90
|
+
readonly autoAcceptApprovedBy?: string;
|
|
23
91
|
readonly deadline?: string;
|
|
24
92
|
readonly createdAt: string;
|
|
25
93
|
readonly updatedAt: string;
|
|
94
|
+
readonly version: number;
|
|
26
95
|
}
|
|
27
|
-
export type WatchSeverity = 'info' | 'notable' | 'urgent';
|
|
28
96
|
export interface WatchObservation {
|
|
29
97
|
readonly objectiveId: string;
|
|
30
98
|
readonly watchId: string;
|
|
@@ -34,8 +102,40 @@ export interface WatchObservation {
|
|
|
34
102
|
readonly evidenceRefs: readonly string[];
|
|
35
103
|
readonly severity: WatchSeverity;
|
|
36
104
|
readonly changed: boolean;
|
|
105
|
+
readonly succeeded?: boolean;
|
|
106
|
+
readonly value?: string;
|
|
107
|
+
readonly executionKey?: string;
|
|
108
|
+
}
|
|
109
|
+
export interface ProjectObjectiveListRequest {
|
|
110
|
+
readonly workspaceId: string;
|
|
111
|
+
}
|
|
112
|
+
export interface ProjectObjectiveCommandRequest extends ProjectObjectiveListRequest {
|
|
113
|
+
readonly objectiveId: string;
|
|
114
|
+
readonly requestId: string;
|
|
115
|
+
}
|
|
116
|
+
export interface ProjectObjectiveUpdateRequest extends ProjectObjectiveCommandRequest {
|
|
117
|
+
readonly patch: Partial<Pick<ProjectObjective, 'title' | 'outcome' | 'watches' | 'milestones' | 'successSignals' | 'autonomy' | 'budget' | 'deadline' | 'autoAccept'>>;
|
|
118
|
+
readonly expectedVersion?: number;
|
|
119
|
+
}
|
|
120
|
+
export interface ProjectObjectiveView extends ProjectObjective {
|
|
121
|
+
readonly lastObservation?: WatchObservation | null;
|
|
122
|
+
readonly usage?: {
|
|
123
|
+
readonly autoSessions: number;
|
|
124
|
+
readonly probes: number;
|
|
125
|
+
readonly date: string;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
export interface ProjectObjectiveListResult {
|
|
129
|
+
readonly ok: boolean;
|
|
130
|
+
readonly code?: string;
|
|
131
|
+
readonly items?: readonly ProjectObjectiveView[];
|
|
132
|
+
}
|
|
133
|
+
export interface ProjectObjectiveItemResult {
|
|
134
|
+
readonly ok: boolean;
|
|
135
|
+
readonly code?: string;
|
|
136
|
+
readonly item?: ProjectObjective;
|
|
37
137
|
}
|
|
38
|
-
/**
|
|
138
|
+
/** The first observation is a change; summaries and caller flags cannot override digest truth. */
|
|
39
139
|
export declare function diffWatchObservation(prev: WatchObservation | null | undefined, next: Omit<WatchObservation, 'changed'> & {
|
|
40
140
|
readonly changed?: boolean;
|
|
41
141
|
}): WatchObservation;
|
package/dist/objectives.js
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
/** A watch reports upward only when its digest changes. The first observation counts as a change. */
|
|
1
|
+
/** The first observation is a change; summaries and caller flags cannot override digest truth. */
|
|
3
2
|
export function diffWatchObservation(prev, next) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
watchId: next.watchId,
|
|
8
|
-
observedAt: next.observedAt,
|
|
9
|
-
digest: next.digest,
|
|
10
|
-
summary: next.summary,
|
|
11
|
-
evidenceRefs: next.evidenceRefs,
|
|
12
|
-
severity: next.severity,
|
|
13
|
-
changed,
|
|
14
|
-
};
|
|
3
|
+
return { objectiveId: next.objectiveId, watchId: next.watchId, observedAt: next.observedAt, digest: next.digest, summary: next.summary,
|
|
4
|
+
evidenceRefs: next.evidenceRefs, severity: next.severity, changed: !prev || prev.digest !== next.digest,
|
|
5
|
+
...(typeof next.succeeded === 'boolean' ? { succeeded: next.succeeded } : {}), ...(typeof next.value === 'string' ? { value: next.value } : {}) };
|
|
15
6
|
}
|
package/dist/project.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Bot list projection. Sort is recent activity only.
|
|
3
3
|
* needsYou changes the badge and the filter, not the order.
|
|
4
4
|
*/
|
|
5
|
+
import type { ProjectModelPolicy } from './model-routing.ts';
|
|
5
6
|
import type { PendingApprovalState, WorkSessionStatus } from './delegation.ts';
|
|
6
7
|
export interface ProjectRegistryEntry {
|
|
7
8
|
readonly workspaceId: string;
|
|
@@ -15,22 +16,46 @@ export type BotAvatar = {
|
|
|
15
16
|
readonly kind: 'generated';
|
|
16
17
|
readonly shape: string;
|
|
17
18
|
readonly color: string;
|
|
19
|
+
readonly variant?: number;
|
|
18
20
|
} | {
|
|
19
21
|
readonly kind: 'image';
|
|
20
22
|
readonly ref: string;
|
|
21
23
|
};
|
|
24
|
+
export type BotAvatarReadResult = {
|
|
25
|
+
readonly ok: true;
|
|
26
|
+
readonly dataUrl: string;
|
|
27
|
+
} | {
|
|
28
|
+
readonly ok: false;
|
|
29
|
+
readonly code: 'PROJECT_AGENT_DISABLED' | 'NOT_FOUND' | 'INVALID_IMAGE';
|
|
30
|
+
};
|
|
22
31
|
export interface BotProfile {
|
|
23
32
|
readonly workspaceId: string;
|
|
24
33
|
readonly displayName: string;
|
|
25
34
|
readonly avatar: BotAvatar;
|
|
26
35
|
readonly managed?: boolean;
|
|
27
36
|
readonly agentConversationId?: string;
|
|
37
|
+
readonly proactivity?: 'inherit' | 'quiet' | 'low' | 'standard' | 'high' | 'muted';
|
|
38
|
+
/** Absent means this bot uses memory. */
|
|
39
|
+
readonly memoryEnabled?: boolean;
|
|
40
|
+
readonly planApproval?: 'never' | 'writes' | 'always';
|
|
41
|
+
readonly acceptancePolicy?: 'auto' | 'confirm';
|
|
42
|
+
/** Policy acceptance keeps a separate merge confirmation unless explicitly enabled. */
|
|
43
|
+
readonly autoHandoffOnPolicyAccept?: boolean;
|
|
44
|
+
/** Archived deletion intent, retained until each cleanup step is persisted. */
|
|
45
|
+
readonly deletionCleanup?: {
|
|
46
|
+
readonly folder: string;
|
|
47
|
+
readonly trashPending: boolean;
|
|
48
|
+
readonly removePending: boolean;
|
|
49
|
+
} | null;
|
|
50
|
+
readonly modelPolicy?: ProjectModelPolicy | null;
|
|
28
51
|
readonly updatedAt?: string;
|
|
29
52
|
}
|
|
30
53
|
export interface BotRowState {
|
|
31
54
|
readonly needsYou: number;
|
|
32
55
|
readonly unread: number;
|
|
33
56
|
readonly running: number;
|
|
57
|
+
/** Ephemeral status of the runner hosted by this desktop process. */
|
|
58
|
+
readonly agentStatus?: 'idle' | 'thinking' | 'waiting_provider' | 'error';
|
|
34
59
|
}
|
|
35
60
|
export interface BotListItem {
|
|
36
61
|
readonly workspaceId: string;
|
|
@@ -54,10 +79,14 @@ export interface BotListMessage {
|
|
|
54
79
|
readonly role: 'user' | 'assistant';
|
|
55
80
|
readonly text: string;
|
|
56
81
|
readonly at: string;
|
|
82
|
+
/** silent replies stay in the conversation and do not raise the unread badge. */
|
|
83
|
+
readonly countUnread?: boolean;
|
|
57
84
|
}
|
|
58
85
|
export declare const BOT_AVATAR_SHAPES: readonly ["circle", "square", "triangle", "diamond", "hex", "pill", "star", "arch"];
|
|
59
|
-
export declare const BOT_AVATAR_COLORS: readonly ["#
|
|
60
|
-
export declare function generateAvatar(workspaceId: string): BotAvatar
|
|
86
|
+
export declare const BOT_AVATAR_COLORS: readonly ["#6474e5", "#f36d63", "#f4ad45", "#61b68c", "#a884e5", "#e774ad", "#55bac7", "#a8a59f"];
|
|
87
|
+
export declare function generateAvatar(workspaceId: string): Extract<BotAvatar, {
|
|
88
|
+
kind: 'generated';
|
|
89
|
+
}>;
|
|
61
90
|
export declare function projectBotListItem(input: {
|
|
62
91
|
readonly profile: BotProfile;
|
|
63
92
|
readonly lastMessage?: BotListMessage | null;
|
package/dist/project.js
CHANGED
|
@@ -13,14 +13,14 @@ export const BOT_AVATAR_SHAPES = [
|
|
|
13
13
|
'arch',
|
|
14
14
|
];
|
|
15
15
|
export const BOT_AVATAR_COLORS = [
|
|
16
|
-
'#
|
|
17
|
-
'#
|
|
18
|
-
'#
|
|
19
|
-
'#
|
|
20
|
-
'#
|
|
21
|
-
'#
|
|
22
|
-
'#
|
|
23
|
-
'#
|
|
16
|
+
'#6474e5',
|
|
17
|
+
'#f36d63',
|
|
18
|
+
'#f4ad45',
|
|
19
|
+
'#61b68c',
|
|
20
|
+
'#a884e5',
|
|
21
|
+
'#e774ad',
|
|
22
|
+
'#55bac7',
|
|
23
|
+
'#a8a59f',
|
|
24
24
|
];
|
|
25
25
|
const NEEDS_YOU_STATUSES = new Set(['waiting_user', 'result_ready']);
|
|
26
26
|
const RUNNING_STATUSES = new Set(['starting', 'running', 'verifying']);
|
|
@@ -36,7 +36,8 @@ export function generateAvatar(workspaceId) {
|
|
|
36
36
|
const hash = fnv1a(workspaceId);
|
|
37
37
|
const shape = BOT_AVATAR_SHAPES[hash % BOT_AVATAR_SHAPES.length] ?? BOT_AVATAR_SHAPES[0];
|
|
38
38
|
const color = BOT_AVATAR_COLORS[(hash >>> 16) % BOT_AVATAR_COLORS.length] ?? BOT_AVATAR_COLORS[0];
|
|
39
|
-
|
|
39
|
+
const variant = (hash >>> 8) % 32;
|
|
40
|
+
return { kind: 'generated', shape, color, variant };
|
|
40
41
|
}
|
|
41
42
|
function latestIso(values) {
|
|
42
43
|
let best = '';
|
|
@@ -55,7 +56,10 @@ export function projectBotListItem(input) {
|
|
|
55
56
|
const waitingSessions = sessions.filter((item) => NEEDS_YOU_STATUSES.has(item.status)).length;
|
|
56
57
|
const running = sessions.filter((item) => RUNNING_STATUSES.has(item.status)).length;
|
|
57
58
|
const lastMessage = input.lastMessage ?? null;
|
|
58
|
-
const unread = lastMessage
|
|
59
|
+
const unread = lastMessage
|
|
60
|
+
&& lastMessage.role === 'assistant'
|
|
61
|
+
&& lastMessage.countUnread !== false
|
|
62
|
+
&& (!input.readCursor || lastMessage.at > input.readCursor)
|
|
59
63
|
? 1
|
|
60
64
|
: 0;
|
|
61
65
|
return {
|