@ours.network/fleet 2.4.0 → 2.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/README.md +2 -0
  2. package/contrib/.claude-plugin/marketplace.json +1 -0
  3. package/contrib/claude-native/.claude-plugin/plugin.json +1 -0
  4. package/contrib/claude-native/hooks/hooks.json +1 -0
  5. package/contrib/claude-native/hooks/register.js +160 -0
  6. package/dist/application/fleet-query-service.d.ts +9 -0
  7. package/dist/application/fleet-query-service.js +36 -2
  8. package/dist/application/native-claude-conversation.d.ts +34 -0
  9. package/dist/application/native-claude-conversation.js +102 -0
  10. package/dist/application/native-codex-conversation.d.ts +20 -0
  11. package/dist/application/native-codex-conversation.js +68 -0
  12. package/dist/application/native-conversation.d.ts +120 -0
  13. package/dist/application/native-conversation.js +193 -0
  14. package/dist/application/native-conversations.d.ts +19 -0
  15. package/dist/application/native-conversations.js +74 -0
  16. package/dist/application/native-correspondence.d.ts +98 -0
  17. package/dist/application/native-correspondence.js +161 -0
  18. package/dist/application/native-mailbox.d.ts +14 -0
  19. package/dist/application/native-mailbox.js +77 -0
  20. package/dist/application/types.d.ts +7 -1
  21. package/dist/build-info.json +4 -4
  22. package/dist/cli.js +2 -0
  23. package/dist/native-codex-history.d.ts +9 -0
  24. package/dist/native-codex-history.js +62 -0
  25. package/dist/native-codex-wake.d.ts +25 -0
  26. package/dist/native-codex-wake.js +237 -0
  27. package/dist/native-participation-cli.d.ts +62 -0
  28. package/dist/native-participation-cli.js +279 -0
  29. package/dist/native-participation.d.ts +125 -0
  30. package/dist/native-participation.js +446 -0
  31. package/dist/web/runtime.js +49 -3
  32. package/docs/native-session-participation.md +193 -0
  33. package/package.json +7 -6
