@ours.network/fleet 2.4.2 → 2.4.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/contrib/.claude-plugin/marketplace.json +1 -1
- package/contrib/claude-native/hooks/register.js +101 -124
- package/dist/application/fleet-query-service.js +2 -2
- package/dist/application/native-claude-conversation.js +13 -2
- package/dist/application/native-codex-conversation.d.ts +1 -1
- package/dist/application/native-codex-conversation.js +9 -5
- package/dist/application/native-conversation.d.ts +5 -0
- package/dist/application/native-conversation.js +30 -5
- package/dist/application/native-conversations.d.ts +3 -0
- package/dist/application/native-conversations.js +2 -0
- package/dist/build-info.json +4 -4
- package/dist/native-codex-wake.d.ts +0 -14
- package/dist/native-codex-wake.js +0 -30
- package/dist/native-participation-cli.js +86 -107
- package/dist/native-participation.d.ts +173 -56
- package/dist/native-participation.js +159 -212
- package/dist/web/runtime.js +21 -0
- package/docs/native-session-participation.md +35 -45
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"ours-fleet
|
|
1
|
+
{"name":"ours-fleet","owner":{"name":"ours.network"},"plugins":[{"name":"ours-fleet-native","source":"./claude-native","description":"Shared native Human conversation with local Fleet"}]}
|
|
@@ -1,159 +1,136 @@
|
|
|
1
|
+
// Event-driven bridge between this Claude session and the local Ours Fleet.
|
|
2
|
+
//
|
|
3
|
+
// Nothing runs on a timer. One long-lived `claude-watch` child per session says "input" when the App queues a
|
|
4
|
+
// prompt (and keeps Fleet's heartbeat); the one-shot `claude-bridge` exchange runs only when something
|
|
5
|
+
// happened: the session started or joined, a turn started or ended, a message was appended, or input arrived.
|
|
6
|
+
|
|
7
|
+
let launcher = null;
|
|
1
8
|
let polling = false;
|
|
2
|
-
|
|
3
|
-
let
|
|
9
|
+
let again = false;
|
|
10
|
+
let turnActive = false;
|
|
4
11
|
let submitting = null;
|
|
5
12
|
let active = null;
|
|
6
13
|
let activeTurn = null;
|
|
14
|
+
let lastFailure = null;
|
|
7
15
|
const correlations = {};
|
|
8
16
|
const finished = [];
|
|
9
17
|
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (!/no connected MCP/.test(error)) break;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return { isError: true, content: [{ type: 'text', text: error }] };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* One read-only Ours tool the Fleet App asked for, run on this session's own MCP only while current_identity
|
|
32
|
-
* still shows the participant's identity, and read again afterwards.
|
|
33
|
-
*/
|
|
34
|
-
async function answer($, request) {
|
|
35
|
-
const identity = async () => (await oursCall($, 'current_identity', {}))?.content?.find(item => item.type === 'text')?.text;
|
|
36
|
-
const before = await identity();
|
|
37
|
-
const expected = request.expect;
|
|
38
|
-
if (typeof expected?.name !== 'string' || typeof expected?.cid !== 'string' || !before?.startsWith(`Bound to "${expected.name}" (${expected.cid})`))
|
|
39
|
-
return { id: request.id, value: { before, result: { isError: true, content: [] } } };
|
|
40
|
-
const result = await oursCall($, request.tool, request.arguments ?? {});
|
|
41
|
-
const after = await identity();
|
|
42
|
-
return { id: request.id, value: { before, result: { isError: !!result?.isError, content: result?.content }, after } };
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// One App read at a time, off the pulse, so normal input and state keep flowing. A failed read only
|
|
46
|
-
// fails that request (the App reports it); it never stops this session's participation.
|
|
47
|
-
const ANSWER_LIMIT = 900 * 1024; // under the bridge's 1 MiB input cap
|
|
48
|
-
let reading = false;
|
|
49
|
-
// A failure produced here, not by the Ours tool; Fleet shows it only while consent still holds.
|
|
50
|
-
function failed(request, before, text) {
|
|
51
|
-
return { id: request.id, value: { before, local: true, result: { isError: true, content: [{ type: 'text', text }] } } };
|
|
52
|
-
}
|
|
53
|
-
function serve($, bridge, request) {
|
|
54
|
-
if (reading || !['list_contacts', 'list_history'].includes(request?.tool)) return;
|
|
55
|
-
reading = true;
|
|
56
|
-
(async () => {
|
|
57
|
-
let reply;
|
|
58
|
-
try { reply = await answer($, request); }
|
|
59
|
-
catch (error) { reply = failed(request, undefined, `the read could not run in this session (${error?.message ?? error})`); }
|
|
60
|
-
if (JSON.stringify(reply).length > ANSWER_LIMIT)
|
|
61
|
-
reply = failed(request, reply.value.before, 'the result is too large to hand to Fleet; request a smaller history page');
|
|
62
|
-
// Exactly one answer; a failed handoff is reported by the App's own deadline, never resent.
|
|
63
|
-
try { await bridge({ reads: [reply] }); } catch {}
|
|
64
|
-
})().finally(() => { reading = false; });
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
async function currentIdentity($) {
|
|
68
|
-
let error = 'no connected Ours MCP server in this session';
|
|
69
|
-
for (const server of OURS_SERVERS) {
|
|
70
|
-
try {
|
|
71
|
-
const result = await $.mcp.call(server, 'current_identity', {});
|
|
72
|
-
oursServer = server;
|
|
73
|
-
const text = result?.content?.find(item => item.type === 'text')?.text;
|
|
74
|
-
return result?.isError ? { error: text ?? 'current_identity failed' } : { text };
|
|
75
|
-
} catch (failure) {
|
|
76
|
-
if (!/no connected MCP/.test(String(failure?.message ?? failure))) return { error: String(failure?.message ?? failure) };
|
|
18
|
+
// Run Fleet with the absolute Node and entry its participation hook was installed with. The session's PATH may
|
|
19
|
+
// resolve another `node` (an older system one) that Fleet refuses, which made every bridge call exit 1.
|
|
20
|
+
async function fleet($) {
|
|
21
|
+
if (launcher) return launcher;
|
|
22
|
+
const hooks = await $.settings.read({ key: 'hooks' }).catch(() => undefined);
|
|
23
|
+
for (const entries of Object.values(hooks ?? {})) {
|
|
24
|
+
for (const entry of Array.isArray(entries) ? entries : []) {
|
|
25
|
+
for (const hook of Array.isArray(entry?.hooks) ? entry.hooks : []) {
|
|
26
|
+
if (hook?.type === 'command' && typeof hook.command === 'string' && Array.isArray(hook.args)
|
|
27
|
+
&& hook.args.length === 3 && hook.args[1] === 'participation' && hook.args[2] === 'hook') {
|
|
28
|
+
launcher = [hook.command, hook.args[0]];
|
|
29
|
+
return launcher;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
77
32
|
}
|
|
78
33
|
}
|
|
79
|
-
|
|
34
|
+
launcher = ['ours-fleet'];
|
|
35
|
+
return launcher;
|
|
80
36
|
}
|
|
81
37
|
|
|
82
|
-
function
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
let response;
|
|
89
|
-
try { response = await run(); } catch (error) { stop($, `the Fleet bridge could not run (${error?.message ?? error})`); return undefined; }
|
|
90
|
-
if (response.exitCode !== 0) {
|
|
91
|
-
const detail = String(response.stderr ?? '').trim().split('\n').at(-1) || `exit code ${response.exitCode}`;
|
|
92
|
-
stop($, `the Fleet bridge failed (${detail})`);
|
|
93
|
-
return undefined;
|
|
94
|
-
}
|
|
95
|
-
try { return JSON.parse(response.stdout); } catch { stop($, 'the Fleet bridge returned an unreadable reply'); return undefined; }
|
|
38
|
+
function failed($, text) {
|
|
39
|
+
const reason = String(text ?? '').trim().split('\n').filter(Boolean).at(-1) || 'no detail';
|
|
40
|
+
// One visible line per distinct failure; every occurrence goes to the debug log.
|
|
41
|
+
$.ui.log(`Ours Fleet bridge: ${reason}`, { to: 'debug' });
|
|
42
|
+
if (reason !== lastFailure) $.ui.log(`Ours Fleet could not exchange state with this session: ${reason}`);
|
|
43
|
+
lastFailure = reason;
|
|
96
44
|
}
|
|
97
45
|
|
|
98
46
|
async function pulse($) {
|
|
99
|
-
if (polling
|
|
47
|
+
if (polling) { again = true; return; }
|
|
100
48
|
polling = true;
|
|
101
49
|
try {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
});
|
|
50
|
+
do {
|
|
51
|
+
again = false;
|
|
52
|
+
const id = await $.session.id();
|
|
53
|
+
const info = await $.session.info();
|
|
54
|
+
const tail = await $.session.messages({ last: 1 });
|
|
55
|
+
if (!Array.isArray(tail)) return;
|
|
56
|
+
const ready = !turnActive && submitting === null && active === null;
|
|
57
|
+
const response = await $.process.run([...await fleet($), 'participation', 'claude-bridge', id], {
|
|
58
|
+
stdin: JSON.stringify({ transcriptPath: info.transcriptPath, lastMessageId: tail.at(-1)?.uuid ?? null,
|
|
59
|
+
status: turnActive ? 'busy' : 'idle', correlations, finished, ready }),
|
|
60
|
+
timeoutMs: 10000,
|
|
61
|
+
});
|
|
62
|
+
if (response.exitCode !== 0) { failed($, response.stderr || `exit code ${response.exitCode}`); return; }
|
|
63
|
+
lastFailure = null;
|
|
64
|
+
const command = JSON.parse(response.stdout).command;
|
|
65
|
+
if (!command || submitting !== null || active !== null) continue;
|
|
66
|
+
submitting = command.clientId;
|
|
67
|
+
// Never claim terminal-local consent. The authenticated App Human supplies
|
|
68
|
+
// these words; Claude keeps the plugin origin and its own native controls.
|
|
69
|
+
$.prompt.submit({ text: command.text, asUser: true }).then(result => {
|
|
70
|
+
if (result?.drop) { finished.push({ clientId: command.clientId, outcome: 'cancelled' }); void pulse($); }
|
|
71
|
+
submitting = null;
|
|
72
|
+
}, () => {
|
|
73
|
+
finished.push({ clientId: command.clientId, outcome: 'failed' });
|
|
74
|
+
submitting = null;
|
|
75
|
+
void pulse($);
|
|
76
|
+
});
|
|
77
|
+
} while (again);
|
|
131
78
|
} catch (error) {
|
|
132
|
-
|
|
79
|
+
failed($, error?.message ?? error);
|
|
133
80
|
} finally { polling = false; }
|
|
134
81
|
}
|
|
135
82
|
|
|
83
|
+
async function watch($) {
|
|
84
|
+
const id = await $.session.id();
|
|
85
|
+
const child = $.process.spawn({ argv: [...await fleet($), 'participation', 'claude-watch', id] });
|
|
86
|
+
let buffer = '';
|
|
87
|
+
for await (const piece of child) {
|
|
88
|
+
if (piece.stream === 'stderr') { failed($, piece.text); continue; }
|
|
89
|
+
if (piece.stream !== 'stdout') continue;
|
|
90
|
+
buffer += piece.text;
|
|
91
|
+
for (let end; (end = buffer.indexOf('\n')) >= 0;) {
|
|
92
|
+
const line = buffer.slice(0, end).trim();
|
|
93
|
+
buffer = buffer.slice(end + 1);
|
|
94
|
+
if (line === 'joined' || line === 'input') void pulse($);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
136
99
|
export function register(on) {
|
|
137
|
-
on('session.start', ($, e, next) => {
|
|
138
|
-
|
|
139
|
-
|
|
100
|
+
on('session.start', async ($, e, next) => {
|
|
101
|
+
const started = await next(e);
|
|
102
|
+
if (e.isInteractive) {
|
|
103
|
+
void pulse($);
|
|
104
|
+
void watch($).catch(error => failed($, `the Fleet watcher stopped (${error?.message ?? error})`));
|
|
105
|
+
}
|
|
106
|
+
return started;
|
|
140
107
|
});
|
|
141
108
|
on('session.append', ($, e, next) => {
|
|
142
109
|
if (submitting && e.agentId === undefined && e.message.type === 'user' && e.origin.kind === 'plugin' && e.origin.name === 'ours-fleet-native') {
|
|
143
110
|
correlations[e.uuid] = submitting;
|
|
144
111
|
active = submitting;
|
|
145
112
|
}
|
|
146
|
-
|
|
113
|
+
const result = next(e);
|
|
114
|
+
if (e.agentId === undefined) void pulse($);
|
|
115
|
+
return result;
|
|
147
116
|
});
|
|
148
117
|
on('turn.start', ($, e, next) => {
|
|
149
|
-
if (e.agentId === undefined
|
|
118
|
+
if (e.agentId === undefined) {
|
|
119
|
+
turnActive = true;
|
|
120
|
+
if (active && activeTurn === null) activeTurn = e.turnId;
|
|
121
|
+
void pulse($);
|
|
122
|
+
}
|
|
150
123
|
return next(e);
|
|
151
124
|
});
|
|
152
125
|
on('turn.complete', ($, e, next) => {
|
|
153
|
-
if (e.agentId === undefined
|
|
154
|
-
|
|
155
|
-
active
|
|
156
|
-
|
|
126
|
+
if (e.agentId === undefined) {
|
|
127
|
+
turnActive = false;
|
|
128
|
+
if (active && activeTurn === e.turnId) {
|
|
129
|
+
finished.push({ clientId: active, outcome: e.reason === 'aborted' ? 'cancelled' : e.reason === 'answer' ? 'completed' : 'failed' });
|
|
130
|
+
active = null;
|
|
131
|
+
activeTurn = null;
|
|
132
|
+
}
|
|
133
|
+
void pulse($);
|
|
157
134
|
}
|
|
158
135
|
return next(e);
|
|
159
136
|
});
|
|
@@ -207,9 +207,9 @@ export class FleetQueryService {
|
|
|
207
207
|
};
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
|
+
// The App shows the harness (Claude Code, Codex) from config.harness, so the name carries only the session.
|
|
210
211
|
function nativeParticipantLabel(row) {
|
|
211
|
-
|
|
212
|
-
return row.title?.trim() ? `${clean(row.title, 160)} · ${harness}` : `${harness} · ${row.cwd ? clean(basename(row.cwd), 160) : 'Session'}`;
|
|
212
|
+
return row.title?.trim() ? clean(row.title, 160) : row.cwd ? clean(basename(row.cwd), 160) : 'Terminal session';
|
|
213
213
|
}
|
|
214
214
|
function nativeParticipantView(row, label) {
|
|
215
215
|
return {
|
|
@@ -77,8 +77,19 @@ export class NativeClaudeConversation {
|
|
|
77
77
|
}
|
|
78
78
|
commands() { if (!existsSync(this.directory))
|
|
79
79
|
return []; return readdirSync(this.directory).filter(n => /^input-[a-f0-9]+\.json$/.test(n)).map(n => JSON.parse(readFileSync(join(this.directory, n), 'utf8'))).sort((a, b) => a.sequence - b.sequence); }
|
|
80
|
-
async submit(text, clientId) {
|
|
81
|
-
|
|
80
|
+
async submit(text, clientId) {
|
|
81
|
+
const state = this.snapshot();
|
|
82
|
+
// The plugin's long-lived watcher keeps alive.json fresh; state.json changes only on session events.
|
|
83
|
+
let alive = 0;
|
|
84
|
+
try {
|
|
85
|
+
alive = Number(JSON.parse(readFileSync(join(this.directory, 'alive.json'), 'utf8')).at) || 0;
|
|
86
|
+
}
|
|
87
|
+
catch { }
|
|
88
|
+
if (Date.now() - Math.max(state.at, alive) > 15000)
|
|
89
|
+
throw new FleetError('capability_unavailable', 'The ours-fleet-native plugin is not running in this Claude session. Restart or resume the session in the terminal to send it input from the App.');
|
|
90
|
+
this.guard();
|
|
91
|
+
await withFileLock(join(this.directory, 'input.lock'), () => { this.guard(); const sequence = Math.max(0, ...this.commands().map(row => row.sequence)) + 1; atomicPrivateWrite(join(this.directory, 'input-' + createHash('sha256').update(clientId).digest('hex') + '.json'), { text, clientId, sequence }); });
|
|
92
|
+
}
|
|
82
93
|
async pulse(state) {
|
|
83
94
|
this.guard();
|
|
84
95
|
mkdirSync(this.directory, { recursive: true, mode: 0o700 });
|
|
@@ -12,7 +12,7 @@ export declare class NativeCodexConversation implements NativeConversationTransp
|
|
|
12
12
|
queued: string[];
|
|
13
13
|
finished: {
|
|
14
14
|
clientId: string;
|
|
15
|
-
outcome: "
|
|
15
|
+
outcome: "completed" | "cancelled" | "failed";
|
|
16
16
|
}[];
|
|
17
17
|
status: "idle" | "busy";
|
|
18
18
|
}>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readCodexHistory } from '../native-codex-history.js';
|
|
1
2
|
import { withCodex, verifyCodexBinding } from '../native-codex-wake.js';
|
|
2
3
|
import { FleetError } from './errors.js';
|
|
3
4
|
/** Uses only read/queue RPCs: the native terminal remains the controlling client. */
|
|
@@ -18,14 +19,17 @@ export class NativeCodexConversation {
|
|
|
18
19
|
this.guard();
|
|
19
20
|
return withCodex(this.socket, async (request) => {
|
|
20
21
|
let loaded;
|
|
22
|
+
let fallback;
|
|
21
23
|
try {
|
|
22
24
|
loaded = await request('thread/read', { threadId: this.threadId, includeTurns: true });
|
|
23
25
|
}
|
|
24
26
|
catch (error) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
if (!/list_turns is not supported/.test(String(error)))
|
|
28
|
+
throw error;
|
|
29
|
+
loaded = await request('thread/read', { threadId: this.threadId, includeTurns: false });
|
|
30
|
+
if (!loaded.thread.path)
|
|
31
|
+
throw new FleetError('capability_unavailable', 'Native history path is unavailable');
|
|
32
|
+
fallback = await readCodexHistory(loaded.thread.path, this.threadId);
|
|
29
33
|
}
|
|
30
34
|
const messages = [];
|
|
31
35
|
let cursor = null;
|
|
@@ -53,7 +57,7 @@ export class NativeCodexConversation {
|
|
|
53
57
|
this.guard();
|
|
54
58
|
if (loaded.thread.status.type === 'notLoaded')
|
|
55
59
|
throw new FleetError('role_not_found', 'Native runtime is unloaded');
|
|
56
|
-
return { messages, queued, finished, status: loaded.thread.status.type === 'idle' ? 'idle' : 'busy' };
|
|
60
|
+
return { messages: fallback?.messages ?? messages, queued, finished: fallback?.finished ?? finished, status: loaded.thread.status.type === 'idle' ? 'idle' : 'busy' };
|
|
57
61
|
});
|
|
58
62
|
}
|
|
59
63
|
async submit(text, clientId) {
|
|
@@ -41,6 +41,9 @@ export declare class NativeConversation implements RoleSessionControl {
|
|
|
41
41
|
private store;
|
|
42
42
|
private generation;
|
|
43
43
|
private seen;
|
|
44
|
+
/** Ledger time of each native message, and the latest time in the ledger. */
|
|
45
|
+
private times;
|
|
46
|
+
private lastAt;
|
|
44
47
|
private commands;
|
|
45
48
|
private completed;
|
|
46
49
|
private nativeState;
|
|
@@ -56,6 +59,8 @@ export declare class NativeConversation implements RoleSessionControl {
|
|
|
56
59
|
private commandPath;
|
|
57
60
|
private assertConnected;
|
|
58
61
|
private state;
|
|
62
|
+
private nativeAt;
|
|
63
|
+
private append;
|
|
59
64
|
private changed;
|
|
60
65
|
describe(): Promise<{
|
|
61
66
|
backend: "acp" | "codex-app-server";
|
|
@@ -13,6 +13,9 @@ export class NativeConversation {
|
|
|
13
13
|
store;
|
|
14
14
|
generation;
|
|
15
15
|
seen = new Map();
|
|
16
|
+
/** Ledger time of each native message, and the latest time in the ledger. */
|
|
17
|
+
times = new Map();
|
|
18
|
+
lastAt = '';
|
|
16
19
|
commands = new Map();
|
|
17
20
|
completed = new Set();
|
|
18
21
|
nativeState = { status: 'idle', messages: [], queued: [] };
|
|
@@ -31,8 +34,12 @@ export class NativeConversation {
|
|
|
31
34
|
for (let after;;) {
|
|
32
35
|
const page = this.store.page({ after, limit: 1000 });
|
|
33
36
|
for (const event of page.events) {
|
|
34
|
-
if (event.
|
|
37
|
+
if (event.at > this.lastAt)
|
|
38
|
+
this.lastAt = event.at;
|
|
39
|
+
if (event.messageId?.startsWith('native:')) {
|
|
35
40
|
this.seen.set(event.messageId, JSON.stringify(event.payload));
|
|
41
|
+
this.times.set(event.messageId, event.at);
|
|
42
|
+
}
|
|
36
43
|
if (event.kind === 'turn.completed' && event.promptId)
|
|
37
44
|
this.completed.add(event.promptId);
|
|
38
45
|
}
|
|
@@ -57,6 +64,24 @@ export class NativeConversation {
|
|
|
57
64
|
pendingPrompts: pending.map(c => ({ promptId: c.receipt.promptId, source: 'owner_admin_console', admittedAt: c.receipt.acceptedAt, bytes: 0 })),
|
|
58
65
|
pendingPromptCount: pending.length, activePromptIds: active.map(c => c.receipt.promptId), ...(this.failed ? { observationFailure: 'capture_failed' } : {}) };
|
|
59
66
|
}
|
|
67
|
+
// Apps order the conversation by event time. Native clocks are coarser than the ledger's (Codex reports a
|
|
68
|
+
// turn's start in whole seconds), so a reply could carry a time before the prompt admitted for it. A native
|
|
69
|
+
// message keeps the time it was first recorded with, and a new one is never placed before the ledger's end.
|
|
70
|
+
nativeAt(messageId, at) {
|
|
71
|
+
const known = this.times.get(messageId);
|
|
72
|
+
if (known)
|
|
73
|
+
return known;
|
|
74
|
+
const parsed = at && !Number.isNaN(Date.parse(at)) ? new Date(at).toISOString() : new Date().toISOString();
|
|
75
|
+
return parsed > this.lastAt ? parsed : new Date(Date.parse(this.lastAt) + 1).toISOString();
|
|
76
|
+
}
|
|
77
|
+
append(draft) {
|
|
78
|
+
const event = this.store.append(draft);
|
|
79
|
+
if (event.at > this.lastAt)
|
|
80
|
+
this.lastAt = event.at;
|
|
81
|
+
if (event.messageId?.startsWith('native:'))
|
|
82
|
+
this.times.set(event.messageId, event.at);
|
|
83
|
+
return event;
|
|
84
|
+
}
|
|
60
85
|
changed() { this.revision++; for (const listener of this.listeners)
|
|
61
86
|
listener(this.state()); }
|
|
62
87
|
async describe() { return { backend: this.options.harness === 'codex' ? 'codex-app-server' : 'acp', protocolVersion: 3, features: ['conversation_v3', 'conversation_live_complete', ...(this.options.correspondence ? ['agent_correspondence'] : [])], snapshot: await this.snapshot() }; }
|
|
@@ -84,8 +109,8 @@ export class NativeConversation {
|
|
|
84
109
|
const digest = JSON.stringify(payload);
|
|
85
110
|
if (this.seen.get(messageId) === digest)
|
|
86
111
|
continue;
|
|
87
|
-
this.
|
|
88
|
-
source: message.role === 'user' ? 'local_console' : 'agent', ...
|
|
112
|
+
this.append({ sessionGeneration: this.generation, kind: 'message.replace', messageId,
|
|
113
|
+
source: message.role === 'user' ? 'local_console' : 'agent', ...{ at: this.nativeAt(messageId, message.at) }, payload });
|
|
89
114
|
this.seen.set(messageId, digest);
|
|
90
115
|
}
|
|
91
116
|
for (const command of this.commands.values()) {
|
|
@@ -99,7 +124,7 @@ export class NativeConversation {
|
|
|
99
124
|
atomicPrivateWrite(this.commandPath(command.receipt.commandId), command);
|
|
100
125
|
}
|
|
101
126
|
if (finished) {
|
|
102
|
-
this.
|
|
127
|
+
this.append({ sessionGeneration: this.generation, kind: 'turn.completed', promptId: command.receipt.promptId, payload: { outcome: finished.outcome } });
|
|
103
128
|
this.completed.add(command.receipt.promptId);
|
|
104
129
|
}
|
|
105
130
|
}
|
|
@@ -135,7 +160,7 @@ export class NativeConversation {
|
|
|
135
160
|
throw new FleetError('capability_unavailable', 'History is available; load the Ours native Claude plugin to send input to this session');
|
|
136
161
|
// Finish any concurrent history capture before admitting a send, so its outgoing row cannot race the receipt.
|
|
137
162
|
const promptId = randomUUID();
|
|
138
|
-
const event = this.
|
|
163
|
+
const event = this.append({ sessionGeneration: this.generation, kind: 'prompt.admitted', promptId, commandId: request.commandId, source: 'owner_admin_console', actor: { browserSession: request.actorBrowserSession }, payload: { text: textBlock(request.text), queuedBehind: 0 } });
|
|
139
164
|
const receipt = { commandId: request.commandId, promptId, state: 'queued', queuedBehind: 0, acceptedAt: event.at, eventCursor: String(event.seq), sessionGeneration: this.generation };
|
|
140
165
|
const clientId = `ours-fleet-human:${this.options.cid}:${request.commandId}`;
|
|
141
166
|
const command = { digest, receipt, status: 'intent', clientId };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { NativeParticipation } from '../native-participation.js';
|
|
1
2
|
import { NativeConversation } from './native-conversation.js';
|
|
2
3
|
import type { ConversationRoleObservation, ConversationRoleState } from './conversation-role-observer.js';
|
|
3
4
|
/** The web process owns projections, while native participation remains the authority for membership. */
|
|
@@ -15,5 +16,7 @@ export declare class NativeConversations {
|
|
|
15
16
|
}[];
|
|
16
17
|
session(id: string): Promise<NativeConversation | undefined>;
|
|
17
18
|
observe(id: string, listener: (state: ConversationRoleState) => void): ConversationRoleObservation;
|
|
19
|
+
/** The App's agent tools for a native participant, or undefined when the role is not one. */
|
|
20
|
+
oursTools(id: string): Promise<NativeParticipation | undefined>;
|
|
18
21
|
close(): void;
|
|
19
22
|
}
|
|
@@ -69,6 +69,8 @@ export class NativeConversations {
|
|
|
69
69
|
timer.unref();
|
|
70
70
|
return { snapshot: () => ({ ...state }), subscribe(fn) { listeners.add(fn); return { snapshot: { ...state }, unsubscribe: () => { listeners.delete(fn); } }; }, dispose() { clearInterval(timer); listeners.clear(); } };
|
|
71
71
|
}
|
|
72
|
+
/** The App's agent tools for a native participant, or undefined when the role is not one. */
|
|
73
|
+
async oursTools(id) { await this.initialize(); return this.list().some(row => row.name === id) ? this.registry : undefined; }
|
|
72
74
|
close() { for (const session of this.sessions.values())
|
|
73
75
|
session.close(); this.sessions.clear(); }
|
|
74
76
|
}
|
package/dist/build-info.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.4.
|
|
3
|
-
"buildId": "
|
|
4
|
-
"commit": "
|
|
2
|
+
"version": "2.4.4",
|
|
3
|
+
"buildId": "45f2ae97be18",
|
|
4
|
+
"commit": "cce2988302e1e4208b0652eb1c50ff18490b6c2c",
|
|
5
5
|
"dirty": false,
|
|
6
|
-
"builtAt": "2026-12-
|
|
6
|
+
"builtAt": "2026-12-03T10:50:48.794Z",
|
|
7
7
|
"capabilities": [
|
|
8
8
|
"service.refresh-v1",
|
|
9
9
|
"managed-cli.codex-reasoning-effort-v1",
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type NativeToolRead } from './native-participation.js';
|
|
2
1
|
export declare function validateCodexSocket(path: string): void;
|
|
3
2
|
export declare function withCodex<T>(path: string, run: (request: (method: string, params: object) => Promise<unknown>) => Promise<T>): Promise<T>;
|
|
4
3
|
export declare function listLoadedCodexThreads(path: string, metadata?: (id: string, value: {
|
|
@@ -6,19 +5,6 @@ export declare function listLoadedCodexThreads(path: string, metadata?: (id: str
|
|
|
6
5
|
cwd?: string;
|
|
7
6
|
}) => void): Promise<string[]>;
|
|
8
7
|
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
8
|
/** Read-only verification through the target runtime's actual MCP connection. */
|
|
23
9
|
export declare function verifyCodexBinding(path: string, threadId: string, cid: string, name: string): Promise<boolean>;
|
|
24
10
|
export declare function cancelCodexWakes(path: string, threadId: string, grant: string, cid?: string): Promise<void>;
|
|
@@ -137,36 +137,6 @@ export async function listLoadedCodexThreads(path, metadata) {
|
|
|
137
137
|
export async function inspectCodexThread(path, threadId) {
|
|
138
138
|
return withCodex(path, request => inspectThread(request, threadId));
|
|
139
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
140
|
/** Read-only verification through the target runtime's actual MCP connection. */
|
|
171
141
|
export async function verifyCodexBinding(path, threadId, cid, name) {
|
|
172
142
|
return withCodex(path, async (request) => {
|