jaxon-agents 0.1.0 → 0.2.0
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 +39 -31
- package/README.zh-CN.md +42 -34
- package/dist/BUILD_INFO.json +3 -3
- package/dist/PACKAGE_MANIFEST.json +31 -25
- package/dist/RELEASE_META.json +8 -2
- package/dist/api/mcp-tools.js +5 -4
- package/dist/connections/health.js +4 -1
- package/dist/console/activity-client.js +620 -0
- package/dist/console/activity-page.js +24 -0
- package/dist/console/activity-topics.js +640 -0
- package/dist/console/activity.js +379 -0
- package/dist/console/assets.js +207 -16
- package/dist/console/pages.js +38 -17
- package/dist/console/server.js +51 -5
- package/dist/console/station-pages.js +40 -6
- package/dist/daemon/client.js +1 -1
- package/dist/daemon/host.js +2 -0
- package/dist/environment/pi-launch-spec.js +1 -1
- package/dist/ops/catalog.js +1 -0
- package/dist/ops/core.js +89 -35
- package/dist/pi-host/history-reader.js +20 -0
- package/dist/pi-host/mcp-bridge.entry.js +22 -5
- package/dist/sessions/dashboard-usage.js +5 -3
- package/dist/sessions/supervisor.js +391 -31
- package/dist/stations/cues.js +59 -48
- package/dist/stations/interactions.js +75 -0
- package/dist/stations/member-instructions.js +25 -0
- package/dist/stations/station-member.entry.js +6 -6
- package/package.json +8 -2
- package/runtime/provenance.json +3 -3
- package/runtime/runtime-lock.json +2 -2
- package/runtime/runtime-package.json +1 -1
package/dist/stations/cues.js
CHANGED
|
@@ -1,63 +1,74 @@
|
|
|
1
1
|
import * as fs from 'node:fs';
|
|
2
2
|
import * as path from 'node:path';
|
|
3
|
-
|
|
4
|
-
const MAX_PENDING = 20;
|
|
5
|
-
/** Station-scoped cue journal and the master's unread cue inbox. */
|
|
3
|
+
/** The journal is a read-only history for humans; the live inbox is session metadata. */
|
|
6
4
|
export class StationCueStore {
|
|
5
|
+
onChange;
|
|
7
6
|
root;
|
|
8
7
|
constructor(root) { this.root = root; }
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
writeMaster(ref, pending) {
|
|
20
|
-
fs.mkdirSync(this.directory(ref), { recursive: true, mode: 0o700 });
|
|
21
|
-
atomic(this.masterFile(ref), json(pending));
|
|
22
|
-
}
|
|
23
|
-
enqueueMaster(ref, cue) {
|
|
24
|
-
const pending = this.readMaster(ref);
|
|
25
|
-
pending.cues = pending.cues.filter((item) => item.from.session_id !== cue.from.session_id);
|
|
26
|
-
pending.cues.push(cue);
|
|
27
|
-
if (pending.cues.length > MAX_PENDING) {
|
|
28
|
-
const remove = pending.cues.length - MAX_PENDING;
|
|
29
|
-
pending.cues.splice(0, remove);
|
|
30
|
-
pending.dropped += remove;
|
|
8
|
+
logFile(ref) { return path.join(this.root, ref.station_id, 'cues.jsonl'); }
|
|
9
|
+
write(ref, row) {
|
|
10
|
+
const file = this.logFile(ref);
|
|
11
|
+
try {
|
|
12
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
13
|
+
fs.appendFileSync(file, JSON.stringify(row) + '\n', { mode: 0o600 });
|
|
14
|
+
this.onChange?.(ref.station_id);
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
console.error('Writing cue journal', ref.station_id, error);
|
|
31
18
|
}
|
|
32
|
-
this.writeMaster(ref, pending);
|
|
33
|
-
}
|
|
34
|
-
masterPending(ref) {
|
|
35
|
-
const pending = this.readMaster(ref);
|
|
36
|
-
return { count: pending.cues.length, from: [...new Set(pending.cues.map((cue) => cue.from.agent))] };
|
|
37
|
-
}
|
|
38
|
-
consumeMaster(ref) {
|
|
39
|
-
const pending = this.readMaster(ref);
|
|
40
|
-
if (pending.cues.length)
|
|
41
|
-
this.writeMaster(ref, { cues: [], dropped: 0 });
|
|
42
|
-
return pending;
|
|
43
|
-
}
|
|
44
|
-
append(ref, cue, to) {
|
|
45
|
-
fs.mkdirSync(this.directory(ref), { recursive: true, mode: 0o700 });
|
|
46
|
-
fs.appendFileSync(this.logFile(ref), JSON.stringify({ ...cue, to }) + '\n', { mode: 0o600 });
|
|
47
19
|
}
|
|
20
|
+
append(ref, row) { this.write(ref, row); }
|
|
21
|
+
event(ref, row) { this.write(ref, row); }
|
|
48
22
|
list(ref, limit = 100) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
23
|
+
let content;
|
|
24
|
+
try {
|
|
25
|
+
content = fs.readFileSync(this.logFile(ref), 'utf8');
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
if (error.code === 'ENOENT')
|
|
54
29
|
return [];
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
const rows = [];
|
|
33
|
+
const events = new Map();
|
|
34
|
+
for (const line of content.split('\n')) {
|
|
35
|
+
if (!line)
|
|
36
|
+
continue;
|
|
37
|
+
let row;
|
|
55
38
|
try {
|
|
56
|
-
|
|
39
|
+
row = JSON.parse(line);
|
|
57
40
|
}
|
|
58
41
|
catch {
|
|
59
|
-
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (!row || typeof row !== 'object')
|
|
45
|
+
continue;
|
|
46
|
+
if ('from' in row && row.to)
|
|
47
|
+
rows.push(row);
|
|
48
|
+
else if ('cue_ids' in row && Array.isArray(row.cue_ids)) {
|
|
49
|
+
for (const id of row.cue_ids) {
|
|
50
|
+
const key = `${row.session_id}:${id}`;
|
|
51
|
+
const details = events.get(key) ?? {};
|
|
52
|
+
if ('woken_turn_id' in row)
|
|
53
|
+
details.woken_turn_id = row.woken_turn_id;
|
|
54
|
+
else if ('delivered_at' in row)
|
|
55
|
+
details.delivered_at = row.delivered_at;
|
|
56
|
+
else {
|
|
57
|
+
details.wake = row.wake;
|
|
58
|
+
details.error_code = row.error_code;
|
|
59
|
+
}
|
|
60
|
+
events.set(key, details);
|
|
61
|
+
}
|
|
60
62
|
}
|
|
61
|
-
}
|
|
63
|
+
}
|
|
64
|
+
return rows.slice(-limit).map(row => {
|
|
65
|
+
const event = events.get(`${row.to.session_id}:${row.cue_id}`);
|
|
66
|
+
if (!event)
|
|
67
|
+
return row;
|
|
68
|
+
if (!event.woken_turn_id)
|
|
69
|
+
return { ...row, ...event };
|
|
70
|
+
const { wake: _, error_code: __, ...delivery } = row;
|
|
71
|
+
return { ...delivery, ...event, delivery: 'woken' };
|
|
72
|
+
});
|
|
62
73
|
}
|
|
63
74
|
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { atomic } from "./station-store.js";
|
|
4
|
+
/** Small append-only master/member signal journal used only by the activity view. */
|
|
5
|
+
export class InteractionStore {
|
|
6
|
+
root;
|
|
7
|
+
writes = new Map();
|
|
8
|
+
reported = new Map();
|
|
9
|
+
onChange;
|
|
10
|
+
constructor(root) { this.root = root; }
|
|
11
|
+
file(ref) { return path.join(this.root, ref.station_id, 'interactions.jsonl'); }
|
|
12
|
+
key(sessionId, turnId) { return `${sessionId}\0${turnId}`; }
|
|
13
|
+
list(ref) {
|
|
14
|
+
const file = this.file(ref);
|
|
15
|
+
if (!fs.existsSync(file))
|
|
16
|
+
return [];
|
|
17
|
+
return fs.readFileSync(file, 'utf8').split('\n').flatMap((line) => {
|
|
18
|
+
if (!line)
|
|
19
|
+
return [];
|
|
20
|
+
try {
|
|
21
|
+
return [JSON.parse(line)];
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
compact(ref) {
|
|
29
|
+
if (!fs.existsSync(this.file(ref)))
|
|
30
|
+
return;
|
|
31
|
+
try {
|
|
32
|
+
const cutoff = Date.now() - 7 * 86_400_000;
|
|
33
|
+
const rows = this.list(ref).filter((row) => Date.parse(row.at) >= cutoff).slice(-20_000);
|
|
34
|
+
const body = rows.map((row) => JSON.stringify(row)).join('\n') + (rows.length ? '\n' : '');
|
|
35
|
+
fs.mkdirSync(path.dirname(this.file(ref)), { recursive: true, mode: 0o700 });
|
|
36
|
+
atomic(this.file(ref), body);
|
|
37
|
+
this.reported.set(ref.station_id, new Set(rows.filter((row) => row.kind === 'report' && row.turn_id)
|
|
38
|
+
.map((row) => this.key(row.session_id, row.turn_id))));
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
console.error('Compacting activity interactions', ref.station_id, error);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
append(ref, interaction) {
|
|
45
|
+
if (interaction.kind === 'report' && interaction.turn_id) {
|
|
46
|
+
const key = this.key(interaction.session_id, interaction.turn_id);
|
|
47
|
+
const seen = this.reported.get(ref.station_id) ?? new Set();
|
|
48
|
+
if (seen.has(key))
|
|
49
|
+
return;
|
|
50
|
+
if (!this.reported.has(ref.station_id)) {
|
|
51
|
+
for (const row of this.list(ref))
|
|
52
|
+
if (row.kind === 'report' && row.turn_id)
|
|
53
|
+
seen.add(this.key(row.session_id, row.turn_id));
|
|
54
|
+
}
|
|
55
|
+
if (seen.has(key)) {
|
|
56
|
+
this.reported.set(ref.station_id, seen);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
seen.add(key);
|
|
60
|
+
this.reported.set(ref.station_id, seen);
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
fs.mkdirSync(path.dirname(this.file(ref)), { recursive: true, mode: 0o700 });
|
|
64
|
+
fs.appendFileSync(this.file(ref), JSON.stringify(interaction) + '\n', { mode: 0o600 });
|
|
65
|
+
const count = (this.writes.get(ref.station_id) ?? 0) + 1;
|
|
66
|
+
this.writes.set(ref.station_id, count);
|
|
67
|
+
if (count % 1000 === 0)
|
|
68
|
+
this.compact(ref);
|
|
69
|
+
this.onChange?.(ref.station_id);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
console.error('Writing activity interaction', ref.station_id, error);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const cueGuidance = {
|
|
2
|
+
zh: '以 master 的裁决与方向为准。cue 是同事间的平级提醒,值得回应,但别被牵着走:回应写在你的看板上,只在对方确实需要知道时才回 cue;不要为回应 cue 来回循环,也不要偏离 master 已定的方向。有分歧时把分歧写在看板上,以 master 的判断为准;需要新任务时写在看板上,由 master 决定是否派单。',
|
|
3
|
+
en: "master's decisions and direction take precedence. A cue is a peer reminder: answer it, but don't be led by it. Reply on your board and cue back only when the peer actually needs to know; never loop on cues, and never drift from the direction master has set. If you disagree, record it on your board and defer to master; if new work seems needed, note it on your board and let master decide.",
|
|
4
|
+
};
|
|
5
|
+
/** The daemon locale selects the entire member block; Station content does not participate. */
|
|
6
|
+
export function stationMemberInstructions(agent, seat) {
|
|
7
|
+
const locale = process.env.LC_ALL || process.env.LC_MESSAGES || process.env.LANG || 'en';
|
|
8
|
+
if (/^zh(?:[-_.@]|$)/i.test(locale))
|
|
9
|
+
return [
|
|
10
|
+
seat ? `你是该 Station 的成员 ${agent}。下方已在 system 中自动注入 master 看板与你自己看板的当前全文,无需再调用 board_read(owner="master");`
|
|
11
|
+
: `你是该 Station 中 ${agent} 的独立会话。下方已在 system 中自动注入 master 看板与你们共用的角色看板,无需再调用 board_read(owner="master");`,
|
|
12
|
+
'你只能修改自己角色的看板(board_write),需要其他同事的看板时用 board_read。',
|
|
13
|
+
'需要同事知道的结论与指针先写在你的看板上,再发 cue;cue 的文字只用来说明为什么提醒,例如“评审意见已更新”。',
|
|
14
|
+
'同一角色可能还有其他会话,它们与你共用这块看板;写入前以最新内容为底,保留他人仍有效的结论。',
|
|
15
|
+
'', cueGuidance.zh,
|
|
16
|
+
].join('\n');
|
|
17
|
+
return [
|
|
18
|
+
seat ? `You are ${agent}, a member of this Station. The full current master board and your own board are already in the system prompt below; do not call board_read(owner="master") again.`
|
|
19
|
+
: `You are an independent session for ${agent} in this Station. The full current master board and your shared role board are already in the system prompt below; do not call board_read(owner="master") again.`,
|
|
20
|
+
'You can only update your own role board (board_write). Use board_read to read another member’s board.',
|
|
21
|
+
'Write conclusions and pointers on your board before sending a cue. The optional message only explains the reminder, for example “Review notes updated”.',
|
|
22
|
+
'Other sessions of the same role share this board. Before writing, use its latest content and preserve conclusions from peers that still apply.',
|
|
23
|
+
'', cueGuidance.en,
|
|
24
|
+
].join('\n');
|
|
25
|
+
}
|
|
@@ -59,18 +59,18 @@ function cueBlock(cues = [], dropped = 0) {
|
|
|
59
59
|
}
|
|
60
60
|
export default function stationMember(pi) {
|
|
61
61
|
pi.on('before_agent_start', async (event, ctx) => {
|
|
62
|
-
const { station, agent, session_id, seat = true, master_board, board, cues, dropped_cues } = await operation('member_context', {}, ctx.signal);
|
|
62
|
+
const { station, agent, session_id, seat = true, member_instructions, master_board, board, cues, dropped_cues } = await operation('member_context', {}, ctx.signal);
|
|
63
63
|
// An old daemon can load this extension before it has had a chance to restart.
|
|
64
64
|
const master = master_board ?? (await operation('board_read', { owner: 'master' }, ctx.signal)).board;
|
|
65
|
-
const instructions = [
|
|
65
|
+
const instructions = member_instructions ?? [
|
|
66
66
|
seat ? `你是该 Station 的成员 ${agent}。下方已在 system 中自动注入 master 看板与你自己看板的当前全文,无需再调用 board_read(owner="master");`
|
|
67
67
|
: `你是该 Station 中 ${agent} 的独立会话。下方已在 system 中自动注入 master 看板与你们共用的角色看板,无需再调用 board_read(owner="master");`,
|
|
68
68
|
'你只能修改自己角色的看板(board_write),需要其他同事的看板时用 board_read。',
|
|
69
69
|
'同一角色可能还有其他会话,它们与你共用这块看板;写入前以最新内容为底,保留他人仍有效的结论。',
|
|
70
|
-
'需要同事知道的结论与指针先写在你的看板上,再发 cue;cue
|
|
71
|
-
];
|
|
70
|
+
'需要同事知道的结论与指针先写在你的看板上,再发 cue;cue 的文字只用来说明为什么提醒,例如“评审意见已更新”。',
|
|
71
|
+
].join('\n');
|
|
72
72
|
const prompt = [station.description, `<station_member agent="${agent}" session="${session_id}" seat="${seat}">`,
|
|
73
|
-
|
|
73
|
+
instructions, '</station_member>', boardBlock('master_board', master), boardBlock('your_board', board), cueBlock(cues, dropped_cues)].filter(Boolean).join('\n');
|
|
74
74
|
return { systemPrompt: event.systemPrompt + '\n\n' + prompt };
|
|
75
75
|
});
|
|
76
76
|
const toolResult = (result) => ({ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], details: result });
|
|
@@ -82,7 +82,7 @@ export default function stationMember(pi) {
|
|
|
82
82
|
parameters: Type.Object({ content: Type.String(), expected_version: Type.Optional(Type.Integer({ minimum: 0 })) }, { additionalProperties: false }),
|
|
83
83
|
async execute(_id, params, signal) { return toolResult(await operation('board_write', params, signal)); },
|
|
84
84
|
});
|
|
85
|
-
pi.registerTool({ name: 'cue', label: 'Cue Station colleagues', description: 'Remind 1-8 roles
|
|
85
|
+
pi.registerTool({ name: 'cue', label: 'Cue Station colleagues', description: 'Remind 1-8 roles or member sessions to check boards. No text is preferred. Write conclusions and pointers on your board first, then cue; message is only an optional one-line reason (at most 100 Unicode characters). Cue wakes an idle colleague to align on the board; it does not dispatch work or interrupt a busy turn. The master is not a cue target; write on the board instead.',
|
|
86
86
|
parameters: Type.Object({ to: Type.Array(Type.String(), { minItems: 1, maxItems: 8, uniqueItems: true }), message: Type.Optional(Type.String()) }, { additionalProperties: false }),
|
|
87
87
|
async execute(_id, params, signal) { return toolResult(await operation('cue', params, signal)); },
|
|
88
88
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jaxon-agents",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"jaxon-agents": "dist/launcher.js"
|
|
@@ -36,7 +36,13 @@
|
|
|
36
36
|
},
|
|
37
37
|
"upgrade": {
|
|
38
38
|
"format": 1,
|
|
39
|
-
"from": [
|
|
39
|
+
"from": [
|
|
40
|
+
{
|
|
41
|
+
"id": "from-0-1-0",
|
|
42
|
+
"range": ">=0.1.0 <0.2.0",
|
|
43
|
+
"kind": "replace"
|
|
44
|
+
}
|
|
45
|
+
]
|
|
40
46
|
}
|
|
41
47
|
},
|
|
42
48
|
"publishConfig": {
|
package/runtime/provenance.json
CHANGED