monomind 2.0.0 → 2.0.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 (35) hide show
  1. package/README.md +11 -12
  2. package/package.json +2 -2
  3. package/packages/@monomind/cli/.claude/helpers/token-tracker.cjs +10 -0
  4. package/packages/@monomind/cli/README.md +11 -12
  5. package/packages/@monomind/cli/dist/src/browser/dashboard/server.js +71 -12
  6. package/packages/@monomind/cli/dist/src/browser/dashboard/ui.html +4 -4
  7. package/packages/@monomind/cli/dist/src/commands/browse-workflow.js +2 -2
  8. package/packages/@monomind/cli/dist/src/index.js +8 -7
  9. package/packages/@monomind/cli/dist/src/mcp-tools/coherence/types.d.ts +18 -18
  10. package/packages/@monomind/cli/dist/src/mcp-tools/quality/coverage-analysis/prioritize-gaps.d.ts +12 -12
  11. package/packages/@monomind/cli/dist/src/mcp-tools/quality/security-compliance/detect-secrets.d.ts +4 -4
  12. package/packages/@monomind/cli/dist/src/orgrt/bus.d.ts +23 -0
  13. package/packages/@monomind/cli/dist/src/orgrt/bus.js +64 -0
  14. package/packages/@monomind/cli/dist/src/orgrt/daemon.d.ts +41 -0
  15. package/packages/@monomind/cli/dist/src/orgrt/daemon.js +101 -0
  16. package/packages/@monomind/cli/dist/src/orgrt/forwarder.d.ts +11 -0
  17. package/packages/@monomind/cli/dist/src/orgrt/forwarder.js +37 -0
  18. package/packages/@monomind/cli/dist/src/orgrt/mailbox.d.ts +25 -0
  19. package/packages/@monomind/cli/dist/src/orgrt/mailbox.js +39 -0
  20. package/packages/@monomind/cli/dist/src/orgrt/policy.d.ts +24 -0
  21. package/packages/@monomind/cli/dist/src/orgrt/policy.js +86 -0
  22. package/packages/@monomind/cli/dist/src/orgrt/provider.d.ts +9 -0
  23. package/packages/@monomind/cli/dist/src/orgrt/provider.js +54 -0
  24. package/packages/@monomind/cli/dist/src/orgrt/session.d.ts +23 -0
  25. package/packages/@monomind/cli/dist/src/orgrt/session.js +78 -0
  26. package/packages/@monomind/cli/dist/src/orgrt/types.d.ts +847 -0
  27. package/packages/@monomind/cli/dist/src/orgrt/types.js +51 -0
  28. package/packages/@monomind/cli/dist/src/parser.js +31 -5
  29. package/packages/@monomind/cli/dist/src/ui/collector.mjs +69 -44
  30. package/packages/@monomind/cli/dist/src/ui/dashboard.html +112 -25
  31. package/packages/@monomind/cli/dist/src/ui/orgs.html +54 -0
  32. package/packages/@monomind/cli/dist/src/ui/server.mjs +87 -12
  33. package/packages/@monomind/cli/package.json +3 -2
  34. package/packages/@monomind/cli/dist/src/consensus/vote-signer.d.ts +0 -36
  35. package/packages/@monomind/cli/dist/src/consensus/vote-signer.js +0 -88
