chainlesschain 0.166.161 → 0.166.162
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 +9 -3
- package/package.json +1 -1
- package/src/assets/linux-subreaper/linux-arm64/manifest.json +1 -1
- package/src/assets/linux-subreaper/linux-x64/manifest.json +1 -1
- package/src/command-help-index.json +1 -1
- package/src/commands/agenda.js +23 -2
- package/src/commands/agent.js +56 -21
- package/src/commands/ccron.js +1 -0
- package/src/commands/loop.js +34 -1
- package/src/commands/mcp.js +13 -3
- package/src/commands/plugin.js +10 -31
- package/src/commands/skill.js +31 -6
- package/src/commands/tasks.js +20 -2
- package/src/data/changelog.json +13 -0
- package/src/harness/background-task-command-runner.js +23 -25
- package/src/lib/background-agent-supervisor.js +3 -0
- package/src/lib/cowork-cron.js +115 -31
- package/src/lib/install-command-policy.js +23 -0
- package/src/lib/json-schema-output.js +12 -31
- package/src/lib/loop.js +30 -11
- package/src/lib/lsp/__tests__/code-intelligence.integration.test.js +17 -15
- package/src/lib/plan-mode.js +16 -0
- package/src/lib/plugin-runtime/install.js +111 -67
- package/src/lib/process-execution-broker/index.js +19 -9
- package/src/lib/public-ide-capability-manifest.js +88 -0
- package/src/lib/public-ide-capability-validation.js +24 -0
- package/src/lib/repl-denials.js +11 -0
- package/src/lib/search-command.js +13 -2
- package/src/lib/session-plan-approval.js +11 -2
- package/src/lib/status-line.cjs +3 -2
- package/src/lib/task-record.js +12 -1
- package/src/repl/agent-repl.js +195 -33
- package/src/runtime/agent-core.js +37 -17
- package/src/runtime/headless-runner.js +61 -4
- package/src/runtime/headless-stream.js +50 -2
- package/src/workers/background-agent-worker.js +11 -10
|
@@ -149,6 +149,8 @@ import {
|
|
|
149
149
|
classifyDenial,
|
|
150
150
|
recordDenial,
|
|
151
151
|
formatDenials,
|
|
152
|
+
DESTRUCTIVE_SHELL_DENIAL_CODE,
|
|
153
|
+
isDestructiveShellDenial,
|
|
152
154
|
} from "../lib/repl-denials.js";
|
|
153
155
|
import executionBroker from "../lib/process-execution-broker/index.js";
|
|
154
156
|
import { extractPluginUsageAttribution } from "../lib/plugin-usage-attribution.js";
|
|
@@ -640,6 +642,7 @@ async function withHeadlessSessionHostLease(options, deps, task) {
|
|
|
640
642
|
let budgetRoot = null;
|
|
641
643
|
let scopedOptions = options;
|
|
642
644
|
let preflightAdmission;
|
|
645
|
+
let taskStarted = false;
|
|
643
646
|
try {
|
|
644
647
|
// Session authority/lease/budget setup can lazily initialize AppConfig and
|
|
645
648
|
// DatabaseManager. Those legacy diagnostics use console.info (stdout), and
|
|
@@ -805,12 +808,50 @@ async function withHeadlessSessionHostLease(options, deps, task) {
|
|
|
805
808
|
scopedOptions = { ...scopedOptions, ...budgetRoot.options };
|
|
806
809
|
}
|
|
807
810
|
});
|
|
811
|
+
taskStarted = true;
|
|
808
812
|
return await task(scopedOptions, {
|
|
809
813
|
...deps,
|
|
810
814
|
[HEADLESS_SESSION_RESOLUTION]: resolution,
|
|
811
815
|
[HEADLESS_SESSION_HOST_LEASE]: lease,
|
|
812
816
|
[HEADLESS_CANONICAL_ADMISSION]: preflightAdmission,
|
|
813
817
|
});
|
|
818
|
+
} catch (error) {
|
|
819
|
+
if (taskStarted) throw error;
|
|
820
|
+
const sessionId =
|
|
821
|
+
resolution?.resumeId || resolution?.sessionId || options.sessionId;
|
|
822
|
+
const persistence = projectSessionPersistenceFailure(
|
|
823
|
+
createSessionPersistenceFailure(error, {
|
|
824
|
+
sessionId,
|
|
825
|
+
operation: "session-start",
|
|
826
|
+
}),
|
|
827
|
+
{ phase: "before-model" },
|
|
828
|
+
);
|
|
829
|
+
if (!persistence) throw error;
|
|
830
|
+
try {
|
|
831
|
+
deps.onPersistenceFailure?.(persistence);
|
|
832
|
+
} catch {
|
|
833
|
+
// Observability cannot change persistence semantics.
|
|
834
|
+
}
|
|
835
|
+
const result = `${persistence.code}: canonical session admission was refused (${persistence.fs_code}; ${persistence.commit_state})`;
|
|
836
|
+
if (outputFormat !== "text") {
|
|
837
|
+
deps.writeOut(
|
|
838
|
+
JSON.stringify(
|
|
839
|
+
buildResultEnvelope({
|
|
840
|
+
subtype: "error_persistence",
|
|
841
|
+
isError: true,
|
|
842
|
+
result,
|
|
843
|
+
sessionId,
|
|
844
|
+
toolCalls: [],
|
|
845
|
+
usage: {},
|
|
846
|
+
numTurns: 0,
|
|
847
|
+
durationMs: 0,
|
|
848
|
+
persistence,
|
|
849
|
+
}),
|
|
850
|
+
) + "\n",
|
|
851
|
+
);
|
|
852
|
+
}
|
|
853
|
+
deps.writeErr(`${result}\n`);
|
|
854
|
+
return { exitCode: 1, result, isError: true, persistence };
|
|
814
855
|
} finally {
|
|
815
856
|
// Cleanup can touch the same lazy stores. Keep late diagnostics out of a
|
|
816
857
|
// completed JSON/NDJSON payload while preserving release-on-close failure.
|
|
@@ -1591,7 +1632,13 @@ async function runAgentHeadlessInWorkspace(
|
|
|
1591
1632
|
try {
|
|
1592
1633
|
const { openSessionPlan } =
|
|
1593
1634
|
await import("../lib/session-plan-approval.js");
|
|
1594
|
-
const plan = openSessionPlan(sessionId, options.permissionMode
|
|
1635
|
+
const plan = openSessionPlan(sessionId, options.permissionMode, {
|
|
1636
|
+
// A resumed worker replays the original launch profile. A verified
|
|
1637
|
+
// session approval takes precedence over that historical default.
|
|
1638
|
+
permissionModeIsFallback:
|
|
1639
|
+
Boolean(process.env.CC_BACKGROUND_AGENT_ID) &&
|
|
1640
|
+
process.env.CC_BACKGROUND_RESTORE_PLAN_PERMISSION === "1",
|
|
1641
|
+
});
|
|
1595
1642
|
planManager = plan.manager;
|
|
1596
1643
|
options = { ...options, permissionMode: plan.permissionMode };
|
|
1597
1644
|
} catch {
|
|
@@ -3279,6 +3326,7 @@ async function runAgentHeadlessInWorkspace(
|
|
|
3279
3326
|
};
|
|
3280
3327
|
let finalText = "";
|
|
3281
3328
|
let endReason = "complete";
|
|
3329
|
+
let destructiveShellDenied = false;
|
|
3282
3330
|
let stopForCost = false;
|
|
3283
3331
|
let stopForCompactionUsageUnknown = false;
|
|
3284
3332
|
|
|
@@ -3892,6 +3940,7 @@ async function runAgentHeadlessInWorkspace(
|
|
|
3892
3940
|
}
|
|
3893
3941
|
case "tool-result": {
|
|
3894
3942
|
const err = event.error || event.result?.error || null;
|
|
3943
|
+
if (isDestructiveShellDenial(event)) destructiveShellDenied = true;
|
|
3895
3944
|
// A denied request has no invocation to settle. Explicit provider
|
|
3896
3945
|
// IDs must never fall back to a different pending invocation.
|
|
3897
3946
|
const settledCall =
|
|
@@ -4670,10 +4719,15 @@ async function runAgentHeadlessInWorkspace(
|
|
|
4670
4719
|
endReason === "budget-exhausted" || endReason === "max_turns";
|
|
4671
4720
|
const costStopped = endReason === "cost-budget-exhausted";
|
|
4672
4721
|
const goalExhausted = endReason === "goal-exhausted";
|
|
4722
|
+
// A final answer can follow a hard shell refusal. Keep the refusal in the
|
|
4723
|
+
// process result so automation cannot treat the destructive request as done.
|
|
4724
|
+
const deniedDestructiveRequest =
|
|
4725
|
+
endReason === "complete" && destructiveShellDenied;
|
|
4673
4726
|
let isError =
|
|
4674
4727
|
exhausted ||
|
|
4675
4728
|
costStopped ||
|
|
4676
4729
|
goalExhausted ||
|
|
4730
|
+
deniedDestructiveRequest ||
|
|
4677
4731
|
endReason === "no-response" ||
|
|
4678
4732
|
endReason === "deferred-mutation-unresolved";
|
|
4679
4733
|
let subtype = exhausted
|
|
@@ -4847,6 +4901,9 @@ async function runAgentHeadlessInWorkspace(
|
|
|
4847
4901
|
}
|
|
4848
4902
|
}
|
|
4849
4903
|
|
|
4904
|
+
const resultCode =
|
|
4905
|
+
sessionPersistenceCode ||
|
|
4906
|
+
(deniedDestructiveRequest ? DESTRUCTIVE_SHELL_DENIAL_CODE : null);
|
|
4850
4907
|
if (isStream) {
|
|
4851
4908
|
emitStream({
|
|
4852
4909
|
type: "result",
|
|
@@ -4862,7 +4919,7 @@ async function runAgentHeadlessInWorkspace(
|
|
|
4862
4919
|
? { compaction_degradations: compactionDegradations }
|
|
4863
4920
|
: {}),
|
|
4864
4921
|
...(persistenceFailure ? { persistence: persistenceFailure } : {}),
|
|
4865
|
-
...(
|
|
4922
|
+
...(resultCode ? { code: resultCode } : {}),
|
|
4866
4923
|
});
|
|
4867
4924
|
} else if (isJson) {
|
|
4868
4925
|
writeOut(
|
|
@@ -4881,7 +4938,7 @@ async function runAgentHeadlessInWorkspace(
|
|
|
4881
4938
|
compactionDegradations,
|
|
4882
4939
|
persistence: persistenceFailure,
|
|
4883
4940
|
}),
|
|
4884
|
-
...(
|
|
4941
|
+
...(resultCode ? { code: resultCode } : {}),
|
|
4885
4942
|
}) + "\n",
|
|
4886
4943
|
);
|
|
4887
4944
|
} else {
|
|
@@ -4929,7 +4986,7 @@ async function runAgentHeadlessInWorkspace(
|
|
|
4929
4986
|
result: finalText,
|
|
4930
4987
|
isError,
|
|
4931
4988
|
...(persistenceFailure ? { persistence: persistenceFailure } : {}),
|
|
4932
|
-
...(
|
|
4989
|
+
...(resultCode ? { code: resultCode } : {}),
|
|
4933
4990
|
};
|
|
4934
4991
|
}
|
|
4935
4992
|
|
|
@@ -130,6 +130,12 @@ import {
|
|
|
130
130
|
} from "../lib/capability-negotiation.js";
|
|
131
131
|
import { IterationBudget } from "../lib/iteration-budget.js";
|
|
132
132
|
import { CostBudget } from "../lib/cost-budget.js";
|
|
133
|
+
import {
|
|
134
|
+
classifyDenial,
|
|
135
|
+
DESTRUCTIVE_SHELL_DENIAL_CODE,
|
|
136
|
+
isDestructiveShellDenial,
|
|
137
|
+
recordDenial,
|
|
138
|
+
} from "../lib/repl-denials.js";
|
|
133
139
|
import {
|
|
134
140
|
resolvePermissionMode,
|
|
135
141
|
normalizePermissionMode,
|
|
@@ -965,6 +971,7 @@ async function runTurn(
|
|
|
965
971
|
cache_creation_input_tokens: 0,
|
|
966
972
|
};
|
|
967
973
|
const toolCalls = [];
|
|
974
|
+
const destructiveDenials = [];
|
|
968
975
|
let finalText = "";
|
|
969
976
|
let endReason = "complete";
|
|
970
977
|
let stopForCost = false;
|
|
@@ -1074,6 +1081,12 @@ async function runTurn(
|
|
|
1074
1081
|
}
|
|
1075
1082
|
case "tool-result": {
|
|
1076
1083
|
const err = event.error || event.result?.error || null;
|
|
1084
|
+
if (isDestructiveShellDenial(event)) {
|
|
1085
|
+
recordDenial(destructiveDenials, {
|
|
1086
|
+
...classifyDenial(event),
|
|
1087
|
+
at: now(),
|
|
1088
|
+
});
|
|
1089
|
+
}
|
|
1077
1090
|
// No invocation started for a preflight denial. For actual results,
|
|
1078
1091
|
// retain the adjacency fallback only for legacy events without IDs.
|
|
1079
1092
|
const lastCall =
|
|
@@ -1290,7 +1303,14 @@ async function runTurn(
|
|
|
1290
1303
|
) {
|
|
1291
1304
|
sideEffects.persist();
|
|
1292
1305
|
}
|
|
1293
|
-
return {
|
|
1306
|
+
return {
|
|
1307
|
+
finalText,
|
|
1308
|
+
endReason,
|
|
1309
|
+
usage,
|
|
1310
|
+
toolCalls,
|
|
1311
|
+
compactionUsageUnknown,
|
|
1312
|
+
destructiveDenials,
|
|
1313
|
+
};
|
|
1294
1314
|
}
|
|
1295
1315
|
|
|
1296
1316
|
function compactionUsageUnknownDiagnostic(event) {
|
|
@@ -6060,6 +6080,28 @@ async function runAgentHeadlessStreamInWorkspace(
|
|
|
6060
6080
|
break;
|
|
6061
6081
|
}
|
|
6062
6082
|
|
|
6083
|
+
if (outcome.destructiveDenials.length > 0) {
|
|
6084
|
+
emit({
|
|
6085
|
+
type: "denials_summary",
|
|
6086
|
+
count: outcome.destructiveDenials.length,
|
|
6087
|
+
denials: outcome.destructiveDenials,
|
|
6088
|
+
session_id: sessionId,
|
|
6089
|
+
turn: turns,
|
|
6090
|
+
});
|
|
6091
|
+
try {
|
|
6092
|
+
const { appendRecentDenials } =
|
|
6093
|
+
await import("../lib/permission-denial-store.js");
|
|
6094
|
+
appendRecentDenials(outcome.destructiveDenials, {
|
|
6095
|
+
sessionId,
|
|
6096
|
+
permissionMode: options.permissionMode || "default",
|
|
6097
|
+
cwd,
|
|
6098
|
+
source: "headless",
|
|
6099
|
+
});
|
|
6100
|
+
} catch {
|
|
6101
|
+
// The review store is best-effort; the refusal still reaches the client.
|
|
6102
|
+
}
|
|
6103
|
+
}
|
|
6104
|
+
|
|
6063
6105
|
if (outcome.endReason === "user-input-pending") {
|
|
6064
6106
|
if (!settleToolRoundsForHost("after-model")) break;
|
|
6065
6107
|
emit({
|
|
@@ -6156,9 +6198,12 @@ async function runAgentHeadlessStreamInWorkspace(
|
|
|
6156
6198
|
outcome.endReason === "budget-exhausted" ||
|
|
6157
6199
|
outcome.endReason === "max_turns";
|
|
6158
6200
|
const costStopped = outcome.endReason === "cost-budget-exhausted";
|
|
6201
|
+
const deniedDestructiveRequest =
|
|
6202
|
+
outcome.endReason === "complete" && outcome.destructiveDenials.length > 0;
|
|
6159
6203
|
const isError =
|
|
6160
6204
|
exhausted ||
|
|
6161
6205
|
costStopped ||
|
|
6206
|
+
deniedDestructiveRequest ||
|
|
6162
6207
|
outcome.endReason === "no-response" ||
|
|
6163
6208
|
outcome.endReason === "deferred-mutation-unresolved" ||
|
|
6164
6209
|
Boolean(persistenceFailure);
|
|
@@ -6200,13 +6245,16 @@ async function runAgentHeadlessStreamInWorkspace(
|
|
|
6200
6245
|
usage: outcome.usage,
|
|
6201
6246
|
...(transcriptRefs ? { transcript_refs: transcriptRefs } : {}),
|
|
6202
6247
|
...(persistenceFailure ? { persistence: persistenceFailure } : {}),
|
|
6248
|
+
...(deniedDestructiveRequest && !persistenceFailure
|
|
6249
|
+
? { code: DESTRUCTIVE_SHELL_DENIAL_CODE }
|
|
6250
|
+
: {}),
|
|
6203
6251
|
});
|
|
6204
6252
|
|
|
6205
6253
|
// --json-schema (P2): emit this turn's structured verdict right after its
|
|
6206
6254
|
// result — schema_digest + valid + value/errors from the turn's final text.
|
|
6207
6255
|
// Never falls back to free text; an unparseable/invalid reply reports
|
|
6208
6256
|
// valid:false with coded/pointered errors. Parity with single-prompt output.
|
|
6209
|
-
if (_jsonSchema) {
|
|
6257
|
+
if (_jsonSchema && !deniedDestructiveRequest) {
|
|
6210
6258
|
const parsed = _jso.extractJsonPayload(String(outcome.finalText ?? ""));
|
|
6211
6259
|
emit({
|
|
6212
6260
|
..._jso.buildStructuredResult(
|
|
@@ -130,11 +130,11 @@ export function assertBackgroundAgentWorkerAcceptsPrompt(
|
|
|
130
130
|
function ownsBackgroundAgentWorkerRecord(current, workerPid, workerGeneration) {
|
|
131
131
|
return Boolean(
|
|
132
132
|
current &&
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
133
|
+
(!current.workerGeneration ||
|
|
134
|
+
current.workerGeneration === workerGeneration) &&
|
|
135
|
+
(Number(current.workerClaimedPid) === workerPid ||
|
|
136
|
+
(current.workerClaimedPid == null &&
|
|
137
|
+
Number(current.workerPid ?? current.pid) === workerPid)),
|
|
138
138
|
);
|
|
139
139
|
}
|
|
140
140
|
|
|
@@ -148,11 +148,10 @@ export function createBackgroundAgentWorkerFinalStateUpdater({
|
|
|
148
148
|
now = Date.now,
|
|
149
149
|
}) {
|
|
150
150
|
return (current) => {
|
|
151
|
-
if (
|
|
152
|
-
current
|
|
153
|
-
workerPid,
|
|
154
|
-
|
|
155
|
-
)) {
|
|
151
|
+
if (
|
|
152
|
+
!current ||
|
|
153
|
+
!ownsBackgroundAgentWorkerRecord(current, workerPid, workerGeneration)
|
|
154
|
+
) {
|
|
156
155
|
return null;
|
|
157
156
|
}
|
|
158
157
|
if (current.status !== "running") {
|
|
@@ -1123,6 +1122,8 @@ function startTurn(argv, promptText) {
|
|
|
1123
1122
|
env: {
|
|
1124
1123
|
...process.env,
|
|
1125
1124
|
CC_BACKGROUND_AGENT_ID: job.id,
|
|
1125
|
+
CC_BACKGROUND_RESTORE_PLAN_PERMISSION:
|
|
1126
|
+
job.restorePlanPermission === true ? "1" : "",
|
|
1126
1127
|
CC_BACKGROUND_TURN_IPC_NONCE: turnIpcToken,
|
|
1127
1128
|
[BACKGROUND_TURN_BOOTSTRAP_ENV.nonce]: turnBootstrapNonce,
|
|
1128
1129
|
[BACKGROUND_TURN_BOOTSTRAP_ENV.workerGeneration]:
|