@@ -11,7 +11,8 @@ export interface ResolvedRoleView {
11
11
  coordinator?: string;
12
12
  model?: string;
13
13
  cwd?: string;
14
- permissions: CommonPermissions;
14
+ /** Absent when native terminal permissions are not controlled or observed by Fleet. */
15
+ permissions?: CommonPermissions;
15
16
  nativeRuntime?: {
16
17
  approval?: string;
17
18
  permissionMode?: string;
@@ -23,6 +24,11 @@ export interface ResolvedRoleView {
23
24
  }>;
24
25
  }
25
26
  export interface RoleRecord {
27
+ /** Independent native runtime; mail is addressed by CID, never a managed supervisor. */
28
+ nativeParticipation?: {
29
+ harness: 'claude' | 'codex';
30
+ cid: string;
31
+ };
26
32
  id: string;
27
33
  lifetime: RoleLifetime;
28
34
  configured: boolean;
@@ -1,9 +1,9 @@
1
1
  {
2
- "version": "2.4.0",
3
- "buildId": "17723bb4a836",
4
- "commit": "3b9273d4451adb2793ad8e695b41190c8d603784",
2
+ "version": "2.4.2",
3
+ "buildId": "c4df69be7960",
4
+ "commit": "047f0e7dac25a02aa8dbed1005f21d341ff6d53e",
5
5
  "dirty": false,
6
- "builtAt": "2026-11-17T20:23:49.639Z",
6
+ "builtAt": "2026-12-02T22:59:37.875Z",
7
7
  "capabilities": [
8
8
  "service.refresh-v1",
9
9
  "managed-cli.codex-reasoning-effort-v1",
package/dist/cli.js CHANGED
@@ -58,6 +58,7 @@ import { beginFleetAuditCollection, consumeFleetAuditCollection, FleetCliExit, s
58
58
  import './harness/claude-code.js'; // registers the claude-code adapter
59
59
  import './harness/codex.js'; // registers the codex adapter
60
60
  import './harness/hermes.js';
61
+ import { registerNativeParticipationCommands } from './native-participation-cli.js';
61
62
  import { registerLayoutCommands } from './rooms-tasks/layout-cli.js';
62
63
  import { MANAGED_CONFIGURATION_FLAG, assertPinnedConfiguration, enableManagedCli, managedCliReport, parseManagedEntry, } from './managed-cli.js';
63
64
  import { MANAGED_CLI_WORKFLOW_IDS } from './config.js';
@@ -1884,6 +1885,7 @@ function configureWebAccess(opts) {
1884
1885
  return undefined;
1885
1886
  }
1886
1887
  // ── rooms & tasks ──────────────────────────────────────────────────────────
1888
+ registerNativeParticipationCommands(program);
1887
1889
  registerLayoutCommands(program, cOpt);
1888
1890
  registerTemplateCommands(program, cOpt);
1889
1891
  registerTaskCommands(program, cOpt);
@@ -0,0 +1,9 @@
1
+ import type { NativeMessage } from './application/native-conversation.js';
2
+ /** Read only the file named by thread/read, and verify its embedded thread ID. */
3
+ export declare function readCodexHistory(path: string, threadId: string): Promise<{
4
+ messages: NativeMessage[];
5
+ finished: {
6
+ clientId: string;
7
+ outcome: "completed" | "cancelled" | "failed";
8
+ }[];
9
+ }>;
@@ -0,0 +1,62 @@
1
+ import { open } from 'node:fs/promises';
2
+ import { constants } from 'node:fs';
3
+ import { createInterface } from 'node:readline';
4
+ /** Read only the file named by thread/read, and verify its embedded thread ID. */
5
+ export async function readCodexHistory(path, threadId) {
6
+ const file = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW);
7
+ const messages = new Map();
8
+ const clients = new Map();
9
+ const outcomes = new Map();
10
+ try {
11
+ const stat = await file.stat();
12
+ if (!stat.isFile() || stat.uid !== process.getuid?.())
13
+ throw Error('Native history must be a regular file owned by this user');
14
+ const lines = createInterface({ input: file.createReadStream(), crlfDelay: Infinity });
15
+ let first = true;
16
+ for await (const line of lines) {
17
+ if (!line)
18
+ continue;
19
+ let row;
20
+ try {
21
+ row = JSON.parse(line);
22
+ }
23
+ catch {
24
+ continue;
25
+ } // native writer may leave an incomplete final line
26
+ const p = row.payload;
27
+ if (first) {
28
+ first = false;
29
+ if (row.type !== 'session_meta' || p?.id !== threadId)
30
+ throw Error('Native history thread identity mismatch');
31
+ continue;
32
+ }
33
+ if (row.type !== 'event_msg')
34
+ continue;
35
+ if (p.type === 'task_complete')
36
+ outcomes.set(p.turn_id, 'completed');
37
+ if (p.type === 'turn_aborted')
38
+ outcomes.set(p.turn_id, 'cancelled');
39
+ if (p.type !== 'item_completed')
40
+ continue;
41
+ const item = p.item;
42
+ if (p.thread_id !== threadId || !item?.id || !['UserMessage', 'AgentMessage'].includes(item.type))
43
+ continue;
44
+ const text = (item.content ?? []).filter((b) => b.type === 'text' || b.type === 'Text').map((b) => b.text ?? '').join('\n');
45
+ if (!text)
46
+ continue;
47
+ messages.set(item.id, { id: item.id, role: item.type === 'UserMessage' ? 'user' : 'assistant', text, clientId: item.client_id, at: row.timestamp });
48
+ if (item.type === 'UserMessage' && item.client_id)
49
+ clients.set(p.turn_id, [...(clients.get(p.turn_id) ?? []), item.client_id]);
50
+ }
51
+ if (first)
52
+ throw Error('Native history has no session metadata');
53
+ const finished = [];
54
+ for (const [turn, outcome] of outcomes)
55
+ for (const clientId of clients.get(turn) ?? [])
56
+ finished.push({ clientId, outcome });
57
+ return { messages: [...messages.values()], finished };
58
+ }
59
+ finally {
60
+ await file.close().catch(() => { });
61
+ }
62
+ }
@@ -0,0 +1,25 @@
1
+ import { type NativeToolRead } from './native-participation.js';
2
+ export declare function validateCodexSocket(path: string): void;
3
+ export declare function withCodex<T>(path: string, run: (request: (method: string, params: object) => Promise<unknown>) => Promise<T>): Promise<T>;
4
+ export declare function listLoadedCodexThreads(path: string, metadata?: (id: string, value: {
5
+ title?: string;
6
+ cwd?: string;
7
+ }) => void): Promise<string[]>;
8
+ export declare function inspectCodexThread(path: string, threadId: string): Promise<'idle' | 'busy' | 'absent'>;
9
+ /**
10
+ * The thread's own Ours identity, read through its live MCP connection (the read-only
11
+ * current_identity tool). Fleet never opens or allocates the native attachment itself.
12
+ */
13
+ export declare function readCodexIdentity(path: string, threadId: string): Promise<{
14
+ text?: string;
15
+ error?: string;
16
+ }>;
17
+ /** One read-only Ours tool call on the thread's own MCP connection, bracketed by current_identity readbacks. */
18
+ export declare function readCodexOursTool(path: string, threadId: string, tool: string, args: object, expect: {
19
+ name: string;
20
+ cid: string;
21
+ }, allowed: () => boolean): Promise<NativeToolRead>;
22
+ /** Read-only verification through the target runtime's actual MCP connection. */
23
+ export declare function verifyCodexBinding(path: string, threadId: string, cid: string, name: string): Promise<boolean>;
24
+ export declare function cancelCodexWakes(path: string, threadId: string, grant: string, cid?: string): Promise<void>;
25
+ export declare function wakeCodexThread(path: string, threadId: string, wakeId: string): Promise<boolean>;
@@ -0,0 +1,237 @@
1
+ import { existsSync, lstatSync, mkdirSync, readFileSync, realpathSync } from 'node:fs';
2
+ import { createHash } from 'node:crypto';
3
+ import { dirname, isAbsolute, join, normalize } from 'node:path';
4
+ import WebSocket from 'ws';
5
+ import { nativeParticipationRoot, wakePrompt } from './native-participation.js';
6
+ import { atomicPrivateWrite } from './agent-ours/state.js';
7
+ export function validateCodexSocket(path) {
8
+ if (!isAbsolute(path) || normalize(path) !== path || path.includes(':')) {
9
+ throw new Error('Provide a normalized absolute Codex Unix socket path.');
10
+ }
11
+ const uid = process.getuid?.();
12
+ const entry = lstatSync(path);
13
+ const target = realpathSync(path);
14
+ const socket = lstatSync(target);
15
+ // Current Codex uses a private short-path socket and a symlink at --listen.
16
+ // Both entry and endpoint must be protected by their enclosing directories.
17
+ const privateParent = (endpoint) => {
18
+ const parent = lstatSync(dirname(endpoint));
19
+ return parent.isDirectory() && parent.uid === uid && !(parent.mode & 0o077);
20
+ };
21
+ if (uid === undefined || !socket.isSocket() || entry.uid !== uid || socket.uid !== uid
22
+ || !privateParent(path) || !privateParent(target)) {
23
+ throw new Error('The Codex Unix socket must be owned by this user in a private directory.');
24
+ }
25
+ }
26
+ // Requests are sequential and use a separate connection. The native TUI keeps
27
+ // handling input, interrupts, approvals and all server-initiated requests.
28
+ export async function withCodex(path, run) {
29
+ validateCodexSocket(path);
30
+ const socket = new WebSocket(`ws+unix://${path}:/`, { handshakeTimeout: 2500, maxPayload: 32 * 1024 * 1024 });
31
+ try {
32
+ await new Promise((resolve, reject) => {
33
+ socket.once('open', resolve);
34
+ socket.on('error', reject);
35
+ });
36
+ let nextId = 0;
37
+ async function request(method, params) {
38
+ const id = ++nextId;
39
+ return new Promise((resolve, reject) => {
40
+ function cleanup() {
41
+ clearTimeout(timeout);
42
+ socket.off('message', receive);
43
+ socket.off('close', closed);
44
+ }
45
+ function closed() {
46
+ cleanup();
47
+ reject(new Error('Codex App Server disconnected.'));
48
+ }
49
+ function receive(raw) {
50
+ let reply;
51
+ try {
52
+ reply = JSON.parse(String(raw));
53
+ }
54
+ catch {
55
+ return;
56
+ }
57
+ if (reply?.id !== id || reply.method)
58
+ return;
59
+ cleanup();
60
+ if (reply.error)
61
+ reject(new Error(reply.error.message ?? 'Codex App Server rejected the request.'));
62
+ else
63
+ resolve(reply.result);
64
+ }
65
+ const timeout = setTimeout(() => {
66
+ cleanup();
67
+ reject(new Error(`Codex App Server did not acknowledge ${method}.`));
68
+ }, 3500);
69
+ socket.on('message', receive);
70
+ socket.once('close', closed);
71
+ socket.send(JSON.stringify({ id, method, params }), (error) => {
72
+ if (error) {
73
+ cleanup();
74
+ reject(error);
75
+ }
76
+ });
77
+ });
78
+ }
79
+ await request('initialize', { clientInfo: { name: 'ours_fleet', version: '0.1.0' },
80
+ capabilities: { experimentalApi: true } });
81
+ socket.send(JSON.stringify({ method: 'initialized', params: {} }));
82
+ return await run(request);
83
+ }
84
+ finally {
85
+ socket.terminate();
86
+ }
87
+ }
88
+ async function loadedThreads(request) {
89
+ const ids = [];
90
+ let cursor = null;
91
+ do {
92
+ const page = await request('thread/loaded/list', { limit: 100, cursor });
93
+ ids.push(...page.data);
94
+ cursor = page.nextCursor;
95
+ } while (cursor);
96
+ return ids;
97
+ }
98
+ async function readThread(request, threadId) {
99
+ const { thread } = await request('thread/read', { threadId, includeTurns: false });
100
+ return thread;
101
+ }
102
+ function interactive(thread, threadId) {
103
+ // The stock TUI on the default daemon is classified as vscode by Codex 0.172.
104
+ // Skip exec/internal threads; separately verify this runtime's Ours integration.
105
+ return thread?.id === threadId && !thread.ephemeral
106
+ && (thread.source === 'cli' || thread.source === 'vscode');
107
+ }
108
+ async function hasOursIntegration(request, threadId) {
109
+ const result = await request('mcpServerStatus/list', {
110
+ threadId, serverName: 'ours', detail: 'toolsAndAuthOnly',
111
+ });
112
+ return result.data.some(server => server.name === 'ours' && server.runtimeStatus === 'connected'
113
+ && Object.hasOwn(server.tools, 'get_messages') && Object.hasOwn(server.tools, 'send_message'));
114
+ }
115
+ export async function listLoadedCodexThreads(path, metadata) {
116
+ return withCodex(path, async (request) => {
117
+ const ids = await loadedThreads(request);
118
+ const eligible = [];
119
+ for (const id of ids) {
120
+ try {
121
+ const thread = await readThread(request, id);
122
+ if (interactive(thread, id) && await hasOursIntegration(request, id)) {
123
+ await queued(request, id);
124
+ eligible.push(id);
125
+ metadata?.(id, { title: thread?.name ?? '', cwd: thread?.cwd });
126
+ }
127
+ }
128
+ catch (error) {
129
+ // Ignore a confirmed unload race, not a missing capability or bad reply.
130
+ if ((await loadedThreads(request)).includes(id))
131
+ throw error;
132
+ }
133
+ }
134
+ return eligible;
135
+ });
136
+ }
137
+ export async function inspectCodexThread(path, threadId) {
138
+ return withCodex(path, request => inspectThread(request, threadId));
139
+ }
140
+ /**
141
+ * The thread's own Ours identity, read through its live MCP connection (the read-only
142
+ * current_identity tool). Fleet never opens or allocates the native attachment itself.
143
+ */
144
+ export async function readCodexIdentity(path, threadId) {
145
+ return withCodex(path, async (request) => {
146
+ const result = await request('mcpServer/tool/call', {
147
+ threadId, server: 'ours', tool: 'current_identity', arguments: {},
148
+ });
149
+ const text = result.content?.find(item => item.type === 'text')?.text;
150
+ return result.isError ? { error: text ?? 'current_identity failed' } : { text };
151
+ });
152
+ }
153
+ /** One read-only Ours tool call on the thread's own MCP connection, bracketed by current_identity readbacks. */
154
+ export async function readCodexOursTool(path, threadId, tool, args, expect, allowed) {
155
+ return withCodex(path, async (request) => {
156
+ const call = async (name, value) => await request('mcpServer/tool/call', {
157
+ threadId, server: 'ours', tool: name, arguments: value,
158
+ });
159
+ const text = (result) => result.content?.find(item => item.type === 'text')?.text;
160
+ const before = text(await call('current_identity', {}));
161
+ // The read runs only while the thread is still bound to the participant's identity.
162
+ // ...and only while participation for it is still granted.
163
+ if (!before?.startsWith(`Bound to "${expect.name}" (${expect.cid})`) || !allowed())
164
+ return { before, result: { isError: true, content: [] } };
165
+ const result = await call(tool, args);
166
+ const after = text(await call('current_identity', {}));
167
+ return { before, result, after };
168
+ });
169
+ }
170
+ /** Read-only verification through the target runtime's actual MCP connection. */
171
+ export async function verifyCodexBinding(path, threadId, cid, name) {
172
+ return withCodex(path, async (request) => {
173
+ const result = await request('mcpServer/tool/call', {
174
+ threadId, server: 'ours', tool: 'current_identity', arguments: {},
175
+ });
176
+ return !result.isError && !!result.content?.some(item => item.type === 'text'
177
+ && item.text?.startsWith(`Bound to "${name}" (${cid})`));
178
+ });
179
+ }
180
+ async function inspectThread(request, threadId) {
181
+ if (!(await loadedThreads(request)).includes(threadId))
182
+ return 'absent';
183
+ const thread = await readThread(request, threadId);
184
+ if (!interactive(thread, threadId) || thread?.status?.type === 'notLoaded')
185
+ return 'absent';
186
+ return thread?.status?.type === 'idle' ? 'idle' : 'busy';
187
+ }
188
+ async function queued(request, threadId) {
189
+ const result = [];
190
+ let cursor = null;
191
+ do {
192
+ const page = await request('thread/queue/list', { threadId, cursor, limit: 100 });
193
+ result.push(...page.data);
194
+ cursor = page.nextCursor;
195
+ } while (cursor);
196
+ return result;
197
+ }
198
+ export async function cancelCodexWakes(path, threadId, grant, cid) {
199
+ await withCodex(path, async (request) => {
200
+ for (const item of await queued(request, threadId)) {
201
+ if (item.clientUserMessageId?.startsWith(`ours-fleet:${grant}:${threadId}:`) || (cid && item.clientUserMessageId?.startsWith(`ours-fleet-human:${cid}:`)))
202
+ await request('thread/queue/delete', { threadId, queuedSubmissionId: item.id });
203
+ }
204
+ });
205
+ }
206
+ export async function wakeCodexThread(path, threadId, wakeId) {
207
+ return withCodex(path, async (request) => {
208
+ if (await inspectThread(request, threadId) === 'absent')
209
+ return false;
210
+ const digest = createHash('sha256').update(JSON.stringify([path, threadId, wakeId])).digest('hex');
211
+ const receipt = join(nativeParticipationRoot(), 'codex-wakes', digest + '.json');
212
+ if (existsSync(receipt)) {
213
+ if (JSON.parse(readFileSync(receipt, 'utf8')).accepted)
214
+ return true;
215
+ if ((await queued(request, threadId)).some(item => item.clientUserMessageId === wakeId))
216
+ return true;
217
+ let cursor = null;
218
+ do {
219
+ const page = await request('thread/items/list', { threadId, cursor, limit: 100, sortDirection: 'desc' });
220
+ if (page.data.some(({ item }) => item.type === 'userMessage' && item.clientId === wakeId))
221
+ return true;
222
+ cursor = page.nextCursor;
223
+ } while (cursor);
224
+ // Queue correlation IDs are not idempotency keys. An uncertain submission
225
+ // must not be blindly repeated, which could start a duplicate agent turn.
226
+ throw new Error('Codex wake acknowledgment is uncertain; waiting for queue/history reconciliation.');
227
+ }
228
+ // Verify support before persisting a submission intent.
229
+ await queued(request, threadId);
230
+ mkdirSync(dirname(receipt), { recursive: true, mode: 0o700 });
231
+ atomicPrivateWrite(receipt, { accepted: false });
232
+ await request('thread/queue/add', { threadId, clientUserMessageId: wakeId,
233
+ input: [{ type: 'text', text: wakePrompt, text_elements: [] }] });
234
+ atomicPrivateWrite(receipt, { accepted: true });
235
+ return true;
236
+ });
237
+ }
@@ -0,0 +1,62 @@
1
+ import { Command } from 'commander';
2
+ export declare function claudeNativeHooks(executable: string, entry: string): {
3
+ hooks: {
4
+ SessionStart: {
5
+ hooks: ({
6
+ asyncRewake: true;
7
+ timeout: number;
8
+ type: string;
9
+ command: string;
10
+ args: string[];
11
+ } | {
12
+ timeout: number;
13
+ type: string;
14
+ command: string;
15
+ args: string[];
16
+ })[];
17
+ }[];
18
+ Stop: {
19
+ hooks: ({
20
+ asyncRewake: true;
21
+ timeout: number;
22
+ type: string;
23
+ command: string;
24
+ args: string[];
25
+ } | {
26
+ timeout: number;
27
+ type: string;
28
+ command: string;
29
+ args: string[];
30
+ })[];
31
+ }[];
32
+ SessionEnd: {
33
+ hooks: ({
34
+ asyncRewake: true;
35
+ timeout: number;
36
+ type: string;
37
+ command: string;
38
+ args: string[];
39
+ } | {
40
+ timeout: number;
41
+ type: string;
42
+ command: string;
43
+ args: string[];
44
+ })[];
45
+ }[];
46
+ UserPromptSubmit: {
47
+ hooks: ({
48
+ asyncRewake: true;
49
+ timeout: number;
50
+ type: string;
51
+ command: string;
52
+ args: string[];
53
+ } | {
54
+ timeout: number;
55
+ type: string;
56
+ command: string;
57
+ args: string[];
58
+ })[];
59
+ }[];
60
+ };
61
+ };
62
+ export declare function registerNativeParticipationCommands(program: Command): void;