@monoes/monomindcli 2.16.13 → 2.16.14
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 +1 -1
- package/dist/src/commands/org-control.d.ts +117 -0
- package/dist/src/commands/org-control.d.ts.map +1 -0
- package/dist/src/commands/org-control.js +274 -0
- package/dist/src/commands/org-control.js.map +1 -0
- package/dist/src/commands/org-lifecycle.d.ts +7 -0
- package/dist/src/commands/org-lifecycle.d.ts.map +1 -0
- package/dist/src/commands/org-lifecycle.js +298 -0
- package/dist/src/commands/org-lifecycle.js.map +1 -0
- package/dist/src/commands/org-manage.d.ts +7 -0
- package/dist/src/commands/org-manage.d.ts.map +1 -0
- package/dist/src/commands/org-manage.js +357 -0
- package/dist/src/commands/org-manage.js.map +1 -0
- package/dist/src/commands/org-memory-command.d.ts +3 -0
- package/dist/src/commands/org-memory-command.d.ts.map +1 -0
- package/dist/src/commands/org-memory-command.js +178 -0
- package/dist/src/commands/org-memory-command.js.map +1 -0
- package/dist/src/commands/org-observe-approvals.d.ts +8 -0
- package/dist/src/commands/org-observe-approvals.d.ts.map +1 -0
- package/dist/src/commands/org-observe-approvals.js +211 -0
- package/dist/src/commands/org-observe-approvals.js.map +1 -0
- package/dist/src/commands/org-observe-checkpoint.d.ts +26 -0
- package/dist/src/commands/org-observe-checkpoint.d.ts.map +1 -0
- package/dist/src/commands/org-observe-checkpoint.js +180 -0
- package/dist/src/commands/org-observe-checkpoint.js.map +1 -0
- package/dist/src/commands/org-observe-config.d.ts +8 -0
- package/dist/src/commands/org-observe-config.d.ts.map +1 -0
- package/dist/src/commands/org-observe-config.js +160 -0
- package/dist/src/commands/org-observe-config.js.map +1 -0
- package/dist/src/commands/org-observe-gates.d.ts +4 -0
- package/dist/src/commands/org-observe-gates.d.ts.map +1 -0
- package/dist/src/commands/org-observe-gates.js +182 -0
- package/dist/src/commands/org-observe-gates.js.map +1 -0
- package/dist/src/commands/org-observe-inbox.d.ts +18 -0
- package/dist/src/commands/org-observe-inbox.d.ts.map +1 -0
- package/dist/src/commands/org-observe-inbox.js +154 -0
- package/dist/src/commands/org-observe-inbox.js.map +1 -0
- package/dist/src/commands/org-observe-logs.d.ts +31 -0
- package/dist/src/commands/org-observe-logs.d.ts.map +1 -0
- package/dist/src/commands/org-observe-logs.js +272 -0
- package/dist/src/commands/org-observe-logs.js.map +1 -0
- package/dist/src/commands/org-observe-questions.d.ts +8 -0
- package/dist/src/commands/org-observe-questions.d.ts.map +1 -0
- package/dist/src/commands/org-observe-questions.js +201 -0
- package/dist/src/commands/org-observe-questions.js.map +1 -0
- package/dist/src/commands/org-observe-report.d.ts +8 -0
- package/dist/src/commands/org-observe-report.d.ts.map +1 -0
- package/dist/src/commands/org-observe-report.js +366 -0
- package/dist/src/commands/org-observe-report.js.map +1 -0
- package/dist/src/commands/org-observe-shared.d.ts +20 -0
- package/dist/src/commands/org-observe-shared.d.ts.map +1 -0
- package/dist/src/commands/org-observe-shared.js +55 -0
- package/dist/src/commands/org-observe-shared.js.map +1 -0
- package/dist/src/commands/org-observe.d.ts +9 -101
- package/dist/src/commands/org-observe.d.ts.map +1 -1
- package/dist/src/commands/org-observe.js +12 -1675
- package/dist/src/commands/org-observe.js.map +1 -1
- package/dist/src/commands/org-poll.d.ts +57 -0
- package/dist/src/commands/org-poll.d.ts.map +1 -0
- package/dist/src/commands/org-poll.js +194 -0
- package/dist/src/commands/org-poll.js.map +1 -0
- package/dist/src/commands/org-run.d.ts +3 -0
- package/dist/src/commands/org-run.d.ts.map +1 -0
- package/dist/src/commands/org-run.js +449 -0
- package/dist/src/commands/org-run.js.map +1 -0
- package/dist/src/commands/org-serve.d.ts +19 -0
- package/dist/src/commands/org-serve.d.ts.map +1 -0
- package/dist/src/commands/org-serve.js +395 -0
- package/dist/src/commands/org-serve.js.map +1 -0
- package/dist/src/commands/org-subcommands-config.d.ts +8 -0
- package/dist/src/commands/org-subcommands-config.d.ts.map +1 -0
- package/dist/src/commands/org-subcommands-config.js +93 -0
- package/dist/src/commands/org-subcommands-config.js.map +1 -0
- package/dist/src/commands/org-subcommands-hil.d.ts +11 -0
- package/dist/src/commands/org-subcommands-hil.d.ts.map +1 -0
- package/dist/src/commands/org-subcommands-hil.js +216 -0
- package/dist/src/commands/org-subcommands-hil.js.map +1 -0
- package/dist/src/commands/org-subcommands-observe.d.ts +12 -0
- package/dist/src/commands/org-subcommands-observe.d.ts.map +1 -0
- package/dist/src/commands/org-subcommands-observe.js +249 -0
- package/dist/src/commands/org-subcommands-observe.js.map +1 -0
- package/dist/src/commands/org-subcommands-runtime.d.ts +12 -0
- package/dist/src/commands/org-subcommands-runtime.d.ts.map +1 -0
- package/dist/src/commands/org-subcommands-runtime.js +163 -0
- package/dist/src/commands/org-subcommands-runtime.js.map +1 -0
- package/dist/src/commands/org.d.ts +3 -151
- package/dist/src/commands/org.d.ts.map +1 -1
- package/dist/src/commands/org.js +43 -2735
- package/dist/src/commands/org.js.map +1 -1
- package/dist/src/orgrt/daemon-types.d.ts +196 -0
- package/dist/src/orgrt/daemon-types.d.ts.map +1 -0
- package/dist/src/orgrt/daemon-types.js +38 -0
- package/dist/src/orgrt/daemon-types.js.map +1 -0
- package/dist/src/orgrt/daemon.d.ts +70 -300
- package/dist/src/orgrt/daemon.d.ts.map +1 -1
- package/dist/src/orgrt/daemon.js +41 -2536
- package/dist/src/orgrt/daemon.js.map +1 -1
- package/dist/src/orgrt/idle-watchdog.d.ts +39 -0
- package/dist/src/orgrt/idle-watchdog.d.ts.map +1 -0
- package/dist/src/orgrt/idle-watchdog.js +289 -0
- package/dist/src/orgrt/idle-watchdog.js.map +1 -0
- package/dist/src/orgrt/org-reload.d.ts +7 -0
- package/dist/src/orgrt/org-reload.d.ts.map +1 -0
- package/dist/src/orgrt/org-reload.js +111 -0
- package/dist/src/orgrt/org-reload.js.map +1 -0
- package/dist/src/orgrt/org-start-steps.d.ts +21 -0
- package/dist/src/orgrt/org-start-steps.d.ts.map +1 -0
- package/dist/src/orgrt/org-start-steps.js +305 -0
- package/dist/src/orgrt/org-start-steps.js.map +1 -0
- package/dist/src/orgrt/org-start.d.ts +7 -0
- package/dist/src/orgrt/org-start.d.ts.map +1 -0
- package/dist/src/orgrt/org-start.js +435 -0
- package/dist/src/orgrt/org-start.js.map +1 -0
- package/dist/src/orgrt/org-state-file.d.ts +8 -0
- package/dist/src/orgrt/org-state-file.d.ts.map +1 -0
- package/dist/src/orgrt/org-state-file.js +116 -0
- package/dist/src/orgrt/org-state-file.js.map +1 -0
- package/dist/src/orgrt/org-stop.d.ts +6 -0
- package/dist/src/orgrt/org-stop.d.ts.map +1 -0
- package/dist/src/orgrt/org-stop.js +332 -0
- package/dist/src/orgrt/org-stop.js.map +1 -0
- package/dist/src/orgrt/org-tools.d.ts +11 -0
- package/dist/src/orgrt/org-tools.d.ts.map +1 -0
- package/dist/src/orgrt/org-tools.js +305 -0
- package/dist/src/orgrt/org-tools.js.map +1 -0
- package/dist/src/orgrt/role-incarnation.d.ts +18 -0
- package/dist/src/orgrt/role-incarnation.d.ts.map +1 -0
- package/dist/src/orgrt/role-incarnation.js +374 -0
- package/dist/src/orgrt/role-incarnation.js.map +1 -0
- package/dist/src/orgrt/role-respawn.d.ts +7 -0
- package/dist/src/orgrt/role-respawn.d.ts.map +1 -0
- package/dist/src/orgrt/role-respawn.js +318 -0
- package/dist/src/orgrt/role-respawn.js.map +1 -0
- package/dist/src/orgrt/role-session-opts.d.ts +389 -0
- package/dist/src/orgrt/role-session-opts.d.ts.map +1 -0
- package/dist/src/orgrt/role-session-opts.js +289 -0
- package/dist/src/orgrt/role-session-opts.js.map +1 -0
- package/dist/src/orgrt/runner-resolve.d.ts +43 -0
- package/dist/src/orgrt/runner-resolve.d.ts.map +1 -0
- package/dist/src/orgrt/runner-resolve.js +77 -0
- package/dist/src/orgrt/runner-resolve.js.map +1 -0
- package/dist/src/orgrt/session-gate.d.ts +34 -0
- package/dist/src/orgrt/session-gate.d.ts.map +1 -0
- package/dist/src/orgrt/session-gate.js +74 -0
- package/dist/src/orgrt/session-gate.js.map +1 -0
- package/dist/src/orgrt/session-prompt.d.ts +31 -0
- package/dist/src/orgrt/session-prompt.d.ts.map +1 -0
- package/dist/src/orgrt/session-prompt.js +115 -0
- package/dist/src/orgrt/session-prompt.js.map +1 -0
- package/dist/src/orgrt/session-run.d.ts +18 -0
- package/dist/src/orgrt/session-run.d.ts.map +1 -0
- package/dist/src/orgrt/session-run.js +429 -0
- package/dist/src/orgrt/session-run.js.map +1 -0
- package/dist/src/orgrt/session-stream.d.ts +21 -0
- package/dist/src/orgrt/session-stream.d.ts.map +1 -0
- package/dist/src/orgrt/session-stream.js +173 -0
- package/dist/src/orgrt/session-stream.js.map +1 -0
- package/dist/src/orgrt/session-types.d.ts +219 -0
- package/dist/src/orgrt/session-types.d.ts.map +1 -0
- package/dist/src/orgrt/session-types.js +2 -0
- package/dist/src/orgrt/session-types.js.map +1 -0
- package/dist/src/orgrt/session-usage.d.ts +29 -0
- package/dist/src/orgrt/session-usage.d.ts.map +1 -0
- package/dist/src/orgrt/session-usage.js +64 -0
- package/dist/src/orgrt/session-usage.js.map +1 -0
- package/dist/src/orgrt/session.d.ts +5 -281
- package/dist/src/orgrt/session.d.ts.map +1 -1
- package/dist/src/orgrt/session.js +8 -1117
- package/dist/src/orgrt/session.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
// packages/@monomind/cli/src/commands/org-observe-approvals.ts
|
|
2
|
+
//
|
|
3
|
+
// `monomind org approvals | approve | deny` — pending tool/action approval
|
|
4
|
+
// requests and their live-or-offline resolution.
|
|
5
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { utcDateMinute } from '../orgrt/reporting.js';
|
|
8
|
+
import { ORG_DIR } from '../orgrt/types.js';
|
|
9
|
+
import { output } from '../output.js';
|
|
10
|
+
import { orgJson, printOrgJson, resolverFlag } from './org-observe-shared.js';
|
|
11
|
+
const log = (text) => {
|
|
12
|
+
console.log(text);
|
|
13
|
+
};
|
|
14
|
+
/** Read approvals.json — the tool/action-approval queue checked by
|
|
15
|
+
* checkApproval for Bash/WebFetch/WebSearch/org_complete (session.ts).
|
|
16
|
+
* Distinct from questions.json/gates.json: approving those does NOT touch
|
|
17
|
+
* this file or grant anything here. A MISSING file legitimately means "no
|
|
18
|
+
* pending approvals" → []. Any other failure THROWS, same rationale as
|
|
19
|
+
* readQuestions above — approveAction/denyAction rewrite this file from
|
|
20
|
+
* what this returns. */
|
|
21
|
+
const readApprovals = (cwd, name) => {
|
|
22
|
+
const path = join(cwd, ORG_DIR, name, 'approvals.json');
|
|
23
|
+
let raw;
|
|
24
|
+
try {
|
|
25
|
+
raw = readFileSync(path, 'utf8');
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
if (err.code === 'ENOENT')
|
|
29
|
+
return [];
|
|
30
|
+
throw new Error(`cannot read ${path}: ${err instanceof Error ? err.message : String(err)}`);
|
|
31
|
+
}
|
|
32
|
+
let parsed;
|
|
33
|
+
try {
|
|
34
|
+
parsed = JSON.parse(raw);
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
throw new Error(`${path} is not valid JSON (${err instanceof Error ? err.message : String(err)})`);
|
|
38
|
+
}
|
|
39
|
+
if (parsed?.approvals === undefined || parsed.approvals === null)
|
|
40
|
+
return [];
|
|
41
|
+
if (!Array.isArray(parsed.approvals))
|
|
42
|
+
throw new Error(`${path}: "approvals" is not an array`);
|
|
43
|
+
return parsed.approvals;
|
|
44
|
+
};
|
|
45
|
+
/** `org approvals <name> [--all]` — list pending (or all) tool/action approval requests. */
|
|
46
|
+
export const approvalsAction = async (ctx, name) => {
|
|
47
|
+
let all;
|
|
48
|
+
try {
|
|
49
|
+
all = readApprovals(ctx.cwd, name);
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
log(output.error(`Cannot read approvals for org ${name}: ${err instanceof Error ? err.message : String(err)}`));
|
|
53
|
+
return { success: false, message: 'approvals.json unreadable' };
|
|
54
|
+
}
|
|
55
|
+
const shown = ctx.flags.all === true ? all : all.filter((a) => a.approved === null);
|
|
56
|
+
if (orgJson(ctx))
|
|
57
|
+
return printOrgJson({
|
|
58
|
+
v: 1,
|
|
59
|
+
org: name,
|
|
60
|
+
// M5: requestId / resolvedBy / input are always present (null for
|
|
61
|
+
// entries recorded before they existed).
|
|
62
|
+
items: shown.map((a) => ({
|
|
63
|
+
...a,
|
|
64
|
+
requestId: a.requestId ?? null,
|
|
65
|
+
resolvedBy: a.resolvedBy ?? null,
|
|
66
|
+
input: a.input ?? null,
|
|
67
|
+
})),
|
|
68
|
+
});
|
|
69
|
+
if (!shown.length) {
|
|
70
|
+
log(output.info(all.length
|
|
71
|
+
? `No pending approvals for org ${name} (${all.length} resolved — use --all).`
|
|
72
|
+
: `No approval requests recorded for org ${name}.`));
|
|
73
|
+
return { success: true };
|
|
74
|
+
}
|
|
75
|
+
for (const a of shown) {
|
|
76
|
+
const when = utcDateMinute(a.ts);
|
|
77
|
+
const mark = a.approved === null ? '❓' : a.approved ? '✓' : '✗';
|
|
78
|
+
const ref = a.requestId ? ` [${a.requestId}]` : '';
|
|
79
|
+
const by = a.resolvedBy ? ` (by ${a.resolvedBy})` : '';
|
|
80
|
+
log(output.info(`${mark} ${when} ${a.roleId}: ${a.action}${ref}${by}`));
|
|
81
|
+
}
|
|
82
|
+
if (shown.some((a) => a.approved === null))
|
|
83
|
+
log(output.info(`\nApprove with: monomind org approve ${name} <role> <action> [--request <id>] [--by <resolver>]\nDeny with: monomind org deny ${name} <role> <action> [--request <id>] [--by <resolver>]`));
|
|
84
|
+
return { success: true };
|
|
85
|
+
};
|
|
86
|
+
/** `org approve <org> <role> <action>` — approve a pending tool/action approval */
|
|
87
|
+
/** Shared by approveAction/denyAction: try the live daemon first (updates its
|
|
88
|
+
* in-memory state and notifies the waiting agent's mailbox immediately), and
|
|
89
|
+
* fall back to writing approvals.json directly when the org isn't running or
|
|
90
|
+
* the daemon is unreachable — mirrors answerAction's live-then-offline shape. */
|
|
91
|
+
async function resolveApproval(ctx, name, role, action, approved) {
|
|
92
|
+
const verb = approved ? 'approved' : 'denied';
|
|
93
|
+
// M5: attribution and request scoping.
|
|
94
|
+
const byFlag = await resolverFlag(ctx);
|
|
95
|
+
if (!byFlag.ok)
|
|
96
|
+
return { success: false, message: byFlag.message };
|
|
97
|
+
const resolvedBy = byFlag.by;
|
|
98
|
+
const requestId = typeof ctx.flags.request === 'string' && ctx.flags.request ? ctx.flags.request : undefined;
|
|
99
|
+
if (ctx.flags.request !== undefined && !requestId)
|
|
100
|
+
return { success: false, message: '--request needs an approval request id (apr-…)' };
|
|
101
|
+
// SEC: approvals carry human authority — the operator credential, never the
|
|
102
|
+
// broker entry's agent credential (which any agent subprocess can read).
|
|
103
|
+
const { lookupOrg, readOperatorCredential } = await import('../orgrt/broker.js');
|
|
104
|
+
const remote = lookupOrg(name);
|
|
105
|
+
if (remote) {
|
|
106
|
+
const cred = readOperatorCredential(name);
|
|
107
|
+
try {
|
|
108
|
+
const res = await fetch(`${remote.url}/api/set-approval`, {
|
|
109
|
+
method: 'POST',
|
|
110
|
+
headers: {
|
|
111
|
+
'Content-Type': 'application/json',
|
|
112
|
+
...(cred ? { 'x-monomind-cred': cred } : {}),
|
|
113
|
+
},
|
|
114
|
+
body: JSON.stringify({
|
|
115
|
+
org: name,
|
|
116
|
+
role,
|
|
117
|
+
action,
|
|
118
|
+
approved,
|
|
119
|
+
resolvedBy,
|
|
120
|
+
...(requestId ? { requestId } : {}),
|
|
121
|
+
}),
|
|
122
|
+
signal: AbortSignal.timeout(10_000),
|
|
123
|
+
});
|
|
124
|
+
const data = (await res.json().catch(() => ({})));
|
|
125
|
+
if (res.ok && data.ok) {
|
|
126
|
+
if (orgJson(ctx))
|
|
127
|
+
return printOrgJson({
|
|
128
|
+
v: 1,
|
|
129
|
+
org: name,
|
|
130
|
+
role,
|
|
131
|
+
action,
|
|
132
|
+
approved,
|
|
133
|
+
delivery: 'live',
|
|
134
|
+
resolvedBy,
|
|
135
|
+
requestId: requestId ?? null,
|
|
136
|
+
});
|
|
137
|
+
log(approved
|
|
138
|
+
? output.success(`Approved: ${role} may execute ${action} (live, by ${resolvedBy}).`)
|
|
139
|
+
: output.info(`Denied: ${role} may NOT execute ${action} (live, by ${resolvedBy}).`));
|
|
140
|
+
return { success: true, message: `${verb} ${action} for ${role}` };
|
|
141
|
+
}
|
|
142
|
+
log(output.warning(`Live delivery rejected (${data.error ?? res.status}) — falling back to offline queue.`));
|
|
143
|
+
}
|
|
144
|
+
catch (err) {
|
|
145
|
+
log(output.warning(`Hosting daemon unreachable (${err instanceof Error ? err.message : 'error'}) — falling back to offline queue.`));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// Offline path: org isn't live (or the live call failed) — write approvals.json directly.
|
|
149
|
+
const approvalsPath = join(ctx.cwd, ORG_DIR, name, 'approvals.json');
|
|
150
|
+
if (!existsSync(approvalsPath)) {
|
|
151
|
+
return { success: false, message: `no pending approvals for org ${name}` };
|
|
152
|
+
}
|
|
153
|
+
const data = JSON.parse(readFileSync(approvalsPath, 'utf8'));
|
|
154
|
+
const pending = data.approvals ?? [];
|
|
155
|
+
// Same selection as the daemon's setApproval: the one request named by
|
|
156
|
+
// --request, else every still-pending entry for the (role, action) pair.
|
|
157
|
+
const items = pending.filter((a) => a.roleId === role &&
|
|
158
|
+
a.action === action &&
|
|
159
|
+
a.approved === null &&
|
|
160
|
+
(requestId === undefined || a.requestId === requestId));
|
|
161
|
+
if (items.length === 0) {
|
|
162
|
+
return {
|
|
163
|
+
success: false,
|
|
164
|
+
message: requestId
|
|
165
|
+
? `no pending approval ${requestId} found for role ${role} action ${action}`
|
|
166
|
+
: `no pending approval found for role ${role} action ${action}`,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
const now = Date.now();
|
|
170
|
+
for (const item of items) {
|
|
171
|
+
item.approved = approved;
|
|
172
|
+
item.ts = now;
|
|
173
|
+
item.resolvedBy = resolvedBy;
|
|
174
|
+
item.resolvedAt = now;
|
|
175
|
+
}
|
|
176
|
+
writeFileSync(approvalsPath, JSON.stringify({ approvals: pending }, null, 2));
|
|
177
|
+
if (orgJson(ctx))
|
|
178
|
+
return printOrgJson({
|
|
179
|
+
v: 1,
|
|
180
|
+
org: name,
|
|
181
|
+
role,
|
|
182
|
+
action,
|
|
183
|
+
approved,
|
|
184
|
+
delivery: 'recorded',
|
|
185
|
+
resolvedBy,
|
|
186
|
+
requestId: requestId ?? null,
|
|
187
|
+
});
|
|
188
|
+
log(approved
|
|
189
|
+
? output.success(`Approved: ${role} may execute ${action} (by ${resolvedBy})`)
|
|
190
|
+
: output.info(`Denied: ${role} may NOT execute ${action} (by ${resolvedBy})`));
|
|
191
|
+
return { success: true, message: `${verb} ${action} for ${role}` };
|
|
192
|
+
}
|
|
193
|
+
/** `org approve <org> <role> <action> [--request <id>] [--by <resolver>]` — approve a pending tool/action approval */
|
|
194
|
+
export const approveAction = async (ctx, name) => {
|
|
195
|
+
const role = ctx.args[1];
|
|
196
|
+
const action = ctx.args[2];
|
|
197
|
+
if (!role || !action) {
|
|
198
|
+
return { success: false, message: 'usage: org approve <org> <role> <action>' };
|
|
199
|
+
}
|
|
200
|
+
return resolveApproval(ctx, name, role, action, true);
|
|
201
|
+
};
|
|
202
|
+
/** `org deny <org> <role> <action> [--request <id>] [--by <resolver>]` — deny a pending tool/action approval */
|
|
203
|
+
export const denyAction = async (ctx, name) => {
|
|
204
|
+
const role = ctx.args[1];
|
|
205
|
+
const action = ctx.args[2];
|
|
206
|
+
if (!role || !action) {
|
|
207
|
+
return { success: false, message: 'usage: org deny <org> <role> <action>' };
|
|
208
|
+
}
|
|
209
|
+
return resolveApproval(ctx, name, role, action, false);
|
|
210
|
+
};
|
|
211
|
+
//# sourceMappingURL=org-observe-approvals.js.map
|
|
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C"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { CommandContext, CommandResult } from '../types.js';
|
|
2
|
+
/** `org replay <org> <run-id>` — time-travel debugging: re-emit a past run's bus
|
|
3
|
+
* events into a fresh replay run for inspection. This is event-log replay only —
|
|
4
|
+
* it does not restart agent execution or restore live sessions. To actually
|
|
5
|
+
* resume an org's execution from where it left off, use `org run --resume`. */
|
|
6
|
+
export declare const replayAction: (ctx: CommandContext, name: string) => Promise<CommandResult>;
|
|
7
|
+
/** `org resume-from <org>` — resume live execution from the org's persisted
|
|
8
|
+
* checkpoint (runtime.json): restores mailbox queues, policy/token counters,
|
|
9
|
+
* and session state, subject to checkpoint TTL and checksum validation. Unlike
|
|
10
|
+
* `replay`, this restarts real agent execution via `startOrg(..., { resume: true })`. */
|
|
11
|
+
export declare const resumeFromAction: (ctx: CommandContext, name: string) => Promise<CommandResult>;
|
|
12
|
+
/** `org branch <org> <run-id> <label> [--format json]` — snapshot a run's event
|
|
13
|
+
* log for replay. This is NOT an executable what-if scenario: it copies
|
|
14
|
+
* bus.jsonl into a new run directory tagged with a `.branch-source` marker so
|
|
15
|
+
* it can be inspected or replayed later; it does not fork or re-run agent
|
|
16
|
+
* execution. Delegates to the shared, atomic (tmp+rename) implementation in
|
|
17
|
+
* checkpoint-ops.ts.
|
|
18
|
+
*
|
|
19
|
+
* `<label>` is a note recorded in `.branch-source`, not the new run's name —
|
|
20
|
+
* the run id is generated. `--format json` reports that generated id as a
|
|
21
|
+
* field so a scripted caller can feed it to `org replay` without scraping the
|
|
22
|
+
* human-readable line (#292). */
|
|
23
|
+
export declare const branchAction: (ctx: CommandContext, name: string) => Promise<CommandResult>;
|
|
24
|
+
/** `org decisions <org> [--run id]` — show Rifft-style decision traces */
|
|
25
|
+
export declare const decisionsAction: (ctx: CommandContext, name: string) => Promise<CommandResult>;
|
|
26
|
+
//# sourceMappingURL=org-observe-checkpoint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"org-observe-checkpoint.d.ts","sourceRoot":"","sources":["../../../src/commands/org-observe-checkpoint.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAOjE;;;gFAGgF;AAChF,eAAO,MAAM,YAAY,QAAe,cAAc,QAAQ,MAAM,KAAG,OAAO,CAAC,aAAa,CAuC3F,CAAC;AAyBF;;;0FAG0F;AAC1F,eAAO,MAAM,gBAAgB,QACtB,cAAc,QACb,MAAM,KACX,OAAO,CAAC,aAAa,CAkDvB,CAAC;AAEF;;;;;;;;;;kCAUkC;AAClC,eAAO,MAAM,YAAY,QAAe,cAAc,QAAQ,MAAM,KAAG,OAAO,CAAC,aAAa,CAkB3F,CAAC;AAEF,0EAA0E;AAC1E,eAAO,MAAM,eAAe,QACrB,cAAc,QACb,MAAM,KACX,OAAO,CAAC,aAAa,CAkDvB,CAAC"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// packages/@monomind/cli/src/commands/org-observe-checkpoint.ts
|
|
2
|
+
//
|
|
3
|
+
// `monomind org replay | resume-from | branch | decisions` — checkpoint
|
|
4
|
+
// replay, resume and branching, and decision traces.
|
|
5
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { branchCheckpoint } from '../orgrt/checkpoint-ops.js';
|
|
8
|
+
import { readRunEvents } from '../orgrt/reporting.js';
|
|
9
|
+
import { ORG_DIR } from '../orgrt/types.js';
|
|
10
|
+
import { output } from '../output.js';
|
|
11
|
+
import { orgJson, printOrgJson, resolveRun } from './org-observe-shared.js';
|
|
12
|
+
const log = (text) => {
|
|
13
|
+
console.log(text);
|
|
14
|
+
};
|
|
15
|
+
/** `org replay <org> <run-id>` — time-travel debugging: re-emit a past run's bus
|
|
16
|
+
* events into a fresh replay run for inspection. This is event-log replay only —
|
|
17
|
+
* it does not restart agent execution or restore live sessions. To actually
|
|
18
|
+
* resume an org's execution from where it left off, use `org run --resume`. */
|
|
19
|
+
export const replayAction = async (ctx, name) => {
|
|
20
|
+
const run = ctx.args[1];
|
|
21
|
+
if (!run) {
|
|
22
|
+
return { success: false, message: 'usage: org replay <org> <run-id>' };
|
|
23
|
+
}
|
|
24
|
+
const runDir = join(ctx.cwd, ORG_DIR, name, run);
|
|
25
|
+
if (!existsSync(runDir)) {
|
|
26
|
+
return { success: false, message: `run ${run} not found for org ${name}` };
|
|
27
|
+
}
|
|
28
|
+
const busFile = join(runDir, 'bus.jsonl');
|
|
29
|
+
if (!existsSync(busFile)) {
|
|
30
|
+
return { success: false, message: `no bus events found for run ${run}` };
|
|
31
|
+
}
|
|
32
|
+
log(output.info(`Replaying org ${name} events from checkpoint ${run}...`));
|
|
33
|
+
// Create daemon and replay the bus events for debugging/inspection
|
|
34
|
+
const { OrgDaemon } = await import('../orgrt/daemon.js');
|
|
35
|
+
const daemon = new OrgDaemon(ctx.cwd, { forward: false });
|
|
36
|
+
const resumed = await daemon.replayFrom(name, run);
|
|
37
|
+
if (!resumed) {
|
|
38
|
+
return {
|
|
39
|
+
success: false,
|
|
40
|
+
message: `replay failed - check bus.jsonl and org config for ${name} are valid`,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
log(output.success(`Org ${name} events replayed from ${run} as run ${resumed.run}`));
|
|
44
|
+
log(output.info(`Use: monomind org logs ${name} --run ${resumed.run} to inspect events.`));
|
|
45
|
+
log(output.info(`This is debug replay only — it does not restart agent execution. To resume live execution, use: monomind org run ${name} --resume`));
|
|
46
|
+
return { success: true, message: `replayed events from checkpoint ${run} as ${resumed.run}` };
|
|
47
|
+
};
|
|
48
|
+
/** PID of a live `org serve` daemon for this project, or null. Mirrors
|
|
49
|
+
* runAction's `liveServeDaemonPid` (commands/org-control.ts) — duplicated
|
|
50
|
+
* rather than imported because that function wasn't exported when this copy
|
|
51
|
+
* was written and this file was scoped to not touch org.ts. Liveness is confirmed against the pid
|
|
52
|
+
* itself, not just heartbeat-file presence, since a SIGKILLed daemon leaves
|
|
53
|
+
* a stale heartbeat behind; a stamp older than a few beats (daemon beats
|
|
54
|
+
* every 30s) means it's gone or wedged. */
|
|
55
|
+
function liveServeDaemonPid(cwd) {
|
|
56
|
+
try {
|
|
57
|
+
const hb = JSON.parse(readFileSync(join(cwd, '.monomind', 'serve-heartbeat.json'), 'utf8'));
|
|
58
|
+
if (typeof hb.pid !== 'number' || hb.pid === process.pid)
|
|
59
|
+
return null;
|
|
60
|
+
const age = Date.now() - Date.parse(hb.updatedAt ?? '');
|
|
61
|
+
if (!Number.isFinite(age) || age > 3 * 60_000)
|
|
62
|
+
return null;
|
|
63
|
+
process.kill(hb.pid, 0); // throws if the process is gone
|
|
64
|
+
return hb.pid;
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** `org resume-from <org>` — resume live execution from the org's persisted
|
|
71
|
+
* checkpoint (runtime.json): restores mailbox queues, policy/token counters,
|
|
72
|
+
* and session state, subject to checkpoint TTL and checksum validation. Unlike
|
|
73
|
+
* `replay`, this restarts real agent execution via `startOrg(..., { resume: true })`. */
|
|
74
|
+
export const resumeFromAction = async (ctx, name) => {
|
|
75
|
+
// A live `org serve` daemon (or another `org run`) may already own this
|
|
76
|
+
// org's execution. Building a fresh in-process OrgDaemon and resuming
|
|
77
|
+
// unconditionally — as this action used to — puts two processes on one
|
|
78
|
+
// runtime.json/broker lease and spawns a second set of role sessions
|
|
79
|
+
// against the same shared git workspace, since the fresh daemon's
|
|
80
|
+
// duplicate-start guard (`this.orgs.has(name)`) is scoped to its own empty
|
|
81
|
+
// in-memory map and never sees the other process. `runAction` (org.ts)
|
|
82
|
+
// already guards this by handing the request to the live daemon via a
|
|
83
|
+
// runfile instead of racing it — but that runfile mechanism only carries a
|
|
84
|
+
// plain "start" request (pollRunfiles/org.ts calls `daemon.startOrg(name,
|
|
85
|
+
// task)` with no resume option), so it can't be reused for a resume
|
|
86
|
+
// request without also touching org.ts. Refuse instead of racing the live
|
|
87
|
+
// daemon.
|
|
88
|
+
const serveOwner = liveServeDaemonPid(ctx.cwd);
|
|
89
|
+
if (serveOwner != null) {
|
|
90
|
+
log(output.error(`org ${name}: a live serve daemon (pid ${serveOwner}) already owns this project's orgs — refusing to start a second execution here.`));
|
|
91
|
+
log(output.info(`Check it against the live daemon instead: monomind org status ${name} / org decisions ${name} / org gates ${name}. ` +
|
|
92
|
+
`To resume from checkpoint yourself, stop the live daemon first (monomind org stop) or let it pick the org back up on its own schedule.`));
|
|
93
|
+
return {
|
|
94
|
+
success: false,
|
|
95
|
+
message: `org ${name}: already owned by live serve daemon (pid ${serveOwner}) — refused to avoid a duplicate execution`,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
log(output.info(`Resuming org ${name} from checkpoint...`));
|
|
99
|
+
const { OrgDaemon } = await import('../orgrt/daemon.js');
|
|
100
|
+
const daemon = new OrgDaemon(ctx.cwd, { forward: false });
|
|
101
|
+
const resumed = await daemon.resumeOrg(name);
|
|
102
|
+
if (!resumed) {
|
|
103
|
+
return {
|
|
104
|
+
success: false,
|
|
105
|
+
message: `resume failed for ${name} - check runtime.json checkpoint is present, unexpired, and valid`,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
log(output.success(`Org ${name} resumed - ${resumed.agents.size} role(s) restored`));
|
|
109
|
+
log(output.info(`Stop with: monomind org stop ${name}`));
|
|
110
|
+
return { success: true, message: `resumed ${name} - ${resumed.agents.size} role(s) restored` };
|
|
111
|
+
};
|
|
112
|
+
/** `org branch <org> <run-id> <label> [--format json]` — snapshot a run's event
|
|
113
|
+
* log for replay. This is NOT an executable what-if scenario: it copies
|
|
114
|
+
* bus.jsonl into a new run directory tagged with a `.branch-source` marker so
|
|
115
|
+
* it can be inspected or replayed later; it does not fork or re-run agent
|
|
116
|
+
* execution. Delegates to the shared, atomic (tmp+rename) implementation in
|
|
117
|
+
* checkpoint-ops.ts.
|
|
118
|
+
*
|
|
119
|
+
* `<label>` is a note recorded in `.branch-source`, not the new run's name —
|
|
120
|
+
* the run id is generated. `--format json` reports that generated id as a
|
|
121
|
+
* field so a scripted caller can feed it to `org replay` without scraping the
|
|
122
|
+
* human-readable line (#292). */
|
|
123
|
+
export const branchAction = async (ctx, name) => {
|
|
124
|
+
const run = ctx.args[1];
|
|
125
|
+
const label = ctx.args[2];
|
|
126
|
+
if (!run || !label) {
|
|
127
|
+
return { success: false, message: 'usage: org branch <org> <run-id> <label>' };
|
|
128
|
+
}
|
|
129
|
+
const result = branchCheckpoint(ctx.cwd, name, run, label);
|
|
130
|
+
if (!result.ok) {
|
|
131
|
+
return { success: false, message: result.error };
|
|
132
|
+
}
|
|
133
|
+
if (orgJson(ctx))
|
|
134
|
+
return printOrgJson({ v: 1, org: name, run: result.branchRun, from: run, label });
|
|
135
|
+
log(output.success(`Snapshotted ${run} as run ${result.branchRun} (label: "${label}")`));
|
|
136
|
+
log(output.info(`Replay it with: monomind org replay ${name} ${result.branchRun}`));
|
|
137
|
+
return { success: true, message: `snapshotted ${run} as run ${result.branchRun}` };
|
|
138
|
+
};
|
|
139
|
+
/** `org decisions <org> [--run id]` — show Rifft-style decision traces */
|
|
140
|
+
export const decisionsAction = async (ctx, name) => {
|
|
141
|
+
const run = resolveRun(ctx.cwd, name, ctx.flags.run);
|
|
142
|
+
if (!run) {
|
|
143
|
+
return { success: false, message: `no runs found for org ${name}` };
|
|
144
|
+
}
|
|
145
|
+
const events = readRunEvents(ctx.cwd, name, run);
|
|
146
|
+
if (!events.length) {
|
|
147
|
+
return { success: false, message: `run ${run} has no recorded events` };
|
|
148
|
+
}
|
|
149
|
+
// Filter decision trace events
|
|
150
|
+
const decisionEvents = events.filter((e) => e.type === 'audit' && e.reason === 'decision-trace' && e.data && typeof e.data === 'object');
|
|
151
|
+
if (orgJson(ctx)) {
|
|
152
|
+
return printOrgJson({
|
|
153
|
+
v: 1,
|
|
154
|
+
org: name,
|
|
155
|
+
run,
|
|
156
|
+
items: decisionEvents.map((e) => ({
|
|
157
|
+
ts: e.ts,
|
|
158
|
+
role: e.from ?? 'system',
|
|
159
|
+
...e.data,
|
|
160
|
+
})),
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
if (!decisionEvents.length) {
|
|
164
|
+
log(output.info(`No decision traces found in ${run}`));
|
|
165
|
+
return { success: true };
|
|
166
|
+
}
|
|
167
|
+
log(output.info(`Decision traces for ${name} / ${run} (${decisionEvents.length} decisions):`));
|
|
168
|
+
log(output.info('┌──────────────────┬─────────────┬────────────────────────────────────────┐'));
|
|
169
|
+
log(output.info('│ Role │ Type │ Context │'));
|
|
170
|
+
log(output.info('├──────────────────┼─────────────┼────────────────────────────────────────┤'));
|
|
171
|
+
for (const e of decisionEvents) {
|
|
172
|
+
const role = e.from ?? 'system';
|
|
173
|
+
const type = e.data.decisionType ?? 'unknown';
|
|
174
|
+
const context = e.data.context ?? '-';
|
|
175
|
+
log(output.info(`│ ${role.padEnd(16)} │ ${type.padEnd(11)} │ ${context.padEnd(38)} │`));
|
|
176
|
+
}
|
|
177
|
+
log(output.info('└──────────────────┴─────────────┴────────────────────────────────────────┘'));
|
|
178
|
+
return { success: true, message: `${decisionEvents.length} decision traces` };
|
|
179
|
+
};
|
|
180
|
+
//# sourceMappingURL=org-observe-checkpoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"org-observe-checkpoint.js","sourceRoot":"","sources":["../../../src/commands/org-observe-checkpoint.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,EAAE;AACF,wEAAwE;AACxE,qDAAqD;AAErD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EA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,IAA6B,CAAC,OAAO,IAAI,GAAG,CAAC;QAChE,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1F,CAAC;IAED,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,6EAA6E,CAAC,CAAC,CAAC;IAEhG,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,cAAc,CAAC,MAAM,kBAAkB,EAAE,CAAC;AAChF,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CommandContext, CommandResult } from '../types.js';
|
|
2
|
+
/** Validate org config(s) against OrgDefSchema — the exact parse `org run`/`org serve`
|
|
3
|
+
* perform — plus the structural invariants the runtime assumes but the schema can't
|
|
4
|
+
* express (single root role, resolvable reports_to, unique ids, parseable schedule). */
|
|
5
|
+
export declare const validateAction: (ctx: CommandContext) => Promise<CommandResult>;
|
|
6
|
+
/** `org create <name> --template <t> [--goal g] [--schedule s]` — scaffold a config from a template. */
|
|
7
|
+
export declare const createAction: (ctx: CommandContext, name: string) => Promise<CommandResult>;
|
|
8
|
+
//# sourceMappingURL=org-observe-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"org-observe-config.d.ts","sourceRoot":"","sources":["../../../src/commands/org-observe-config.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAOjE;;wFAEwF;AACxF,eAAO,MAAM,cAAc,QAAe,cAAc,KAAG,OAAO,CAAC,aAAa,CA4E/E,CAAC;AAEF,wGAAwG;AACxG,eAAO,MAAM,YAAY,QAAe,cAAc,QAAQ,MAAM,KAAG,OAAO,CAAC,aAAa,CAoF3F,CAAC"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// packages/@monomind/cli/src/commands/org-observe-config.ts
|
|
2
|
+
//
|
|
3
|
+
// `monomind org validate | create` — org config validation and template
|
|
4
|
+
// scaffolding.
|
|
5
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { resolveOrgDefBlueprints } from '../catalog/blueprints.js';
|
|
8
|
+
import { checkOrgStructure } from '../orgrt/migrate.js';
|
|
9
|
+
import { gitEnforcementFindings } from '../orgrt/role-sandbox.js';
|
|
10
|
+
import { resolveModel } from '../orgrt/session.js';
|
|
11
|
+
import { buildFromTemplate, ORG_TEMPLATES } from '../orgrt/templates.js';
|
|
12
|
+
import { ORG_DIR, OrgDefSchema } from '../orgrt/types.js';
|
|
13
|
+
import { output } from '../output.js';
|
|
14
|
+
import { listOrgConfigFiles, validateOrgName } from './org-control.js';
|
|
15
|
+
const log = (text) => {
|
|
16
|
+
console.log(text);
|
|
17
|
+
};
|
|
18
|
+
/** Validate org config(s) against OrgDefSchema — the exact parse `org run`/`org serve`
|
|
19
|
+
* perform — plus the structural invariants the runtime assumes but the schema can't
|
|
20
|
+
* express (single root role, resolvable reports_to, unique ids, parseable schedule). */
|
|
21
|
+
export const validateAction = async (ctx) => {
|
|
22
|
+
const orgsDir = join(ctx.cwd || process.cwd(), ORG_DIR);
|
|
23
|
+
let files;
|
|
24
|
+
if (ctx.args[0]) {
|
|
25
|
+
const validated = validateOrgName(ctx.args[0]);
|
|
26
|
+
if (!validated.ok)
|
|
27
|
+
return validated.result;
|
|
28
|
+
files = [`${validated.name}.json`];
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
if (!existsSync(orgsDir))
|
|
32
|
+
return {
|
|
33
|
+
success: false,
|
|
34
|
+
message: 'no orgs directory — create an org first with /mastermind:createorg',
|
|
35
|
+
};
|
|
36
|
+
files = listOrgConfigFiles(orgsDir);
|
|
37
|
+
if (!files.length)
|
|
38
|
+
return { success: false, message: 'no org configs found' };
|
|
39
|
+
}
|
|
40
|
+
let failed = 0;
|
|
41
|
+
for (const f of files) {
|
|
42
|
+
const stem = f.replace(/\.json$/, '');
|
|
43
|
+
const path = join(orgsDir, f);
|
|
44
|
+
const errors = [];
|
|
45
|
+
const warnings = [];
|
|
46
|
+
if (!existsSync(path)) {
|
|
47
|
+
log(output.error(`${stem}: not found (${path})`));
|
|
48
|
+
failed++;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
const parsedDef = OrgDefSchema.parse(JSON.parse(readFileSync(path, 'utf8')));
|
|
53
|
+
const bp = resolveOrgDefBlueprints(parsedDef, ctx.cwd || process.cwd());
|
|
54
|
+
const def = bp.def;
|
|
55
|
+
errors.push(...bp.errors);
|
|
56
|
+
for (const n of bp.notes)
|
|
57
|
+
log(output.info(`${stem}: ${n}`));
|
|
58
|
+
errors.push(...checkOrgStructure(def));
|
|
59
|
+
// ADR-O001 D8: a cost tier that can't resolve a model for a role's
|
|
60
|
+
// provider is a config error, not a runtime fallback — surface it here
|
|
61
|
+
// as well as at daemon start, so it's caught before a run is attempted.
|
|
62
|
+
const { validateCostTiers } = await import('../orgrt/cost-tier.js');
|
|
63
|
+
errors.push(...validateCostTiers(def));
|
|
64
|
+
// S3: a typo'd placeholder would reach the prompt verbatim.
|
|
65
|
+
const { unknownPromptVarErrors } = await import('../orgrt/prompt-vars.js');
|
|
66
|
+
errors.push(...unknownPromptVarErrors(def));
|
|
67
|
+
// ADR-O001 D7: catalog size (>15 is an error, <5 a warning) and every
|
|
68
|
+
// loadout's skills/file must resolve — same checks as daemon start.
|
|
69
|
+
const { validateLoadouts } = await import('../orgrt/loadouts.js');
|
|
70
|
+
const loadoutFindings = validateLoadouts(def, ctx.cwd || process.cwd());
|
|
71
|
+
errors.push(...loadoutFindings.errors);
|
|
72
|
+
warnings.push(...loadoutFindings.warnings);
|
|
73
|
+
const { validateRoleSkills } = await import('../orgrt/skill-library.js');
|
|
74
|
+
errors.push(...def.roles.flatMap((r) => validateRoleSkills(r, ctx.cwd || process.cwd())));
|
|
75
|
+
// #258: roles whose policy.git won't have the OS sandbox behind it here
|
|
76
|
+
const gitFindings = gitEnforcementFindings(def);
|
|
77
|
+
errors.push(...gitFindings.errors);
|
|
78
|
+
warnings.push(...gitFindings.warnings);
|
|
79
|
+
if (def.name !== stem)
|
|
80
|
+
warnings.push(`def.name "${def.name}" differs from filename — the runtime addresses this org as "${stem}"`);
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
errors.push(err instanceof Error ? err.message : String(err));
|
|
84
|
+
}
|
|
85
|
+
for (const w of warnings)
|
|
86
|
+
log(output.warning(`${stem}: ${w}`));
|
|
87
|
+
if (errors.length) {
|
|
88
|
+
failed++;
|
|
89
|
+
for (const e of errors)
|
|
90
|
+
log(output.error(`${stem}: ${e}`));
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
log(output.success(`${stem}: valid${warnings.length ? ` (${warnings.length} warning(s))` : ''}`));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return failed
|
|
97
|
+
? { success: false, message: `${failed} of ${files.length} org config(s) failed validation` }
|
|
98
|
+
: { success: true, message: `${files.length} org config(s) valid` };
|
|
99
|
+
};
|
|
100
|
+
/** `org create <name> --template <t> [--goal g] [--schedule s]` — scaffold a config from a template. */
|
|
101
|
+
export const createAction = async (ctx, name) => {
|
|
102
|
+
const templateName = typeof ctx.flags.template === 'string' ? ctx.flags.template : '';
|
|
103
|
+
if (!templateName) {
|
|
104
|
+
log(output.info(`Available templates: ${Object.keys(ORG_TEMPLATES).join(', ')}`));
|
|
105
|
+
return {
|
|
106
|
+
success: false,
|
|
107
|
+
message: 'usage: monomind org create <name> --template <template> [--goal "..."] [--schedule 30m]',
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
const def = buildFromTemplate(templateName, name, typeof ctx.flags.goal === 'string' ? ctx.flags.goal : undefined);
|
|
111
|
+
if (!def) {
|
|
112
|
+
log(output.error(`Unknown template "${templateName}" — available: ${Object.keys(ORG_TEMPLATES).join(', ')}`));
|
|
113
|
+
return { success: false, message: 'unknown template' };
|
|
114
|
+
}
|
|
115
|
+
if (typeof ctx.flags.schedule === 'string')
|
|
116
|
+
def.schedule = ctx.flags.schedule;
|
|
117
|
+
const file = join(ctx.cwd, ORG_DIR, `${name}.json`);
|
|
118
|
+
if (existsSync(file) && ctx.flags.force !== true) {
|
|
119
|
+
log(output.error(`Org "${name}" already exists — pass --force to overwrite.`));
|
|
120
|
+
return { success: false, message: 'org exists' };
|
|
121
|
+
}
|
|
122
|
+
OrgDefSchema.parse(def); // templates must always produce a runnable config
|
|
123
|
+
// Per-role model — the single most consequential setting the template picked on
|
|
124
|
+
// the user's behalf. Mirror resolveModel() (same helper `org run`'s cost estimate
|
|
125
|
+
// uses) so a role relying on its runtime/vendor default isn't mislabeled here.
|
|
126
|
+
const modelRows = def.roles.map((r) => {
|
|
127
|
+
const explicit = r.adapter_config?.model;
|
|
128
|
+
return {
|
|
129
|
+
id: r.id,
|
|
130
|
+
model: String(explicit ?? resolveModel(r, r.runtime ?? def.runtime, r.provider?.vendor)),
|
|
131
|
+
explicit: !!explicit,
|
|
132
|
+
};
|
|
133
|
+
});
|
|
134
|
+
const printModels = () => {
|
|
135
|
+
log(output.bold(' Models:'));
|
|
136
|
+
for (const r of modelRows) {
|
|
137
|
+
log(` ${r.id.padEnd(20)} ${r.model}${r.explicit ? '' : ' (default)'}`);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
if (ctx.interactive && ctx.flags.yes !== true) {
|
|
141
|
+
log(output.bold(`\nAbout to create org "${name}" from template "${templateName}" (${def.roles.length} roles):`));
|
|
142
|
+
printModels();
|
|
143
|
+
const { confirm } = await import('../prompt.js');
|
|
144
|
+
const proceed = await confirm({ message: 'Create this org?', default: true });
|
|
145
|
+
if (!proceed) {
|
|
146
|
+
log(output.info('Cancelled — no file written. Adjust --template/--goal, or edit the template, then retry (pass --yes to skip this prompt).'));
|
|
147
|
+
return { success: false, message: 'cancelled by user' };
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const { mkdirSync } = await import('node:fs');
|
|
151
|
+
mkdirSync(join(ctx.cwd, ORG_DIR), { recursive: true });
|
|
152
|
+
writeFileSync(file, `${JSON.stringify(def, null, 2)}\n`, 'utf8');
|
|
153
|
+
log(output.success(`Org "${name}" created from template "${templateName}" (${def.roles.length} roles).`));
|
|
154
|
+
log(output.info(` Budget: ${def.run_config.budget_tokens} tokens · Turn limit: ${def.run_config.max_turns_per_message} per message (effectively unlimited by default — set run_config.max_turns_per_message, or a role's own max_turns_per_message, to cap it).`));
|
|
155
|
+
if (!ctx.interactive || ctx.flags.yes === true)
|
|
156
|
+
printModels();
|
|
157
|
+
log(output.info(` Edit the goal/roles in ${file}, then: monomind org run ${name}`));
|
|
158
|
+
return { success: true };
|
|
159
|
+
};
|
|
160
|
+
//# sourceMappingURL=org-observe-config.js.map
|