@ours.network/fleet 2.4.4 → 2.5.1
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/README.md +29 -32
- package/dist/agent-ours/mcp-endpoint.d.ts +3 -0
- package/dist/agent-ours/mcp-endpoint.js +3 -0
- package/dist/agent-ours/service.d.ts +3 -0
- package/dist/agent-ours/service.js +19 -2
- package/dist/application/conversation-history.js +2 -2
- package/dist/application/fleet-query-service.js +4 -1
- package/dist/application/role-creation-service.js +0 -3
- package/dist/application/session-control.d.ts +3 -0
- package/dist/application/session-control.js +5 -0
- package/dist/application/types.d.ts +5 -0
- package/dist/build-info.json +4 -4
- package/dist/cli.js +2 -3
- package/dist/config.d.ts +9 -2
- package/dist/config.js +15 -4
- package/dist/docs.d.ts +5 -7
- package/dist/docs.js +38 -46
- package/dist/doctor.js +4 -6
- package/dist/file-delivery/store.d.ts +12 -0
- package/dist/file-delivery/store.js +24 -2
- package/dist/fleet-command-audit.js +3 -2
- package/dist/fleet-proxy.js +0 -1
- package/dist/harness/hermes-permissions.js +1 -1
- package/dist/harness/hermes-session.js +0 -1
- package/dist/init-wizard.js +2 -2
- package/dist/lifecycle-summary.d.ts +3 -2
- package/dist/lifecycle-summary.js +2 -3
- package/dist/notifications/status-producer.d.ts +37 -0
- package/dist/notifications/status-producer.js +146 -0
- package/dist/permissions.d.ts +2 -3
- package/dist/permissions.js +3 -3
- package/dist/preset-migration.js +12 -0
- package/dist/rooms-tasks/cli.js +2 -6
- package/dist/rooms-tasks/deletion.js +3 -0
- package/dist/rooms-tasks/member-overrides.d.ts +2 -1
- package/dist/rooms-tasks/member-overrides.js +1 -4
- package/dist/rooms-tasks/task-contributions.d.ts +15 -0
- package/dist/rooms-tasks/task-contributions.js +13 -2
- package/dist/runner.js +24 -8
- package/dist/session/acp.d.ts +9 -29
- package/dist/session/acp.js +31 -308
- package/dist/session/codex-app-server.d.ts +9 -6
- package/dist/session/codex-app-server.js +19 -58
- package/dist/session/control.d.ts +5 -0
- package/dist/session/control.js +19 -3
- package/dist/session/conversation-types.d.ts +3 -2
- package/dist/session/status-notice.d.ts +24 -0
- package/dist/session/status-notice.js +38 -0
- package/dist/session/types.d.ts +2 -0
- package/dist/spawn.d.ts +1 -2
- package/dist/spawn.js +2 -6
- package/dist/statuses/permission-projection.d.ts +53 -0
- package/dist/statuses/permission-projection.js +317 -0
- package/dist/statuses/status-answers.d.ts +31 -0
- package/dist/statuses/status-answers.js +85 -0
- package/dist/statuses/status-feed.d.ts +85 -0
- package/dist/statuses/status-feed.js +122 -0
- package/dist/statuses/status-kinds.d.ts +15 -0
- package/dist/statuses/status-kinds.js +12 -0
- package/dist/statuses/status-ledger.d.ts +21 -0
- package/dist/statuses/status-ledger.js +80 -0
- package/dist/statuses/status-routes.d.ts +43 -0
- package/dist/statuses/status-routes.js +140 -0
- package/dist/statuses/status-store.d.ts +257 -0
- package/dist/statuses/status-store.js +605 -0
- package/dist/statuses/status-tools.d.ts +21 -0
- package/dist/statuses/status-tools.js +126 -0
- package/dist/supervisor/manager.js +11 -0
- package/dist/web/resource-views.d.ts +3 -1
- package/dist/web/resource-views.js +6 -2
- package/dist/web/server.js +15 -0
- package/docs/acp-files.md +9 -7
- package/docs/validation/managed-cli-permissions.md +1 -1
- package/examples/fleet/agents/Alice.yaml +1 -1
- package/examples/fleet/agents/FleetCoordinator.yaml +1 -1
- package/examples/fleet.yaml +0 -1
- package/package.json +3 -3
- package/presets/fleet/agent_templates/Critic.yaml +1 -1
- package/presets/fleet/agent_templates/Developer.yaml +1 -1
- package/presets/fleet/agent_templates/Engineer.yaml +1 -1
- package/presets/fleet/agent_templates/LocalCoordinator.yaml +1 -1
- package/presets/fleet/agents/FleetCoordinator.yaml +1 -1
- package/presets/fleet.yaml +1 -1
- package/presets/manifest.json +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { StatusLedgerEntry } from '../session/status-notice.js';
|
|
2
|
+
import { type StatusRecord } from './status-store.js';
|
|
3
|
+
/** The identity CID the role's session is bound to, from its own bridge descriptor. */
|
|
4
|
+
export declare function sessionIdentityCid(stateDir: string): string | undefined;
|
|
5
|
+
/** The status as an agent's conversation shows it: what any surface shows, without Owner-private or internal fields. */
|
|
6
|
+
export declare function ledgerStatus(status: StatusRecord): Record<string, unknown>;
|
|
7
|
+
/**
|
|
8
|
+
* The conversation entries one committed status implies: published, each later revision (updated), the accepted
|
|
9
|
+
* answer (answered), each answer delivery outcome (updated) and the close. Keys are stable, so a runner can reconcile
|
|
10
|
+
* from the store at any time and append only what its ledger lacks. Each entry carries the status as committed now.
|
|
11
|
+
*/
|
|
12
|
+
export declare function statusLedgerEntries(status: StatusRecord): StatusLedgerEntry[];
|
|
13
|
+
/**
|
|
14
|
+
* Keeps one role's conversation in step with the statuses its bound identity authored. Runs in the role's runner,
|
|
15
|
+
* the ledger's only writer: on start and on every committed status change it appends what the ledger lacks. Statuses
|
|
16
|
+
* are written by the agent's tools, the web answer routes and delivery, so the ledger follows the store, not callers.
|
|
17
|
+
*/
|
|
18
|
+
export declare function startStatusLedger(stateDir: string, record: (entries: StatusLedgerEntry[]) => number, log: (line: string) => void, observe?: boolean): {
|
|
19
|
+
reconcile(): number;
|
|
20
|
+
stop(): void;
|
|
21
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { observeFleetResources } from '../application/resource-observer.js';
|
|
4
|
+
import { listAuthorStatuses, statusesDir } from './status-store.js';
|
|
5
|
+
/** The identity CID the role's session is bound to, from its own bridge descriptor. */
|
|
6
|
+
export function sessionIdentityCid(stateDir) {
|
|
7
|
+
try {
|
|
8
|
+
const cid = JSON.parse(readFileSync(join(stateDir, '.ours-bridge', 'descriptor.json'), 'utf8')).cid;
|
|
9
|
+
return typeof cid === 'string' && /^[A-Fa-f0-9]{64}$/.test(cid) ? cid.toUpperCase() : undefined;
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** The status as an agent's conversation shows it: what any surface shows, without Owner-private or internal fields. */
|
|
16
|
+
export function ledgerStatus(status) {
|
|
17
|
+
const { version: _version, request_key: _key, seen_revision: _seen, notification_events: _events, ...visible } = status;
|
|
18
|
+
return visible;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The conversation entries one committed status implies: published, each later revision (updated), the accepted
|
|
22
|
+
* answer (answered), each answer delivery outcome (updated) and the close. Keys are stable, so a runner can reconcile
|
|
23
|
+
* from the store at any time and append only what its ledger lacks. Each entry carries the status as committed now.
|
|
24
|
+
*/
|
|
25
|
+
export function statusLedgerEntries(status) {
|
|
26
|
+
// A permission request is already in the conversation as the harness's own permission records.
|
|
27
|
+
if (status.kind === 'permission')
|
|
28
|
+
return [];
|
|
29
|
+
const id = status.status_id, snapshot = ledgerStatus(status);
|
|
30
|
+
const entry = (kind, key) => ({ kind, notice: { key: `${id}:${key}`, statusId: id, revision: status.revision, status: snapshot } });
|
|
31
|
+
const entries = [entry('status.published', 'published')];
|
|
32
|
+
for (let revision = 2; revision <= status.revision; revision++)
|
|
33
|
+
entries.push(entry('status.updated', `revision:${revision}`));
|
|
34
|
+
const answer = status.answer;
|
|
35
|
+
if (answer) {
|
|
36
|
+
entries.push(entry('status.answered', `answered:${answer.submission_id}`));
|
|
37
|
+
if (answer.delivery.state !== 'pending')
|
|
38
|
+
entries.push(entry('status.updated', `delivery:${answer.submission_id}:${answer.delivery.state}:${answer.delivery.at}`));
|
|
39
|
+
}
|
|
40
|
+
if (status.state === 'closed')
|
|
41
|
+
entries.push(entry('status.closed', 'closed'));
|
|
42
|
+
return entries;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Keeps one role's conversation in step with the statuses its bound identity authored. Runs in the role's runner,
|
|
46
|
+
* the ledger's only writer: on start and on every committed status change it appends what the ledger lacks. Statuses
|
|
47
|
+
* are written by the agent's tools, the web answer routes and delivery, so the ledger follows the store, not callers.
|
|
48
|
+
*/
|
|
49
|
+
export function startStatusLedger(stateDir, record, log, observe = true) {
|
|
50
|
+
const shutdown = new AbortController();
|
|
51
|
+
let warned = false;
|
|
52
|
+
const reconcile = () => {
|
|
53
|
+
if (shutdown.signal.aborted)
|
|
54
|
+
return 0;
|
|
55
|
+
const cid = sessionIdentityCid(stateDir);
|
|
56
|
+
if (!cid)
|
|
57
|
+
return 0;
|
|
58
|
+
try {
|
|
59
|
+
const appended = record(listAuthorStatuses(cid).flatMap(statusLedgerEntries));
|
|
60
|
+
warned = false;
|
|
61
|
+
return appended;
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
// The store keeps every change; the next committed change or restart appends what is missing.
|
|
65
|
+
if (!warned)
|
|
66
|
+
log(`status conversation events not recorded yet: ${error?.message ?? String(error)}`);
|
|
67
|
+
warned = true;
|
|
68
|
+
return 0;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
if (observe)
|
|
72
|
+
observeFleetResources({ retryWatchFailures: true, paths: [statusesDir(), join(stateDir, '.ours-bridge')], roots: [] }, state => {
|
|
73
|
+
if (state.health === 'healthy')
|
|
74
|
+
reconcile();
|
|
75
|
+
else
|
|
76
|
+
log('status observation unavailable; status conversation events resume when it recovers');
|
|
77
|
+
}, shutdown.signal);
|
|
78
|
+
reconcile();
|
|
79
|
+
return { reconcile, stop: () => shutdown.abort() };
|
|
80
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { FastifyInstance } from 'fastify';
|
|
2
|
+
import type { WebAuth } from '../web/auth.js';
|
|
3
|
+
import type { WebServices } from '../web/server.js';
|
|
4
|
+
import { sessionIdentityCid } from './status-ledger.js';
|
|
5
|
+
export { sessionIdentityCid };
|
|
6
|
+
import { StatusAnswerService, type AnswerDeliveryPort } from './status-answers.js';
|
|
7
|
+
import { type StatusRecord } from './status-store.js';
|
|
8
|
+
/** The managed runtime CID its supervisor recorded for the agent's bridge; undefined when the agent is gone. */
|
|
9
|
+
export declare function deliveryPort(services: Pick<WebServices, 'repository' | 'session'>): AnswerDeliveryPort;
|
|
10
|
+
/** Status errors in the web error vocabulary; an already-answered question carries the accepted answer. */
|
|
11
|
+
export declare function statusFleetError(error: unknown): unknown;
|
|
12
|
+
/** The stored envelope plus the derived Owner state the cards render. */
|
|
13
|
+
export declare const publicStatus: (status: StatusRecord) => {
|
|
14
|
+
seen: boolean;
|
|
15
|
+
awaits_owner: boolean;
|
|
16
|
+
status_id: string;
|
|
17
|
+
source: "fleet";
|
|
18
|
+
kind: string;
|
|
19
|
+
author: {
|
|
20
|
+
identity_cid: string;
|
|
21
|
+
role: string;
|
|
22
|
+
display_name?: string;
|
|
23
|
+
};
|
|
24
|
+
task_id?: string;
|
|
25
|
+
revision: number;
|
|
26
|
+
title: string;
|
|
27
|
+
body: string;
|
|
28
|
+
attachments: import("./status-store.js").StatusAttachment[];
|
|
29
|
+
interaction?: import("./status-store.js").StatusInteraction;
|
|
30
|
+
state: "active" | "closed";
|
|
31
|
+
closed?: {
|
|
32
|
+
reason: string;
|
|
33
|
+
at: string;
|
|
34
|
+
superseded_by?: string;
|
|
35
|
+
};
|
|
36
|
+
supersedes?: string;
|
|
37
|
+
answer?: import("./status-store.js").StatusAnswer;
|
|
38
|
+
permission?: import("./status-store.js").PermissionDetails;
|
|
39
|
+
created_at: string;
|
|
40
|
+
updated_at: string;
|
|
41
|
+
};
|
|
42
|
+
/** Owner answer and Try again routes for Fleet agents' questions. Both require an authenticated, CSRF-checked browser. */
|
|
43
|
+
export declare function registerStatusAnswerRoutes(app: FastifyInstance, services: WebServices, auth: WebAuth, digestKey: Buffer, answers?: StatusAnswerService): void;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { createHmac } from 'node:crypto';
|
|
2
|
+
import { FleetError } from '../application/errors.js';
|
|
3
|
+
import { sessionIdentityCid } from './status-ledger.js';
|
|
4
|
+
export { sessionIdentityCid };
|
|
5
|
+
import { StatusAnswerService } from './status-answers.js';
|
|
6
|
+
import { AlreadyAnsweredError, findStatus, markStatusSeen, statusAwaitsOwner, statusSeen, StatusError } from './status-store.js';
|
|
7
|
+
import { feedScope, listFeed, markFeedItemSeen } from './status-feed.js';
|
|
8
|
+
import { findDeliveredFile } from '../file-delivery/store.js';
|
|
9
|
+
/** The managed runtime CID its supervisor recorded for the agent's bridge; undefined when the agent is gone. */
|
|
10
|
+
export function deliveryPort(services) {
|
|
11
|
+
return {
|
|
12
|
+
async identityCid(roleId) {
|
|
13
|
+
const role = await services.repository.get(roleId);
|
|
14
|
+
const stateDir = role && services.repository.stateDir(role);
|
|
15
|
+
return stateDir ? sessionIdentityCid(stateDir) : undefined;
|
|
16
|
+
},
|
|
17
|
+
async submit(roleId, prompt) {
|
|
18
|
+
const control = await services.session(roleId);
|
|
19
|
+
if (!control.submitPromptV2)
|
|
20
|
+
throw new FleetError('capability_unavailable', 'this agent session cannot receive answers');
|
|
21
|
+
// Never admit without the receiving supervisor's identity fence (managed sessions only).
|
|
22
|
+
if (!(await control.describe()).features.includes('identity_bound_prompts'))
|
|
23
|
+
throw new FleetError('capability_unavailable', 'this agent session cannot verify its identity at admission');
|
|
24
|
+
return control.submitPromptV2({ commandId: prompt.commandId, text: prompt.text, actorBrowserSession: prompt.actor,
|
|
25
|
+
expectedIdentityCid: prompt.identityCid, source: 'owner_admin_console' });
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/** Status errors in the web error vocabulary; an already-answered question carries the accepted answer. */
|
|
30
|
+
export function statusFleetError(error) {
|
|
31
|
+
if (error instanceof AlreadyAnsweredError)
|
|
32
|
+
return new FleetError('conflict', error.message, { details: { reason: 'already_answered', status: JSON.stringify(publicStatus(error.status)) } });
|
|
33
|
+
if (!(error instanceof StatusError))
|
|
34
|
+
return error;
|
|
35
|
+
const code = error.code === 'not_found' ? 'resource_not_found' : error.code === 'limit_exceeded' ? 'invalid_request' : error.code;
|
|
36
|
+
return new FleetError(code, error.message);
|
|
37
|
+
}
|
|
38
|
+
/** The stored envelope plus the derived Owner state the cards render. */
|
|
39
|
+
export const publicStatus = (status) => {
|
|
40
|
+
const { version: _version, request_key: _key, seen_revision: _seen, notification_events: _events, attachment_stores: _stores, ...visible } = status;
|
|
41
|
+
return { ...visible, seen: statusSeen(status), awaits_owner: statusAwaitsOwner(status) };
|
|
42
|
+
};
|
|
43
|
+
/** Owner answer and Try again routes for Fleet agents' questions. Both require an authenticated, CSRF-checked browser. */
|
|
44
|
+
export function registerStatusAnswerRoutes(app, services, auth, digestKey, answers = new StatusAnswerService(deliveryPort(services))) {
|
|
45
|
+
const actor = (sessionId) => createHmac('sha256', digestKey).update(sessionId).digest('hex').slice(0, 24);
|
|
46
|
+
app.post('/api/v1/statuses/:statusId/answer', async (request) => {
|
|
47
|
+
const session = auth.authenticate(request, true);
|
|
48
|
+
const body = (request.body ?? {});
|
|
49
|
+
const allowed = ['expectedRevision', 'submissionId', 'selection', 'text', 'surface'];
|
|
50
|
+
if (typeof body !== 'object' || Object.keys(body).some(key => !allowed.includes(key)))
|
|
51
|
+
throw new FleetError('invalid_request', 'unexpected answer field');
|
|
52
|
+
if (body.surface !== undefined && body.surface !== 'feed' && body.surface !== 'session')
|
|
53
|
+
throw new FleetError('invalid_request', 'surface must be feed or session');
|
|
54
|
+
try {
|
|
55
|
+
const status = await answers.answer(request.params.statusId, {
|
|
56
|
+
expectedRevision: body.expectedRevision, submissionId: body.submissionId,
|
|
57
|
+
...(body.selection === undefined ? {} : { selection: body.selection }),
|
|
58
|
+
...(body.text === undefined ? {} : { text: body.text }),
|
|
59
|
+
...(body.surface === undefined ? {} : { surface: body.surface }),
|
|
60
|
+
}, actor(session.id));
|
|
61
|
+
return { status: publicStatus(status) };
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
throw statusFleetError(error);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
app.get('/api/v1/statuses', async (request) => {
|
|
68
|
+
auth.authenticate(request);
|
|
69
|
+
const { scope, agent, task, after, limit } = request.query;
|
|
70
|
+
const extra = Object.keys(request.query).filter(key => !['scope', 'agent', 'task', 'after', 'limit'].includes(key));
|
|
71
|
+
if (extra.length)
|
|
72
|
+
throw new FleetError('invalid_request', `unexpected query ${extra[0]}`);
|
|
73
|
+
try {
|
|
74
|
+
return listFeed(feedScope({ scope, agent, task }), { ...(after === undefined ? {} : { after }), ...(limit === undefined ? {} : { limit: Number(limit) }) });
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
throw statusFleetError(error);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
app.get('/api/v1/statuses/:statusId', async (request) => {
|
|
81
|
+
auth.authenticate(request);
|
|
82
|
+
const status = findStatus(request.params.statusId);
|
|
83
|
+
if (!status)
|
|
84
|
+
throw new FleetError('resource_not_found', 'status not found');
|
|
85
|
+
return { status: publicStatus(status) };
|
|
86
|
+
});
|
|
87
|
+
/**
|
|
88
|
+
* A file attached to a status. It is served for as long as the status lists it, independently of the
|
|
89
|
+
* author's current session, and only when the stored bytes still match the metadata recorded at publish.
|
|
90
|
+
*/
|
|
91
|
+
app.get('/api/v1/statuses/:statusId/attachments/:attachmentId', async (request, reply) => {
|
|
92
|
+
auth.authenticate(request);
|
|
93
|
+
const status = findStatus(request.params.statusId);
|
|
94
|
+
const attachment = status?.attachments?.find(a => a.id === request.params.attachmentId);
|
|
95
|
+
const store = attachment && status?.attachment_stores?.[attachment.id];
|
|
96
|
+
if (!attachment || !store)
|
|
97
|
+
throw new FleetError('resource_not_found', 'status file not found');
|
|
98
|
+
let found;
|
|
99
|
+
try {
|
|
100
|
+
found = await findDeliveredFile(store, attachment.id, { name: attachment.name, mimeType: attachment.media_type, size: attachment.size, sha256: attachment.sha256 });
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
// Bytes or record that no longer match what the status recorded are never served, and say so.
|
|
104
|
+
if (error?.message === 'ARTIFACT_INTEGRITY_FAILED')
|
|
105
|
+
throw new FleetError('conflict', 'status file changed', { details: { reason: 'file_changed' } });
|
|
106
|
+
throw new FleetError('resource_not_found', 'status file unavailable');
|
|
107
|
+
}
|
|
108
|
+
reply.header('Cache-Control', 'private, no-store');
|
|
109
|
+
reply.header('X-Content-Type-Options', 'nosniff');
|
|
110
|
+
reply.header('Content-Security-Policy', "default-src 'none'; sandbox");
|
|
111
|
+
reply.header('Content-Disposition', `attachment; filename*=UTF-8''${encodeURIComponent(found.record.name).replace(/'/g, '%27')}`);
|
|
112
|
+
return reply.type('application/octet-stream').send(found.bytes);
|
|
113
|
+
});
|
|
114
|
+
/** The Owner displayed this revision as the current feed card or its session card came on screen. */
|
|
115
|
+
app.post('/api/v1/statuses/:statusId/seen', async (request) => {
|
|
116
|
+
auth.authenticate(request, true);
|
|
117
|
+
const body = (request.body ?? {});
|
|
118
|
+
if (typeof body !== 'object' || Object.keys(body).some(key => key !== 'revision'))
|
|
119
|
+
throw new FleetError('invalid_request', 'expected { revision }');
|
|
120
|
+
try {
|
|
121
|
+
const projected = /^(progress|review):/.test(request.params.statusId);
|
|
122
|
+
if (projected)
|
|
123
|
+
return markFeedItemSeen(request.params.statusId, body.revision);
|
|
124
|
+
const result = markStatusSeen(request.params.statusId, body.revision);
|
|
125
|
+
return { status: publicStatus(result.status), changed: result.changed };
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
throw statusFleetError(error);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
app.post('/api/v1/statuses/:statusId/answer/deliver', async (request) => {
|
|
132
|
+
const session = auth.authenticate(request, true);
|
|
133
|
+
try {
|
|
134
|
+
return { status: publicStatus(await answers.retry(request.params.statusId, actor(session.id))) };
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
throw statusFleetError(error);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
export declare const STATUS_TITLE_MAX = 120;
|
|
2
|
+
export declare const STATUS_BODY_MAX_BYTES: number;
|
|
3
|
+
export declare const STATUS_ATTACHMENTS_MAX = 10;
|
|
4
|
+
export declare const STATUS_OPTIONS_MIN = 2;
|
|
5
|
+
export declare const STATUS_OPTIONS_MAX = 12;
|
|
6
|
+
export declare const STATUS_CLOSE_REASON_MAX = 500;
|
|
7
|
+
export type StatusErrorCode = 'invalid_request' | 'limit_exceeded' | 'not_found' | 'forbidden' | 'conflict' | 'idempotency_conflict';
|
|
8
|
+
export declare class StatusError extends Error {
|
|
9
|
+
readonly code: StatusErrorCode;
|
|
10
|
+
constructor(code: StatusErrorCode, message: string);
|
|
11
|
+
}
|
|
12
|
+
export interface StatusAuthorBinding {
|
|
13
|
+
/** Durable identity CID of the authenticated agent. */
|
|
14
|
+
identityCid: string;
|
|
15
|
+
role: string;
|
|
16
|
+
displayName?: string;
|
|
17
|
+
/** From the supervisor's task binding only. */
|
|
18
|
+
taskId?: string;
|
|
19
|
+
/** For each attachment, the conversation-file store that holds it (resolved by Fleet, never by the agent). */
|
|
20
|
+
attachmentStores?: Record<string, string>;
|
|
21
|
+
}
|
|
22
|
+
/** A file the agent delivered through its conversation-file store, referenced by its artifact ID. */
|
|
23
|
+
export interface StatusAttachment {
|
|
24
|
+
id: string;
|
|
25
|
+
name: string;
|
|
26
|
+
media_type: string;
|
|
27
|
+
size: number;
|
|
28
|
+
sha256: string;
|
|
29
|
+
}
|
|
30
|
+
export interface StatusOption {
|
|
31
|
+
id: string;
|
|
32
|
+
label: string;
|
|
33
|
+
description?: string;
|
|
34
|
+
recommended?: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface StatusInteraction {
|
|
37
|
+
mode: 'text' | 'single' | 'multi';
|
|
38
|
+
options?: StatusOption[];
|
|
39
|
+
allowOther?: boolean;
|
|
40
|
+
placeholder?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface PermissionDetails {
|
|
43
|
+
session_generation: string;
|
|
44
|
+
permission_id: string;
|
|
45
|
+
tool_call_id?: string;
|
|
46
|
+
/** The harness's own options, IDs and labels unchanged; answered only through the existing permission route. */
|
|
47
|
+
options: Array<{
|
|
48
|
+
option_id: string;
|
|
49
|
+
name: string;
|
|
50
|
+
kind: string;
|
|
51
|
+
}>;
|
|
52
|
+
requested_at: string;
|
|
53
|
+
/** From the harness's own resolution record. */
|
|
54
|
+
resolution?: {
|
|
55
|
+
decision: 'allowed' | 'denied' | 'cancelled' | 'expired';
|
|
56
|
+
decision_source: 'automatic' | 'manual';
|
|
57
|
+
option_id?: string;
|
|
58
|
+
reason?: string;
|
|
59
|
+
at: string;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export interface PermissionRequestInput {
|
|
63
|
+
sessionGeneration: string;
|
|
64
|
+
permissionId: string;
|
|
65
|
+
toolCallId?: string;
|
|
66
|
+
title?: string;
|
|
67
|
+
options: Array<{
|
|
68
|
+
optionId: string;
|
|
69
|
+
name: string;
|
|
70
|
+
kind: string;
|
|
71
|
+
}>;
|
|
72
|
+
requestedAt: string;
|
|
73
|
+
}
|
|
74
|
+
export interface PermissionResolutionInput {
|
|
75
|
+
sessionGeneration: string;
|
|
76
|
+
permissionId: string;
|
|
77
|
+
decision: 'allowed' | 'denied' | 'cancelled' | 'expired';
|
|
78
|
+
decisionSource: 'automatic' | 'manual';
|
|
79
|
+
optionId?: string;
|
|
80
|
+
reason?: string;
|
|
81
|
+
at: string;
|
|
82
|
+
}
|
|
83
|
+
export interface StatusRecord {
|
|
84
|
+
version: 1;
|
|
85
|
+
status_id: string;
|
|
86
|
+
source: 'fleet';
|
|
87
|
+
kind: string;
|
|
88
|
+
author: {
|
|
89
|
+
identity_cid: string;
|
|
90
|
+
role: string;
|
|
91
|
+
display_name?: string;
|
|
92
|
+
};
|
|
93
|
+
task_id?: string;
|
|
94
|
+
revision: number;
|
|
95
|
+
title: string;
|
|
96
|
+
body: string;
|
|
97
|
+
attachments: StatusAttachment[];
|
|
98
|
+
interaction?: StatusInteraction;
|
|
99
|
+
state: 'active' | 'closed';
|
|
100
|
+
closed?: {
|
|
101
|
+
reason: string;
|
|
102
|
+
at: string;
|
|
103
|
+
superseded_by?: string;
|
|
104
|
+
};
|
|
105
|
+
supersedes?: string;
|
|
106
|
+
request_key?: string;
|
|
107
|
+
/** The Owner's one accepted answer to a question, committed atomically with its delivery state. */
|
|
108
|
+
answer?: StatusAnswer;
|
|
109
|
+
/** The last revision the Owner has seen (informational statuses and ended questions only). */
|
|
110
|
+
seen_revision?: number;
|
|
111
|
+
/** A harness permission request, exactly as the harness raised it (kind `permission` only). */
|
|
112
|
+
permission?: PermissionDetails;
|
|
113
|
+
/** Pending push work, committed atomically with the change that caused it and removed once the service accepted it. */
|
|
114
|
+
notification_events?: StatusNotificationEvent[];
|
|
115
|
+
/** Server-only: the conversation-file store holding each attachment, so its file stays readable after a fresh session. */
|
|
116
|
+
attachment_stores?: Record<string, string>;
|
|
117
|
+
created_at: string;
|
|
118
|
+
updated_at: string;
|
|
119
|
+
}
|
|
120
|
+
export type AnswerDelivery = {
|
|
121
|
+
state: 'pending';
|
|
122
|
+
command_id: string;
|
|
123
|
+
at: string;
|
|
124
|
+
} | {
|
|
125
|
+
state: 'delivered';
|
|
126
|
+
command_id: string;
|
|
127
|
+
at: string;
|
|
128
|
+
prompt_id: string;
|
|
129
|
+
} | {
|
|
130
|
+
state: 'not_delivered';
|
|
131
|
+
command_id: string;
|
|
132
|
+
at: string;
|
|
133
|
+
reason: string;
|
|
134
|
+
};
|
|
135
|
+
export interface StatusAnswer {
|
|
136
|
+
submission_id: string;
|
|
137
|
+
/** Chosen option IDs for single/multi questions. */
|
|
138
|
+
selection?: string[];
|
|
139
|
+
/** Free text for a text question, or the "Other…" text of a choice question. */
|
|
140
|
+
text?: string;
|
|
141
|
+
answered_at: string;
|
|
142
|
+
/** Where the Owner answered; informational only. */
|
|
143
|
+
surface: 'feed' | 'session';
|
|
144
|
+
delivery: AnswerDelivery;
|
|
145
|
+
}
|
|
146
|
+
export interface AnswerInput {
|
|
147
|
+
expectedRevision: number;
|
|
148
|
+
submissionId: string;
|
|
149
|
+
selection?: string[];
|
|
150
|
+
text?: string;
|
|
151
|
+
surface?: 'feed' | 'session';
|
|
152
|
+
}
|
|
153
|
+
export declare const STATUS_ANSWER_TEXT_MAX = 8000;
|
|
154
|
+
/** The existing session admission refuses prompts over 32 KiB (RoleSessionControlAdapter.submitPromptV2). */
|
|
155
|
+
export declare const ANSWER_PROMPT_MAX_BYTES: number;
|
|
156
|
+
export declare class AlreadyAnsweredError extends StatusError {
|
|
157
|
+
readonly status: StatusRecord;
|
|
158
|
+
constructor(status: StatusRecord);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* One push event (`send`, one per publication or material revision) or the end of a pending question's notification
|
|
162
|
+
* (`resolve`: answered, closed or superseded). Owner answers, seen changes and closes never push.
|
|
163
|
+
*/
|
|
164
|
+
export type StatusNotificationEvent = {
|
|
165
|
+
op: 'send';
|
|
166
|
+
eventId: string;
|
|
167
|
+
delivery: 'inbox' | 'until-resolved';
|
|
168
|
+
} | {
|
|
169
|
+
op: 'resolve';
|
|
170
|
+
eventId: string;
|
|
171
|
+
};
|
|
172
|
+
export interface PublishInput {
|
|
173
|
+
kind: string;
|
|
174
|
+
title: string;
|
|
175
|
+
body: string;
|
|
176
|
+
attachments?: StatusAttachment[];
|
|
177
|
+
interaction?: StatusInteraction;
|
|
178
|
+
supersedes?: string;
|
|
179
|
+
request_key?: string;
|
|
180
|
+
}
|
|
181
|
+
/** A harness permission request: `permission:<authorCid>:<sessionGeneration>:<permissionId>`, the native identity. */
|
|
182
|
+
export declare const PERMISSION_STATUS_ID: RegExp;
|
|
183
|
+
export declare const statusesDir: () => string;
|
|
184
|
+
export declare function canonicalCid(value: string): string;
|
|
185
|
+
/** Validates a publish request in full before anything is stored. Author and mission are refused as inputs. */
|
|
186
|
+
export declare function validatePublish(raw: unknown): Required<Pick<PublishInput, 'kind' | 'title' | 'body'>> & PublishInput & {
|
|
187
|
+
attachments: StatusAttachment[];
|
|
188
|
+
};
|
|
189
|
+
export interface PublishResult {
|
|
190
|
+
status: StatusRecord;
|
|
191
|
+
replayed: boolean;
|
|
192
|
+
superseded?: StatusRecord;
|
|
193
|
+
}
|
|
194
|
+
/** Publish a native status for the authenticated author; a question may supersede (close) the author's older question. */
|
|
195
|
+
export declare function publishStatus(bindingInput: StatusAuthorBinding, raw: unknown, now?: Date): PublishResult;
|
|
196
|
+
/** Close the author's own status with a reason. Closing another agent's status is refused and changes nothing. */
|
|
197
|
+
export declare function closeStatus(bindingInput: StatusAuthorBinding, statusId: string, reasonInput: unknown, now?: Date): {
|
|
198
|
+
status: StatusRecord;
|
|
199
|
+
changed: boolean;
|
|
200
|
+
};
|
|
201
|
+
/** The fixed prompt the originating agent receives. */
|
|
202
|
+
export declare function answerPrompt(status: StatusRecord, answer: Pick<StatusAnswer, 'selection' | 'text'>): string;
|
|
203
|
+
/** The command ID that delivers one answer; a repeated delivery is deduplicated by the session's admission receipt. */
|
|
204
|
+
export declare function answerCommandId(statusId: string, submissionId: string): string;
|
|
205
|
+
/**
|
|
206
|
+
* Accept the Owner's answer: the first accepted answer wins. The answer and `delivery=pending` are committed in one
|
|
207
|
+
* atomic write, so the question is Answered on every surface from then on. The same submission replayed returns the
|
|
208
|
+
* stored answer; a different answer after acceptance fails with the accepted one.
|
|
209
|
+
*/
|
|
210
|
+
export declare function recordAnswer(statusId: string, input: AnswerInput, now?: Date): {
|
|
211
|
+
status: StatusRecord;
|
|
212
|
+
replayed: boolean;
|
|
213
|
+
};
|
|
214
|
+
/** Record the outcome of one delivery attempt of the accepted answer. */
|
|
215
|
+
export declare function setAnswerDelivery(statusId: string, submissionId: string, delivery: AnswerDelivery): StatusRecord;
|
|
216
|
+
/**
|
|
217
|
+
* Seen state (Owner requirement 12): an informational status is seen once its current revision was displayed. An
|
|
218
|
+
* open question is seen only when the Owner has answered it; displaying it never counts. A question that ended
|
|
219
|
+
* without the Owner's answer (closed or superseded) is informational from then on.
|
|
220
|
+
*/
|
|
221
|
+
export declare function statusSeen(status: StatusRecord): boolean;
|
|
222
|
+
/** Waiting for the Owner: an open, unanswered question or a pending permission request. */
|
|
223
|
+
export declare const statusAwaitsOwner: (status: StatusRecord) => boolean;
|
|
224
|
+
/**
|
|
225
|
+
* Record that the Owner displayed `revision` of a status. An open question is not marked (it stays unseen until
|
|
226
|
+
* answered); a stale or future revision changes nothing. Returns the resulting seen state.
|
|
227
|
+
*/
|
|
228
|
+
export declare function markStatusSeen(statusId: string, revision: number): {
|
|
229
|
+
status: StatusRecord;
|
|
230
|
+
seen: boolean;
|
|
231
|
+
changed: boolean;
|
|
232
|
+
};
|
|
233
|
+
/** Statuses with push work still pending, oldest first. */
|
|
234
|
+
export declare function pendingStatusNotifications(): StatusRecord[];
|
|
235
|
+
/** The service accepted this event: remove it (and only it) from the status. Idempotent. */
|
|
236
|
+
export declare function acknowledgeStatusNotification(statusId: string, eventId: string, op: StatusNotificationEvent['op']): void;
|
|
237
|
+
/** Any status by ID, from any author; `undefined` when absent. */
|
|
238
|
+
export declare function findStatus(statusId: string): StatusRecord | undefined;
|
|
239
|
+
/** Every retained status of one author, oldest first. */
|
|
240
|
+
export declare function listAuthorStatuses(identityCid: string): StatusRecord[];
|
|
241
|
+
/** Every retained status, oldest first. */
|
|
242
|
+
export declare function listAllStatuses(): StatusRecord[];
|
|
243
|
+
/** Mission deletion removes only the statuses associated with that mission; the authors' other statuses stay. */
|
|
244
|
+
export declare function deleteTaskStatuses(taskId: string): number;
|
|
245
|
+
/** The Owner deleting an agent's data removes all of its statuses. */
|
|
246
|
+
export declare function deleteAuthorStatuses(identityCid: string): void;
|
|
247
|
+
export declare const permissionStatusId: (cid: string, generation: string, permissionId: string) => string;
|
|
248
|
+
/** A request became pending: one status and one push (until resolved). Idempotent; the first record wins. */
|
|
249
|
+
export declare function recordPermissionRequest(binding: StatusAuthorBinding, input: PermissionRequestInput): StatusRecord;
|
|
250
|
+
/** The harness resolved the request: the status ends with that outcome and its notification is resolved. Idempotent. */
|
|
251
|
+
/** The reason recorded when a request's session generation ended without any native resolution being found. */
|
|
252
|
+
export declare const SESSION_ENDED_REASON = "the session ended while this request was pending";
|
|
253
|
+
/**
|
|
254
|
+
* Record the request's end. The first native resolution wins; a native resolution found later also replaces a
|
|
255
|
+
* synthetic "session ended" (the history it came from was incomplete), without another push or resolve.
|
|
256
|
+
*/
|
|
257
|
+
export declare function recordPermissionResolution(identityCid: string, input: PermissionResolutionInput): StatusRecord | undefined;
|