@@ -0,0 +1,23 @@
1
+ import { query } from '@anthropic-ai/claude-agent-sdk';
2
+ import type { OrgBus } from './bus.js';
3
+ import type { PolicyEngine } from './policy.js';
4
+ import type { Mailbox } from './mailbox.js';
5
+ import type { OrgDef, OrgRole } from './types.js';
6
+ export type DeliverFn = (from: string, to: string, subject: string, body: string) => Promise<string>;
7
+ export interface SessionOpts {
8
+ org: string;
9
+ role: OrgRole;
10
+ bus: OrgBus;
11
+ policy: PolicyEngine;
12
+ mailbox: Mailbox;
13
+ cwd: string;
14
+ deliver: DeliverFn;
15
+ def?: OrgDef;
16
+ maxTurns?: number;
17
+ queryFn?: typeof query;
18
+ }
19
+ /** Role briefing given to each agent session (SDK systemPrompt option). */
20
+ export declare function buildRolePrompt(role: OrgRole, def: Pick<OrgDef, 'name' | 'goal'>, roster: string[]): string;
21
+ /** Runs one persistent agent session; resolves when the mailbox closes and the SDK stream ends. */
22
+ export declare function runAgentSession(opts: SessionOpts): Promise<void>;
23
+ //# sourceMappingURL=session.d.ts.map
@@ -0,0 +1,78 @@
1
+ // packages/@monomind/cli/src/orgrt/session.ts
2
+ import { z } from 'zod';
3
+ import { query, tool, createSdkMcpServer } from '@anthropic-ai/claude-agent-sdk';
4
+ import { resolveProviderEnv } from './provider.js';
5
+ /** Role briefing given to each agent session (SDK systemPrompt option). */
6
+ export function buildRolePrompt(role, def, roster) {
7
+ return [
8
+ `You are agent "${role.id}" (${role.title || role.type}) in the org "${def.name}".`,
9
+ `Org goal: ${def.goal}`,
10
+ role.reports_to ? `You report to "${role.reports_to}".` : `You are the coordinator of this org.`,
11
+ role.responsibilities?.length ? `Your responsibilities:\n- ${role.responsibilities.join('\n- ')}` : '',
12
+ `## Communication protocol`,
13
+ `The ONLY way to communicate with other agents is the org_send tool.`,
14
+ `Roster: ${roster.join(', ')}. Address another org's agent as "<org-name>:<role-id>".`,
15
+ `When you receive a message, act on it, then org_send your result to the requester.`,
16
+ `When your current work is complete and no reply is needed, end your turn without further tool calls.`,
17
+ ].filter(Boolean).join('\n\n');
18
+ }
19
+ /** Runs one persistent agent session; resolves when the mailbox closes and the SDK stream ends. */
20
+ export async function runAgentSession(opts) {
21
+ const { org, role, bus, policy, mailbox, cwd, deliver } = opts;
22
+ const queryFn = opts.queryFn ?? query;
23
+ const orgServer = createSdkMcpServer({
24
+ name: 'org',
25
+ version: '1.0.0',
26
+ tools: [
27
+ tool('org_send', 'Send a message to another agent (role id) or another org ("org:role"). This is the only inter-agent channel.', { to: z.string(), subject: z.string(), message: z.string() }, async (args) => {
28
+ const receipt = await deliver(role.id, args.to, args.subject, args.message);
29
+ return { content: [{ type: 'text', text: receipt }] };
30
+ }),
31
+ ],
32
+ });
33
+ bus.emit({ type: 'status', from: role.id, msg: 'session starting' });
34
+ try {
35
+ const stream = queryFn({
36
+ prompt: mailbox.stream(),
37
+ options: {
38
+ systemPrompt: buildRolePrompt(role, (opts.def ?? { name: org, goal: '' }), opts.def?.roles.map(r => r.id) ?? [role.id]),
39
+ model: role.adapter_config?.model,
40
+ cwd,
41
+ env: resolveProviderEnv(role.provider),
42
+ mcpServers: { org: orgServer },
43
+ maxTurns: opts.maxTurns ?? 30,
44
+ permissionMode: 'default',
45
+ canUseTool: async (toolName, input) => policy.decide(toolName, input),
46
+ // test seam: lets the scripted fake SDK (test-loop.ts) drive org_send and
47
+ // tool calls through the real deliver/policy paths; the real SDK ignores it
48
+ _orgTest: {
49
+ deliver: (to, subject, body) => deliver(role.id, to, subject, body),
50
+ callTool: (name, input) => policy.decide(name, input),
51
+ },
52
+ },
53
+ });
54
+ for await (const m of stream) {
55
+ if (m.type === 'assistant') {
56
+ const text = (m.message?.content ?? [])
57
+ .filter((b) => b.type === 'text').map((b) => b.text).join('\n');
58
+ if (text.trim())
59
+ bus.emit({ type: 'chat', from: role.id, msg: text });
60
+ }
61
+ else if (m.type === 'result') {
62
+ const tokens = (m.usage?.input_tokens ?? 0) + (m.usage?.output_tokens ?? 0);
63
+ policy.addUsage(tokens);
64
+ bus.emit({ type: 'usage', from: role.id, data: { tokens, cost_usd: m.total_cost_usd, subtype: m.subtype } });
65
+ if (policy.overBudget) {
66
+ bus.emit({ type: 'status', from: role.id, msg: 'token budget exhausted — closing session' });
67
+ mailbox.close();
68
+ }
69
+ }
70
+ }
71
+ bus.emit({ type: 'status', from: role.id, msg: 'session ended' });
72
+ }
73
+ catch (err) {
74
+ bus.emit({ type: 'status', from: role.id, msg: `session error: ${err.message}` });
75
+ throw err;
76
+ }
77
+ }
78
+ //# sourceMappingURL=session.js.map