c8ctl-plugin-nano 1.70.5 → 1.70.6
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/c8ctl-plugin.js +130 -18
- package/package.json +8 -8
package/c8ctl-plugin.js
CHANGED
|
@@ -3169,18 +3169,49 @@ const NUDGE_CONTEXT_CAP_CHARS = 24_000;
|
|
|
3169
3169
|
|
|
3170
3170
|
// The bespoke prompt for the re-emit turn: derive the status from the work the
|
|
3171
3171
|
// agent already did, write ONLY the result, change nothing else.
|
|
3172
|
-
|
|
3172
|
+
// ACP `StopReason` values (#301). Only `end_turn` means the agent finished its
|
|
3173
|
+
// turn on its own; anything else (`max_turn_requests`, `max_tokens`, `refusal`,
|
|
3174
|
+
// `cancelled`, …) means the turn was CUT OFF, so the work may be incomplete.
|
|
3175
|
+
export function acpStopReasonFrom(promptResult) {
|
|
3176
|
+
const r = promptResult?.stopReason;
|
|
3177
|
+
return typeof r === 'string' && r.trim() ? r.trim().slice(0, 64) : null;
|
|
3178
|
+
}
|
|
3179
|
+
export function isTruncatedStopReason(stopReason) {
|
|
3180
|
+
return typeof stopReason === 'string' && stopReason !== '' && stopReason !== 'end_turn';
|
|
3181
|
+
}
|
|
3182
|
+
|
|
3183
|
+
function buildResultNudgePrompt(priorStdout, { hasResultFile = true, stopReason = null } = {}) {
|
|
3173
3184
|
const ctx = typeof priorStdout === 'string' ? priorStdout.slice(-NUDGE_CONTEXT_CAP_CHARS) : '';
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3185
|
+
// #301: never ASSERT completion. A budget-cut turn gets a bounded continuation
|
|
3186
|
+
// that asks the agent to preserve its work and report honestly; a clean
|
|
3187
|
+
// end_turn gets a softened re-emit that still allows `blocked`.
|
|
3188
|
+
const intro = isTruncatedStopReason(stopReason)
|
|
3189
|
+
? [
|
|
3190
|
+
`Your previous turn was CUT OFF before you finished (stop reason: ${stopReason}).`,
|
|
3191
|
+
'You did NOT emit a machine-readable result, and the task may be INCOMPLETE.',
|
|
3192
|
+
'',
|
|
3193
|
+
'Do not start new work. If you have uncommitted changes that belong to the task,',
|
|
3194
|
+
'commit them LOCALLY (`git commit -s`) so they are not lost — do NOT push:',
|
|
3195
|
+
'this turn runs without the task\'s branch/push policy, and the harness pushes',
|
|
3196
|
+
'for you afterwards when the task allows it (a push here could bypass that',
|
|
3197
|
+
'policy and publish to the wrong branch).',
|
|
3198
|
+
'Then report your TRUE status as a single flat JSON object of result variables.',
|
|
3199
|
+
'Use "blocked" (with a "summary" and a "question" explaining what remains) unless',
|
|
3200
|
+
'you actually delivered the full task (e.g. the PR is open). Never claim',
|
|
3201
|
+
'"completed" for work that was not committed and delivered.',
|
|
3202
|
+
'',
|
|
3203
|
+
]
|
|
3204
|
+
: [
|
|
3205
|
+
'Your previous turn ended, but you did NOT emit a machine-readable result, so',
|
|
3206
|
+
'the orchestrator cannot read your status and the run cannot advance.',
|
|
3207
|
+
'',
|
|
3208
|
+
'Do NOT redo the work, re-run tools, edit files, push, or open/modify a PR. Just',
|
|
3209
|
+
'report your TRUE status for the work so far: a single flat JSON object of your',
|
|
3210
|
+
'result variables (at minimum {"status":"..."}). If the task is not actually',
|
|
3211
|
+
'finished, report "blocked" with a "summary" and a "question" — do not claim',
|
|
3212
|
+
'completion for work you did not deliver.',
|
|
3213
|
+
'',
|
|
3214
|
+
];
|
|
3184
3215
|
// When the harness could not create the result file, AGENT_RESULT_FILE is NOT
|
|
3185
3216
|
// exported (runAgentJob only sets it for a truthy resultFile), so the usual
|
|
3186
3217
|
// "write to $AGENT_RESULT_FILE" instruction is impossible. Lead with the stdout
|
|
@@ -3229,6 +3260,49 @@ function capStdoutTail(s) {
|
|
|
3229
3260
|
return { text: buf.subarray(start).toString('utf8'), truncated: true };
|
|
3230
3261
|
}
|
|
3231
3262
|
|
|
3263
|
+
// #301: statuses that already report an honest non-success; left untouched.
|
|
3264
|
+
// `needs_input` belongs here too: it is a supported non-success result that
|
|
3265
|
+
// carries the actual `question` a human must answer. Rewriting it to `blocked`
|
|
3266
|
+
// would replace that question with the generic budget-retry prompt and lose the
|
|
3267
|
+
// information needed to unblock the task (Copilot review on #302, "previously
|
|
3268
|
+
// missed" — see agent-workers.test.mjs for needs_input as a supported status).
|
|
3269
|
+
const HONEST_NON_SUCCESS_STATUSES = new Set(['blocked', 'escalated', 'failed', 'incomplete', 'needs_input']);
|
|
3270
|
+
export function isWorkDelivered(git) {
|
|
3271
|
+
if (!git) return false;
|
|
3272
|
+
// A PR only proves delivery while it is OPEN or MERGED. `reconcileAgentPr`
|
|
3273
|
+
// searches `--state all`, so `found: true` also matches a CLOSED, unmerged PR
|
|
3274
|
+
// — e.g. an old, abandoned PR on the same branch. Treating that as delivered
|
|
3275
|
+
// would leave a claimed `completed` result unchanged for work that never
|
|
3276
|
+
// shipped, so a closed-unmerged PR is NOT delivery proof (Copilot review on
|
|
3277
|
+
// #302, discussion_r4464312576). `state` is the gh `pr list` field
|
|
3278
|
+
// (OPEN/CLOSED/MERGED); an absent/unknown state fails closed (not delivered).
|
|
3279
|
+
if (git.pr?.found) {
|
|
3280
|
+
const state = typeof git.pr.state === 'string' ? git.pr.state.trim().toUpperCase() : '';
|
|
3281
|
+
if (state === 'OPEN' || state === 'MERGED') return true;
|
|
3282
|
+
// CLOSED (unmerged) or unknown: fall through to the commit proof below.
|
|
3283
|
+
}
|
|
3284
|
+
return git.pushed === true && Array.isArray(git.commits) && git.commits.length > 0;
|
|
3285
|
+
}
|
|
3286
|
+
// Given the picked raw result of a run whose ACP turn ended with `stopReason`,
|
|
3287
|
+
// return an honest `blocked` result when the turn was cut off (non-`end_turn`)
|
|
3288
|
+
// and the work was NOT verifiably delivered. Otherwise return `raw` unchanged.
|
|
3289
|
+
export function downgradeBudgetStopResult(raw, { stopReason, git } = {}) {
|
|
3290
|
+
if (!isTruncatedStopReason(stopReason)) return raw;
|
|
3291
|
+
if (isWorkDelivered(git)) return raw;
|
|
3292
|
+
const status = isPlainObject(raw) && typeof raw.status === 'string' ? raw.status.trim().toLowerCase() : null;
|
|
3293
|
+
if (status && HONEST_NON_SUCCESS_STATUSES.has(status)) return raw;
|
|
3294
|
+
const prior = isPlainObject(raw) && typeof raw.summary === 'string' && raw.summary.trim() ? ` Agent's own summary: ${raw.summary.trim().slice(0, 2000)}` : '';
|
|
3295
|
+
const msg = `The agent's turn was cut off (stopReason=${stopReason}) before it delivered the task (no PR found, no commits pushed).${prior}`;
|
|
3296
|
+
return {
|
|
3297
|
+
...(isPlainObject(raw) ? raw : {}),
|
|
3298
|
+
status: 'blocked',
|
|
3299
|
+
summary: msg,
|
|
3300
|
+
question: `Agent run stopped early (${stopReason}) without delivering. Retry with a larger budget, or recover the WIP checkpoint and continue?`,
|
|
3301
|
+
stopReason,
|
|
3302
|
+
claimedStatus: status,
|
|
3303
|
+
};
|
|
3304
|
+
}
|
|
3305
|
+
|
|
3232
3306
|
async function resolveAgentResultWithNudge({ result, resultFile, rerun, logger, logPrefix = '' }) {
|
|
3233
3307
|
const stdout0 = result && typeof result.stdout === 'string' ? result.stdout : '';
|
|
3234
3308
|
// A parsed result only counts as usable if it still carries at least one
|
|
@@ -3259,7 +3333,8 @@ async function resolveAgentResultWithNudge({ result, resultFile, rerun, logger,
|
|
|
3259
3333
|
}
|
|
3260
3334
|
let nudge = null;
|
|
3261
3335
|
let nudgeError = null;
|
|
3262
|
-
|
|
3336
|
+
const stopReason = result?.stopReason ?? null;
|
|
3337
|
+
try { nudge = await rerun(buildResultNudgePrompt(stdout0, { hasResultFile: resultFile != null, stopReason })); } catch (err) { nudge = null; nudgeError = err; }
|
|
3263
3338
|
const nudgeOut = nudge && typeof nudge.stdout === 'string' ? nudge.stdout : '';
|
|
3264
3339
|
// Re-apply the per-stream capture cap after concatenation: `result.stdout` is
|
|
3265
3340
|
// forwarded verbatim into the job vars (`output`) and the audit envelope, so
|
|
@@ -3276,13 +3351,22 @@ async function resolveAgentResultWithNudge({ result, resultFile, rerun, logger,
|
|
|
3276
3351
|
// no-nudge early return above).
|
|
3277
3352
|
const truncated = result?.truncated === true || capped.truncated;
|
|
3278
3353
|
const recovered = hasUsableResult(readAgentResultFile(resultFile) ?? parseResultFromStdout(stdout));
|
|
3354
|
+
// The nudge turn has its OWN ACP `stopReason` (#301, Copilot review on #302,
|
|
3355
|
+
// discussion_r4464312610). It must NOT be discarded: when the first turn ended
|
|
3356
|
+
// cleanly (`end_turn`) but the NUDGE was itself cut off (`max_turn_requests`,
|
|
3357
|
+
// `max_tokens`, …) after writing `status:"completed"`, the delivery check must
|
|
3358
|
+
// still see a truncated reason or it would permit completion without delivery
|
|
3359
|
+
// and the logs/audit would show only the first turn's reason. Prefer the
|
|
3360
|
+
// nudge's reason when it is truncated; otherwise keep the first turn's.
|
|
3361
|
+
const nudgeStopReason = nudge && typeof nudge.stopReason === 'string' && nudge.stopReason.trim() ? nudge.stopReason.trim() : null;
|
|
3362
|
+
const effectiveStopReason = (isTruncatedStopReason(nudgeStopReason) ? nudgeStopReason : null) ?? stopReason;
|
|
3279
3363
|
if (nudgeError && logger?.warn) {
|
|
3280
3364
|
logger.warn(`${logPrefix} re-emit nudge rerun threw — ${nudgeError?.message ?? nudgeError}`);
|
|
3281
3365
|
}
|
|
3282
3366
|
if (logger?.info) {
|
|
3283
3367
|
logger.info(recovered
|
|
3284
|
-
? `${logPrefix} no result on the first turn — recovered it via one re-emit nudge`
|
|
3285
|
-
: `${logPrefix} no result on the first turn — re-emit nudge did not recover one`);
|
|
3368
|
+
? `${logPrefix} no result on the first turn${stopReason ? ` (stopReason=${stopReason})` : ''} — recovered it via one ${isTruncatedStopReason(stopReason) ? 'budget-continuation' : 're-emit'} nudge${nudgeStopReason ? ` (nudge stopReason=${nudgeStopReason})` : ''}`
|
|
3369
|
+
: `${logPrefix} no result on the first turn${stopReason ? ` (stopReason=${stopReason})` : ''} — ${isTruncatedStopReason(stopReason) ? 'budget-continuation' : 're-emit'} nudge did not recover one${nudgeStopReason ? ` (nudge stopReason=${nudgeStopReason})` : ''}`);
|
|
3286
3370
|
}
|
|
3287
3371
|
// Propagate the rerun turn's OWN validated ACP outcome back to the caller (#263):
|
|
3288
3372
|
// the nudge is a continuation, so a fresh `_meta.outcome` it reports (e.g. a
|
|
@@ -3296,7 +3380,7 @@ async function resolveAgentResultWithNudge({ result, resultFile, rerun, logger,
|
|
|
3296
3380
|
// agent work (thread 4118913047).
|
|
3297
3381
|
const transcriptFloorOnly = result?.acpTranscriptFloorOnly === true
|
|
3298
3382
|
&& (!nudgeOut.trim() || nudge?.acpTranscriptFloorOnly === true);
|
|
3299
|
-
return { stdout, nudged: true, truncated, acpOutcome: nudge?.acpOutcome ?? result?.acpOutcome ?? null, transcriptFloorOnly };
|
|
3383
|
+
return { stdout, nudged: true, truncated, acpOutcome: nudge?.acpOutcome ?? result?.acpOutcome ?? null, transcriptFloorOnly, stopReason: effectiveStopReason, nudgeStopReason };
|
|
3300
3384
|
}
|
|
3301
3385
|
|
|
3302
3386
|
function coerceBool(v, dflt = false) {
|
|
@@ -9139,6 +9223,7 @@ function spawnCaptureAcp({ command, args = [], cwd, env, stdinData, timeoutMs, i
|
|
|
9139
9223
|
let childClosed = null; // { code, signal } once the child exits
|
|
9140
9224
|
let promptResolved = false; // the main session/prompt turn sent + resolved
|
|
9141
9225
|
let acpOutcome = null; // the turn's `_meta.outcome`, if the agent reported one
|
|
9226
|
+
let acpStopReason = null; // the turn's ACP `stopReason` (#301)
|
|
9142
9227
|
let settleTimer = null; // post-turn grace before force-reaping a lingering agent
|
|
9143
9228
|
// One-time warning latch for the reserved escalate/filter policies so the
|
|
9144
9229
|
// deferral is observable (not silent) but never spams a warning per request.
|
|
@@ -9245,6 +9330,7 @@ function spawnCaptureAcp({ command, args = [], cwd, env, stdinData, timeoutMs, i
|
|
|
9245
9330
|
// floor (thread 4118913047).
|
|
9246
9331
|
const floorOnly = floorEmitted && !sawRealTranscript;
|
|
9247
9332
|
let resolved = acpOutcome ? { ...result, acpOutcome } : result;
|
|
9333
|
+
if (acpStopReason) resolved = { ...resolved, stopReason: acpStopReason };
|
|
9248
9334
|
if (floorOnly) resolved = { ...resolved, acpTranscriptFloorOnly: true };
|
|
9249
9335
|
resolve(resolved);
|
|
9250
9336
|
};
|
|
@@ -9709,6 +9795,7 @@ function spawnCaptureAcp({ command, args = [], cwd, env, stdinData, timeoutMs, i
|
|
|
9709
9795
|
prompt: [{ type: 'text', text: String(stdinData ?? '') }],
|
|
9710
9796
|
});
|
|
9711
9797
|
acpOutcome = acpOutcomeFrom(prompted);
|
|
9798
|
+
acpStopReason = acpStopReasonFrom(prompted);
|
|
9712
9799
|
// End-of-turn: the main session/prompt request resolved. Mark it so the
|
|
9713
9800
|
// `close` handler can tell a completed turn from an early/handshake exit.
|
|
9714
9801
|
promptResolved = true;
|
|
@@ -10140,6 +10227,12 @@ function buildResultEnvelope(result, { sandbox, image, git, result: agentResult,
|
|
|
10140
10227
|
// The agent's explicit ACP end-of-task report (`_meta.outcome`), host-recorded
|
|
10141
10228
|
// alongside whatever result vars it returned.
|
|
10142
10229
|
if (result.acpOutcome) env.outcome = result.acpOutcome;
|
|
10230
|
+
// #301: why the (first) ACP turn ended — `end_turn` or a budget cut-off. After a
|
|
10231
|
+
// nudge this is the EFFECTIVE reason (the nudge's when it was truncated), and the
|
|
10232
|
+
// nudge turn's own reason is recorded separately so the audit shows both turns.
|
|
10233
|
+
if (result.stopReason) env.stopReason = result.stopReason;
|
|
10234
|
+
if (result.nudgeStopReason) env.nudgeStopReason = result.nudgeStopReason;
|
|
10235
|
+
if (result.budgetDowngraded) env.budgetDowngraded = true;
|
|
10143
10236
|
// Audit (issue #63): record which linked-resource key supplied the base prompt.
|
|
10144
10237
|
// The engine only keeps `latest` per resourceId (no pinning), so recording the
|
|
10145
10238
|
// resolved key is the only reproducibility handle for which prompt version ran.
|
|
@@ -13375,7 +13468,7 @@ async function workAgent(req, flags, ctx) {
|
|
|
13375
13468
|
// the result is recoverable only via the stdout `::nano:result::`
|
|
13376
13469
|
// sentinel, which `resolveAgentResultWithNudge` handles directly.
|
|
13377
13470
|
if (result.ok) {
|
|
13378
|
-
const { stdout, nudged, truncated, acpOutcome, transcriptFloorOnly } = await resolveAgentResultWithNudge({
|
|
13471
|
+
const { stdout, nudged, truncated, acpOutcome, transcriptFloorOnly, stopReason: effectiveStopReason, nudgeStopReason } = await resolveAgentResultWithNudge({
|
|
13379
13472
|
result,
|
|
13380
13473
|
resultFile,
|
|
13381
13474
|
logger,
|
|
@@ -13407,6 +13500,15 @@ async function workAgent(req, flags, ctx) {
|
|
|
13407
13500
|
// Adopt the nudge turn's outcome so the escalation / envelope reflect
|
|
13408
13501
|
// the latest continuation, not only the first turn (#263).
|
|
13409
13502
|
result.acpOutcome = acpOutcome;
|
|
13503
|
+
// Adopt the EFFECTIVE stopReason (#301, Copilot review on #302,
|
|
13504
|
+
// discussion_r4464312610): when the nudge turn was itself cut off
|
|
13505
|
+
// (e.g. first turn `end_turn`, nudge `max_turn_requests`), the
|
|
13506
|
+
// delivery check + logs/audit must reflect the truncated nudge turn,
|
|
13507
|
+
// not only the first turn. `effectiveStopReason` is the nudge's reason
|
|
13508
|
+
// when truncated, else the first turn's. Record the nudge's own reason
|
|
13509
|
+
// separately for audit.
|
|
13510
|
+
if (effectiveStopReason) result.stopReason = effectiveStopReason;
|
|
13511
|
+
if (nudgeStopReason) result.nudgeStopReason = nudgeStopReason;
|
|
13410
13512
|
}
|
|
13411
13513
|
}
|
|
13412
13514
|
|
|
@@ -13643,11 +13745,21 @@ async function workAgent(req, flags, ctx) {
|
|
|
13643
13745
|
// outputs. Read before deleting the temp dir.
|
|
13644
13746
|
// Last resort: vars implied by the agent's ACP `_meta.outcome` (a `blocked`
|
|
13645
13747
|
// report → an escalation) when it wrote no result of its own.
|
|
13646
|
-
|
|
13748
|
+
let rawResult = pickAgentResult(
|
|
13647
13749
|
() => readAgentResultFile(resultFile),
|
|
13648
13750
|
() => parseResultFromStdout(result.stdout),
|
|
13649
13751
|
() => resultVarsFromAcpOutcome(result.acpOutcome),
|
|
13650
13752
|
);
|
|
13753
|
+
// #301: a turn cut off by its budget is never recorded as a success
|
|
13754
|
+
// unless the work was verifiably delivered (PR found / commits pushed).
|
|
13755
|
+
{
|
|
13756
|
+
const honest = downgradeBudgetStopResult(rawResult, { stopReason: result.stopReason, git: gitResult });
|
|
13757
|
+
if (honest !== rawResult) {
|
|
13758
|
+
logger.warn(`[${jobType}] job ${job.jobKey}: turn ended with stopReason=${result.stopReason} and the work was not delivered — recording status "blocked" instead of ${JSON.stringify(rawResult?.status ?? null)}`);
|
|
13759
|
+
rawResult = honest;
|
|
13760
|
+
result.budgetDowngraded = true;
|
|
13761
|
+
}
|
|
13762
|
+
}
|
|
13651
13763
|
if (resultDir) { try { rmSync(resultDir, { recursive: true, force: true }); } catch { /* best effort */ } liveRunDirs.delete(resultDir); }
|
|
13652
13764
|
const resultVars = sanitizeResultVars(rawResult);
|
|
13653
13765
|
|
|
@@ -13656,7 +13768,7 @@ async function workAgent(req, flags, ctx) {
|
|
|
13656
13768
|
const gitNote = gitResult
|
|
13657
13769
|
? ` [${gitResult.branch ? `branch ${gitResult.branch}` : 'detached HEAD'}: ${gitResult.commits.length} commit(s), ${gitResult.branch ? (gitResult.pushed ? 'pushed' : (gitResult.pushFailed ? 'push FAILED' : 'not pushed')) : 'no branch to push'}${gitResult.pr?.found ? `, PR #${gitResult.pr.number}` : ''}]`
|
|
13658
13770
|
: '';
|
|
13659
|
-
logger.info(`[${jobType}] job ${job.jobKey} complete (exit 0)${result.truncated ? ' [output truncated]' : ''}${gitNote}`);
|
|
13771
|
+
logger.info(`[${jobType}] job ${job.jobKey} complete (exit 0)${result.stopReason ? ` [stopReason=${result.stopReason}]` : ''}${result.truncated ? ' [output truncated]' : ''}${gitNote}`);
|
|
13660
13772
|
if (gitResult?.pushFailed) {
|
|
13661
13773
|
// Elevate a push failure from a terse info tail to a loud, actionable
|
|
13662
13774
|
// error naming the stranded commit SHAs (issue #231): these commits are
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "c8ctl-plugin-nano",
|
|
3
|
-
"version": "1.70.
|
|
3
|
+
"version": "1.70.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "c8ctl plugin to start, inspect, and stop a local Nano BPM (nanobpmn) cluster",
|
|
6
6
|
"main": "c8ctl-plugin.js",
|
|
@@ -76,12 +76,12 @@
|
|
|
76
76
|
},
|
|
77
77
|
"optionalDependencies": {
|
|
78
78
|
"node-pty": "^1.0.0",
|
|
79
|
-
"@nanobpm/c8ctl-plugin-nano-darwin-arm64": "1.70.
|
|
80
|
-
"@nanobpm/c8ctl-plugin-nano-darwin-x64": "1.70.
|
|
81
|
-
"@nanobpm/c8ctl-plugin-nano-linux-x64": "1.70.
|
|
82
|
-
"@nanobpm/c8ctl-plugin-nano-linux-arm64": "1.70.
|
|
83
|
-
"@nanobpm/c8ctl-plugin-nano-linux-armv7": "1.70.
|
|
84
|
-
"@nanobpm/c8ctl-plugin-nano-linux-armv6": "1.70.
|
|
85
|
-
"@nanobpm/c8ctl-plugin-nano-win32-x64": "1.70.
|
|
79
|
+
"@nanobpm/c8ctl-plugin-nano-darwin-arm64": "1.70.6",
|
|
80
|
+
"@nanobpm/c8ctl-plugin-nano-darwin-x64": "1.70.6",
|
|
81
|
+
"@nanobpm/c8ctl-plugin-nano-linux-x64": "1.70.6",
|
|
82
|
+
"@nanobpm/c8ctl-plugin-nano-linux-arm64": "1.70.6",
|
|
83
|
+
"@nanobpm/c8ctl-plugin-nano-linux-armv7": "1.70.6",
|
|
84
|
+
"@nanobpm/c8ctl-plugin-nano-linux-armv6": "1.70.6",
|
|
85
|
+
"@nanobpm/c8ctl-plugin-nano-win32-x64": "1.70.6"
|
|
86
86
|
}
|
|
87
87
|
}
|