create-pmos 0.488.0 → 0.489.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/package.json +14 -14
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/workspace/changelog.json +13 -0
- package/workspace/lib/headless.js +80 -11
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/server.js +41 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-pmos",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.489.0",
|
|
4
4
|
"description": "Scaffold the PMOS portable kit — run the PMOS product-management workflow (initiative → lane-fit spec → contract → build → three gates, with work-type lanes for features, research, maintenance, incidents, and content) entirely inside your own repo, with all state as git-versioned files. Includes `workflow-sweep`, which audits the state every board derives from and separates real defects from work you simply have not done. `create-pmos workspace` also installs + launches the local Terminal Workspace GUI. No database, no network, no telemetry.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -32,6 +32,19 @@
|
|
|
32
32
|
"audit"
|
|
33
33
|
],
|
|
34
34
|
"pmosChanges": [
|
|
35
|
+
{
|
|
36
|
+
"v": "0.489.0",
|
|
37
|
+
"at": "2026-11-02T07:07:12.466Z",
|
|
38
|
+
"f": 3,
|
|
39
|
+
"prs": [
|
|
40
|
+
{
|
|
41
|
+
"n": 1151,
|
|
42
|
+
"t": "Background runs can read through connectors; stop on a repeated denied tool",
|
|
43
|
+
"s": "Background runs can read through connectors; stop on a repeated denied tool",
|
|
44
|
+
"k": "fix"
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
},
|
|
35
48
|
{
|
|
36
49
|
"v": "0.488.0",
|
|
37
50
|
"at": "2026-11-02T06:16:07.264Z",
|
|
@@ -282,19 +295,6 @@
|
|
|
282
295
|
"k": "new"
|
|
283
296
|
}
|
|
284
297
|
]
|
|
285
|
-
},
|
|
286
|
-
{
|
|
287
|
-
"v": "0.469.0",
|
|
288
|
-
"at": "2026-10-31T10:43:44.457Z",
|
|
289
|
-
"f": 3,
|
|
290
|
-
"prs": [
|
|
291
|
-
{
|
|
292
|
-
"n": 1122,
|
|
293
|
-
"t": "Build and upload the Board's code for the host (board-publish slice 3, H6)",
|
|
294
|
-
"s": "Build and upload the Board's code for the host (board-publish slice 3, H6)",
|
|
295
|
-
"k": "new"
|
|
296
|
-
}
|
|
297
|
-
]
|
|
298
298
|
}
|
|
299
299
|
]
|
|
300
300
|
}
|
package/payload/KIT-VERSION
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Reference
|
|
3
3
|
title: "Eval calibration log"
|
|
4
4
|
description: "Append-only record of every PM override of an evaluator verdict."
|
|
5
|
-
generated: {by: process:create-pmos, at: "2026-11-
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-02T07:07:08Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Reference
|
|
3
3
|
title: "Health budgets"
|
|
4
4
|
description: "Closed registry of health-budget anchors (D59), edited only by the PM."
|
|
5
|
-
generated: {by: process:create-pmos, at: "2026-11-
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-02T07:07:08Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Reference
|
|
3
3
|
title: "Discoveries and friction log"
|
|
4
4
|
description: "Append-only record of what runs discovered and where the process rubbed."
|
|
5
|
-
generated: {by: process:create-pmos, at: "2026-11-
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-02T07:07:08Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
package/workspace/changelog.json
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"v": "0.489.0",
|
|
4
|
+
"at": "2026-11-02T07:07:12.466Z",
|
|
5
|
+
"f": 3,
|
|
6
|
+
"prs": [
|
|
7
|
+
{
|
|
8
|
+
"n": 1151,
|
|
9
|
+
"t": "Background runs can read through connectors; stop on a repeated denied tool",
|
|
10
|
+
"s": "Background runs can read through connectors; stop on a repeated denied tool",
|
|
11
|
+
"k": "fix"
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
},
|
|
2
15
|
{
|
|
3
16
|
"v": "0.488.0",
|
|
4
17
|
"at": "2026-11-02T06:16:07.264Z",
|
|
@@ -21,9 +21,10 @@
|
|
|
21
21
|
* its first line of text when it ended well, or the real reason when it did not.
|
|
22
22
|
*
|
|
23
23
|
* A headless run uses the PM's own login, model choice (D75), profile and connectors, exactly as a pane does.
|
|
24
|
-
* It cannot ask for permission, so each kind gets a FIXED tool list here
|
|
25
|
-
*
|
|
26
|
-
*
|
|
24
|
+
* It cannot ask for permission, so each kind gets a FIXED tool list here. A kind that reads the PM's sources
|
|
25
|
+
* (CONNECTOR_READ_KINDS) also gets the read-shaped tools of the PM's connectors, by exact name; a connector write is
|
|
26
|
+
* never named, and anything else is denied and reported. A run that calls a refused tool twice is stopped
|
|
27
|
+
* (denialGuard). No bypass flag is ever passed. `PMOS_HEADLESS=off` sends every job back to a pane.
|
|
27
28
|
*
|
|
28
29
|
* The `drive` kind is the Initiative Driver (initiative initiative-driver): origin `drive:<kind>:<id>`. It reads, and it files
|
|
29
30
|
* proposals with `pmos driver propose`. It has no Write, no Edit, no `git push`, no web fetch and no connector write tool: no
|
|
@@ -41,7 +42,7 @@
|
|
|
41
42
|
* it) the PM's earlier copies through read-only connectors, and its only write is `pmos report propose`. `report-find` (origin `report-find:<run>`)
|
|
42
43
|
* is the weekly look for reports the PM already sends. It reads calendar, Slack, mail SUBJECTS and file names, which is untrusted text, so it holds
|
|
43
44
|
* no Write, no Edit, no web fetch and no tool that sends or posts, and its only write is `pmos report propose`. A connector tool is named in neither
|
|
44
|
-
* list
|
|
45
|
+
* static list; the server adds the read-shaped connector tools per run (CONNECTOR_READ_KINDS), and a connector write is denied and reported. A proposal
|
|
45
46
|
* is data; only the PM's press on the Reports page sets a report up. Neither kind ever runs in a pane.
|
|
46
47
|
*
|
|
47
48
|
* The `core-doc` kind drafts ONE core document (initiative core-documents): origin `core-doc:<scope>:<key>`. It reads and searches the repository,
|
|
@@ -210,6 +211,70 @@ const TOOLS = Object.freeze({
|
|
|
210
211
|
'Bash(git log *)', 'Bash(git status *)', 'Bash(git diff *)', 'Bash(ls *)', 'Bash(date *)']),
|
|
211
212
|
});
|
|
212
213
|
|
|
214
|
+
// Connector reads (fix 2026-11-02). Since batch 23 item 2 every run is `--permission-mode dontAsk`, so a tool that is not in the list is denied
|
|
215
|
+
// without a prompt. The kinds below read the PM's sources through connectors (Jira, Confluence, Slack, the calendar, mail, Drive), and before
|
|
216
|
+
// dontAsk they relied on the PM's default mode letting a read-only connector tool run. Now the server names those tools: the read-shaped tools
|
|
217
|
+
// of the PM's connected servers (CONNECTOR_READ_SEED, plus what each run's init line reports, server.js), filtered by the same read-verb rule the
|
|
218
|
+
// onboarding search uses (lib/project-onboard.js readTool). A connector WRITE is never named, so it is still denied. The other kinds read no
|
|
219
|
+
// connector and get none.
|
|
220
|
+
const CONNECTOR_READ_KINDS = Object.freeze(['skill', 'report-setup', 'report-find', 'ms-review', 'propose', 'metric-draft', 'impact', 'metric-read',
|
|
221
|
+
'report-sample-fetch', 'report-structure', 'report-structure-dry', 'report-structure-pull']);
|
|
222
|
+
// The read tools of the claude.ai connectors, by the names Claude Code gives them (`mcp__claude_ai_<connector>__<tool>`). A first run on a new
|
|
223
|
+
// computer needs them before any init line was seen. A name the PM's login does not have is harmless in --allowedTools.
|
|
224
|
+
const CONNECTOR_READ_SEED = Object.freeze([
|
|
225
|
+
...['getAccessibleAtlassianResources', 'searchJiraIssuesUsingJql', 'getJiraIssue', 'getVisibleJiraProjects', 'getJiraProjectIssueTypesMetadata',
|
|
226
|
+
'getJiraIssueTypeMetaWithFields', 'getJiraIssueRemoteIssueLinks', 'getTransitionsForJiraIssue', 'lookupJiraAccountId',
|
|
227
|
+
'getConfluencePage', 'getConfluenceSpaces', 'getPagesInConfluenceSpace', 'getConfluencePageDescendants', 'getConfluencePageFooterComments',
|
|
228
|
+
'getConfluencePageInlineComments', 'searchConfluenceUsingCql', 'search', 'fetch'].map((t) => 'mcp__claude_ai_Atlassian__' + t),
|
|
229
|
+
...['slack_read_channel', 'slack_read_thread', 'slack_read_canvas', 'slack_read_user_profile', 'slack_search_public', 'slack_search_public_and_private',
|
|
230
|
+
'slack_search_channels', 'slack_search_users', 'slack_list_user_channels'].map((t) => 'mcp__claude_ai_Slack__' + t),
|
|
231
|
+
...['list_events', 'get_event', 'search_events', 'list_calendars'].map((t) => 'mcp__claude_ai_Google_Calendar__' + t),
|
|
232
|
+
...['search_threads', 'get_thread', 'get_message', 'list_labels'].map((t) => 'mcp__claude_ai_Gmail__' + t),
|
|
233
|
+
...['search_files', 'read_file_content', 'get_file_metadata', 'list_recent_files'].map((t) => 'mcp__claude_ai_Google_Drive__' + t),
|
|
234
|
+
]);
|
|
235
|
+
const MCP_TOOL_RE = /^mcp__[\w-]+__[\w.-]+$/; // one exact tool: Claude Code's rule syntax, no server-wide or wildcard rule
|
|
236
|
+
/** The read-shaped connector tools among `names` (a run's init line, or a cached list): exact names only, never a write verb. */
|
|
237
|
+
function connectorReads(names) {
|
|
238
|
+
const { readTool } = require('./project-onboard.js');
|
|
239
|
+
const out = [];
|
|
240
|
+
for (const n of Array.isArray(names) ? names : []) {
|
|
241
|
+
const t = String(n || '');
|
|
242
|
+
if (MCP_TOOL_RE.test(t) && readTool(t) && !out.includes(t)) out.push(t);
|
|
243
|
+
}
|
|
244
|
+
return out;
|
|
245
|
+
}
|
|
246
|
+
/** The connector tools named in a stream-json init line, or null when the line is not an init line. */
|
|
247
|
+
function initTools(line) {
|
|
248
|
+
const o = jsonOf(line);
|
|
249
|
+
if (!o || o.type !== 'system' || o.subtype !== 'init' || !Array.isArray(o.tools)) return null;
|
|
250
|
+
return o.tools.filter((t) => typeof t === 'string' && t.startsWith('mcp__'));
|
|
251
|
+
}
|
|
252
|
+
// The one line every run gets about a refused tool (fix 2026-11-02: a Jira refresh called the same denied tool again and again).
|
|
253
|
+
const DENIED_RULE = 'A tool call that is refused in this run stays refused: never call that tool again. Carry on with the tools you have, and say in your answer what you could not read.';
|
|
254
|
+
const DENIED_RE = /Permission to use ([\w.-]+) has been denied|requested permissions to use ([\w.-]+)/;
|
|
255
|
+
/** Follows a run's stream and says when it calls a refused tool a second time: → { see(line) → tool name | null, denied: Map }. */
|
|
256
|
+
function denialGuard(limit = 2) {
|
|
257
|
+
const denied = new Map();
|
|
258
|
+
return {
|
|
259
|
+
denied,
|
|
260
|
+
see(line) {
|
|
261
|
+
const o = jsonOf(line);
|
|
262
|
+
if (!o || o.type !== 'user' || !o.message || !Array.isArray(o.message.content)) return null;
|
|
263
|
+
for (const c of o.message.content) {
|
|
264
|
+
if (!c || c.type !== 'tool_result' || !c.is_error) continue;
|
|
265
|
+
const body = Array.isArray(c.content) ? c.content.map((x) => (x && x.text) || '').join(' ') : String(c.content || '');
|
|
266
|
+
const m = DENIED_RE.exec(body);
|
|
267
|
+
if (!m) continue;
|
|
268
|
+
const tool = m[1] || m[2];
|
|
269
|
+
const n = (denied.get(tool) || 0) + 1;
|
|
270
|
+
denied.set(tool, n);
|
|
271
|
+
if (n >= limit) return tool;
|
|
272
|
+
}
|
|
273
|
+
return null;
|
|
274
|
+
},
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
|
|
213
278
|
const DEFAULT_TIMEOUT_MS = 20 * 60 * 1000;
|
|
214
279
|
|
|
215
280
|
function switchedOff(env) {
|
|
@@ -245,9 +310,11 @@ function kindFor({ agent, origin, skill, env } = {}) {
|
|
|
245
310
|
return null;
|
|
246
311
|
}
|
|
247
312
|
|
|
248
|
-
function argsFor(kind, { modelArgs = [], addDirs = [], writePaths = [], budgetUsd = null } = {}) {
|
|
313
|
+
function argsFor(kind, { modelArgs = [], addDirs = [], writePaths = [], budgetUsd = null, connectorTools = [] } = {}) {
|
|
249
314
|
if (!TOOLS[kind]) throw new Error('unknown headless kind: ' + kind);
|
|
250
315
|
const tools = TOOLS[kind].slice();
|
|
316
|
+
// A kind that reads the PM's sources gets the read-shaped connector tools the server names; any other kind gets none, whatever is passed.
|
|
317
|
+
if (CONNECTOR_READ_KINDS.includes(kind)) for (const t of connectorReads(connectorTools)) tools.push(t);
|
|
251
318
|
// A report-design run may write its render file (a report-sample-fetch run, its text copy) and nothing else: one absolute path, no wildcard, no comma.
|
|
252
319
|
if (WRITE_PATH_KINDS.includes(kind)) {
|
|
253
320
|
for (const p of Array.isArray(writePaths) ? writePaths : []) {
|
|
@@ -268,7 +335,7 @@ function argsFor(kind, { modelArgs = [], addDirs = [], writePaths = [], budgetUs
|
|
|
268
335
|
// dontAsk (batch 23 item 2): the PM's own Claude Code default mode must not reach a run that cannot answer. With "plan" as the PM's default, a
|
|
269
336
|
// report draft stopped after reading ("Plan mode is on, and the draft step writes files") and wrote nothing. dontAsk runs the list above and denies
|
|
270
337
|
// the rest, which is what this file already promises; it is not a bypass.
|
|
271
|
-
const argv = ['-p', '--output-format', 'stream-json', '--verbose', '--no-session-persistence', '--permission-mode', 'dontAsk', ...modelArgs, '--allowedTools', tools.join(',')];
|
|
338
|
+
const argv = ['-p', '--output-format', 'stream-json', '--verbose', '--no-session-persistence', '--permission-mode', 'dontAsk', '--append-system-prompt', DENIED_RULE, ...modelArgs, '--allowedTools', tools.join(',')];
|
|
272
339
|
// A run with a budget (a grill run, lib/grill.js budgetFor) stops at it, so the monthly credit cap holds
|
|
273
340
|
const b = Number(budgetUsd);
|
|
274
341
|
if (budgetUsd != null && Number.isFinite(b) && b > 0) argv.push('--max-budget-usd', String(b));
|
|
@@ -371,16 +438,18 @@ function streamLines(line) {
|
|
|
371
438
|
/** What the run card says about a finished background run. `ok` only when the process ended by itself with code 0 and its
|
|
372
439
|
* result is not an error. The headline is the first line of the agent's last message; the reason, when it failed, is the
|
|
373
440
|
* real one: stopped by the PM, the timeout, a signal, the exit code, an error result, or output that was not a result. */
|
|
374
|
-
function outcomeOf(r, { code = null, signal = null, timedOut = false, stopped = false, timeoutMin = null } = {}) {
|
|
441
|
+
function outcomeOf(r, { code = null, signal = null, timedOut = false, stopped = false, timeoutMin = null, deniedLoop = null } = {}) {
|
|
375
442
|
const res = r || { ok: false, text: '', isError: true, denied: [] };
|
|
376
443
|
const first = String(res.text || '').split('\n').map((x) => x.replace(/^[#>*\-\s]+/, '').trim()).find(Boolean) || '';
|
|
377
|
-
const denied = Array.isArray(res.denied) ? res.denied : [];
|
|
444
|
+
const denied = Array.isArray(res.denied) ? res.denied.slice() : [];
|
|
445
|
+
if (deniedLoop && !denied.includes(deniedLoop)) denied.push(deniedLoop);
|
|
378
446
|
const base = { turns: res.turns == null ? null : res.turns, durationMs: res.durationMs == null ? null : res.durationMs, denied };
|
|
379
447
|
const auth = !timedOut && !stopped && signedOut(res.text);
|
|
380
|
-
const ok = !timedOut && !stopped && !signal && code === 0 && res.ok && !res.isError;
|
|
448
|
+
const ok = !deniedLoop && !timedOut && !stopped && !signal && code === 0 && res.ok && !res.isError;
|
|
381
449
|
if (ok) return { ok: true, headline: oneLine(first || 'Finished. It wrote no summary.', 160), why: null, ...base };
|
|
382
450
|
let why;
|
|
383
|
-
if (
|
|
451
|
+
if (deniedLoop) why = `Stopped: it kept calling ${deniedLoop}, which a background run may not use.`;
|
|
452
|
+
else if (stopped) why = 'Stopped by you.';
|
|
384
453
|
else if (timedOut) why = `Stopped: still running after ${timeoutMin || Math.round(DEFAULT_TIMEOUT_MS / 60000)} minutes.`;
|
|
385
454
|
else if (signal) why = `The process was ended (${signal}).`;
|
|
386
455
|
else if (signedOut(res.text)) why = SIGNED_OUT_WHY;
|
|
@@ -419,4 +488,4 @@ function runEnvOf(extra) {
|
|
|
419
488
|
return out;
|
|
420
489
|
}
|
|
421
490
|
|
|
422
|
-
module.exports = { HEADLESS_SKILLS, HEADLESS_ORIGINS, ASK_ORIGINS, DRIVE_ORIGINS, SCAN_WEB_ORIGINS, SCAN_REPO_ORIGINS, SCAN_RESEARCH_WEB_ORIGINS, SCAN_RESEARCH_REPO_ORIGINS, WEB_KINDS, REPORT_SETUP_ORIGINS, REPORT_FIND_ORIGINS, CORE_DOC_ORIGINS, REPORT_DESIGN_ORIGINS, REPORT_SAMPLE_FETCH_ORIGINS, REPORT_STRUCTURE_ORIGINS, REPORT_STRUCTURE_DRY_ORIGINS, METRIC_DRAFT_ORIGINS, IMPACT_ORIGINS, TOOLS, SKILL_WRITE_DIRS, DEFAULT_TIMEOUT_MS, kindFor, argsFor, skillWriteDirs, timeoutMs, parseResult, streamLines, outcomeOf, signedOut, SIGNED_OUT_WHY, logLines, switchedOff, RUN_ENV, runEnvOf };
|
|
491
|
+
module.exports = { CONNECTOR_READ_KINDS, CONNECTOR_READ_SEED, DENIED_RULE, connectorReads, initTools, denialGuard, HEADLESS_SKILLS, HEADLESS_ORIGINS, ASK_ORIGINS, DRIVE_ORIGINS, SCAN_WEB_ORIGINS, SCAN_REPO_ORIGINS, SCAN_RESEARCH_WEB_ORIGINS, SCAN_RESEARCH_REPO_ORIGINS, WEB_KINDS, REPORT_SETUP_ORIGINS, REPORT_FIND_ORIGINS, CORE_DOC_ORIGINS, REPORT_DESIGN_ORIGINS, REPORT_SAMPLE_FETCH_ORIGINS, REPORT_STRUCTURE_ORIGINS, REPORT_STRUCTURE_DRY_ORIGINS, METRIC_DRAFT_ORIGINS, IMPACT_ORIGINS, TOOLS, SKILL_WRITE_DIRS, DEFAULT_TIMEOUT_MS, kindFor, argsFor, skillWriteDirs, timeoutMs, parseResult, streamLines, outcomeOf, signedOut, SIGNED_OUT_WHY, logLines, switchedOff, RUN_ENV, runEnvOf };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.489.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pmos-workspace",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.489.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@anthropic-ai/sdk": "^1.3.0",
|
package/workspace/package.json
CHANGED
package/workspace/server.js
CHANGED
|
@@ -4369,11 +4369,36 @@ function keepChatHistory(s) {
|
|
|
4369
4369
|
|
|
4370
4370
|
/* A headless run (workspace-headless-jobs). The row is an ordinary session record, so every caller that checks a
|
|
4371
4371
|
* session's state keeps working; it has no pty and no tmux, and `child` is the process. The log is read-only. */
|
|
4372
|
+
/* Connector reads (fix 2026-11-02). A run in dontAsk mode may use a connector only when its tool is named. The connector tools of a Claude login
|
|
4373
|
+
* are learned from each run's init line and kept per Claude home in <state>/connector-tools.json, so the next run names the read-shaped ones
|
|
4374
|
+
* (lib/headless.js connectorReads). Before any run was seen, the claude.ai read tools in CONNECTOR_READ_SEED stand in. */
|
|
4375
|
+
const CONNECTOR_TOOLS_FILE = path.join(STATE, 'connector-tools.json');
|
|
4376
|
+
const connectorHome = (env) => String((env && env.CLAUDE_CONFIG_DIR) || '~');
|
|
4377
|
+
function knownConnectorTools(env) {
|
|
4378
|
+
let all = {}; try { all = JSON.parse(fs.readFileSync(CONNECTOR_TOOLS_FILE, 'utf8')) || {}; } catch { /* none learned yet */ }
|
|
4379
|
+
const seen = all[connectorHome(env)];
|
|
4380
|
+
return [...headlessLib.CONNECTOR_READ_SEED, ...(seen && Array.isArray(seen.tools) ? seen.tools : [])];
|
|
4381
|
+
}
|
|
4382
|
+
function learnConnectorTools(env, tools) {
|
|
4383
|
+
const reads = headlessLib.connectorReads(tools);
|
|
4384
|
+
try {
|
|
4385
|
+
let all = {}; try { all = JSON.parse(fs.readFileSync(CONNECTOR_TOOLS_FILE, 'utf8')) || {}; } catch { /* first one */ }
|
|
4386
|
+
const home = connectorHome(env);
|
|
4387
|
+
if (all[home] && JSON.stringify(all[home].tools) === JSON.stringify(reads)) return;
|
|
4388
|
+
all[home] = { at: nowISO(), tools: reads };
|
|
4389
|
+
fs.mkdirSync(path.dirname(CONNECTOR_TOOLS_FILE), { recursive: true });
|
|
4390
|
+
fs.writeFileSync(CONNECTOR_TOOLS_FILE + '.tmp', JSON.stringify(all, null, 1));
|
|
4391
|
+
fs.renameSync(CONNECTOR_TOOLS_FILE + '.tmp', CONNECTOR_TOOLS_FILE);
|
|
4392
|
+
} catch (e) { warnWriteFail('connector tools', e); }
|
|
4393
|
+
}
|
|
4394
|
+
|
|
4372
4395
|
function startHeadless(base, workdir, kind, launchArgs, env, initialInput, addDirs, onDone, writePaths) {
|
|
4373
4396
|
const prompt = safeFirstInput(String(initialInput).replace(/\r+$/, ''));
|
|
4374
4397
|
// report-design-studio: writePaths names the one render file a report-design run may write; for a skill run, the folders it may write in (lib/headless.js ignores it for every other kind).
|
|
4398
|
+
// A kind that reads the PM's sources gets the read-shaped connector tools of this login (lib/headless.js CONNECTOR_READ_KINDS).
|
|
4375
4399
|
const args = headlessLib.argsFor(kind, { modelArgs: launchArgs, addDirs: Array.isArray(addDirs) ? addDirs : [], writePaths: Array.isArray(writePaths) ? writePaths : [],
|
|
4376
|
-
budgetUsd: kind === 'grill' && env ? env.PMOS_GRILL_BUDGET : null
|
|
4400
|
+
budgetUsd: kind === 'grill' && env ? env.PMOS_GRILL_BUDGET : null,
|
|
4401
|
+
connectorTools: headlessLib.CONNECTOR_READ_KINDS.includes(kind) ? knownConnectorTools(env) : [] });
|
|
4377
4402
|
const s = { ...base, cwd: workdir, state: 'working', pty: null, tmux: null, headless: kind, child: null,
|
|
4378
4403
|
note: '', buf: '', cols: 80, rows: 24, clients: new Set(), created: nowISO(), lastOutputAt: Date.now() };
|
|
4379
4404
|
const say = (text) => {
|
|
@@ -4399,10 +4424,22 @@ function startHeadless(base, workdir, kind, launchArgs, env, initialInput, addDi
|
|
|
4399
4424
|
let out = '', err = '', timedOut = false, part = '', resultLine = '';
|
|
4400
4425
|
const TAIL = 64 * 1024;
|
|
4401
4426
|
const dim = (t) => `\x1b[38;5;244m${t}\x1b[0m`;
|
|
4427
|
+
// A run that calls a refused tool a second time is stopped: in dontAsk mode the answer will not change (lib/headless.js denialGuard).
|
|
4428
|
+
const guard = headlessLib.denialGuard();
|
|
4402
4429
|
const feed = (line) => {
|
|
4403
4430
|
const ev = headlessLib.streamLines(line);
|
|
4404
4431
|
if (ev.result) resultLine = line;
|
|
4405
4432
|
if (ev.log.length) say(ev.log.map((l) => (/^›/.test(l) ? dim(l) : l)).join('\n') + '\n');
|
|
4433
|
+
const seen = headlessLib.initTools(line);
|
|
4434
|
+
if (seen) learnConnectorTools(env, seen);
|
|
4435
|
+
const again = !s.deniedLoop && guard.see(line);
|
|
4436
|
+
if (again) {
|
|
4437
|
+
s.deniedLoop = again;
|
|
4438
|
+
say(`\x1b[38;5;203m✗ ${again} is not allowed in a background run, and Claude asked for it again. Stopped the run.\x1b[0m\n`);
|
|
4439
|
+
killHeadless(child, 'SIGTERM');
|
|
4440
|
+
const hard = setTimeout(() => { if (s.child) killHeadless(child, 'SIGKILL'); }, 5000);
|
|
4441
|
+
if (hard.unref) hard.unref();
|
|
4442
|
+
}
|
|
4406
4443
|
};
|
|
4407
4444
|
child.stdout.on('data', (d) => {
|
|
4408
4445
|
s.lastOutputAt = Date.now();
|
|
@@ -4435,18 +4472,19 @@ function startHeadless(base, workdir, kind, launchArgs, env, initialInput, addDi
|
|
|
4435
4472
|
if (err.trim()) say(dim(err.trim().split('\n').slice(-20).join('\n')) + '\n');
|
|
4436
4473
|
const timeoutMin = Math.max(1, Math.round(headlessLib.timeoutMs() / 60000));
|
|
4437
4474
|
s.note = timedOut ? `stopped: still running after ${timeoutMin} minutes`
|
|
4475
|
+
: s.deniedLoop ? `stopped: kept calling ${s.deniedLoop}, which is not allowed`
|
|
4438
4476
|
: s.stoppedByPm ? 'ended by the PM'
|
|
4439
4477
|
: signal ? `exited (signal ${signal})`
|
|
4440
4478
|
: (code === 0 && r.ok && r.isError) ? 'exited (the run reported an error)'
|
|
4441
4479
|
: `exited (code ${code})`;
|
|
4442
4480
|
// What the Sessions card says about this run (lib/routes-runs.js): the agent's own first line, or the real reason it failed.
|
|
4443
|
-
s.outcome = headlessLib.outcomeOf(r, { code, signal, timedOut, stopped: !!s.stoppedByPm, timeoutMin });
|
|
4481
|
+
s.outcome = headlessLib.outcomeOf(r, { code, signal, timedOut, stopped: !!s.stoppedByPm, timeoutMin, deniedLoop: s.deniedLoop || null });
|
|
4444
4482
|
if (s.outcome.auth) claudeSetup.invalidate(s.profile);
|
|
4445
4483
|
if (!s.outcome.ok && err.trim() && !r.ok) s.outcome.why += ' ' + err.trim().split('\n').filter(Boolean).pop().slice(0, 200);
|
|
4446
4484
|
if (s.note !== 'exited (code 0)') say(`\x1b[38;5;203m[${s.note}]\x1b[0m\n`);
|
|
4447
4485
|
// agent-orchestrator: a failed run that hit the Claude usage limit holds new orchestrator starts until the reset it names (lib/orchestrator-quota.js).
|
|
4448
4486
|
// Only a failed run is read, so a run whose answer is about rate limits sets no hold.
|
|
4449
|
-
if (!timedOut && !s.stoppedByPm && (code !== 0 || !r.ok || r.isError)) {
|
|
4487
|
+
if (!timedOut && !s.stoppedByPm && !s.deniedLoop && (code !== 0 || !r.ok || r.isError)) {
|
|
4450
4488
|
try { const hold = orchQuota.detect([r.isError || !r.ok ? r.text : '', err.slice(-4000), resultLine ? '' : out.slice(-4000)].join('\n')); if (hold) orchQuota.record(STATE, hold); } catch (e) { warnWriteFail('usage-limit hold', e); }
|
|
4451
4489
|
}
|
|
4452
4490
|
persist(s); pushSessions();
|