@khalilgharbaoui/opencode-claude-code-plugin 0.34.1 → 0.35.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/README.md +33 -1
- package/dist/index.js +825 -14
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
- package/skills/claude-code-plugin/SKILL.md +44 -0
package/dist/index.js
CHANGED
|
@@ -197,6 +197,9 @@ function configureLogger(input) {
|
|
|
197
197
|
function resolvedLogFile() {
|
|
198
198
|
return join(activeConfig.dir ?? DEFAULT_DIR, "plugin.log");
|
|
199
199
|
}
|
|
200
|
+
function describeLogFile() {
|
|
201
|
+
return { path: resolvedLogFile(), enabled: activeConfig.file && !fileLoggingDisabled };
|
|
202
|
+
}
|
|
200
203
|
function rotateIfNeeded(logFile) {
|
|
201
204
|
try {
|
|
202
205
|
const stat = statSync(logFile);
|
|
@@ -830,6 +833,135 @@ function reportUnrecognizedModel(stderr) {
|
|
|
830
833
|
warnedUnrecognizedModels.add(model);
|
|
831
834
|
log.warn(message, { model, ...floor ? { cliFloor: floor } : {} });
|
|
832
835
|
}
|
|
836
|
+
var HOOK_SUBTYPES = {
|
|
837
|
+
hook_started: "started",
|
|
838
|
+
hook_progress: "progress",
|
|
839
|
+
hook_response: "response"
|
|
840
|
+
};
|
|
841
|
+
function parseHookEvent(msg) {
|
|
842
|
+
if (msg.type !== "system") return null;
|
|
843
|
+
const phase = msg.subtype ? HOOK_SUBTYPES[msg.subtype] : void 0;
|
|
844
|
+
if (!phase) return null;
|
|
845
|
+
const raw = msg;
|
|
846
|
+
const hookName = str(raw.hook_name);
|
|
847
|
+
const hookEvent = str(raw.hook_event);
|
|
848
|
+
if (!hookName || !hookEvent) return null;
|
|
849
|
+
return {
|
|
850
|
+
phase,
|
|
851
|
+
hookId: str(raw.hook_id) ?? "unknown",
|
|
852
|
+
hookName,
|
|
853
|
+
hookEvent,
|
|
854
|
+
exitCode: num(raw.exit_code),
|
|
855
|
+
outcome: str(raw.outcome),
|
|
856
|
+
stderr: str(raw.stderr)
|
|
857
|
+
};
|
|
858
|
+
}
|
|
859
|
+
function isHookFailure(hook) {
|
|
860
|
+
if (hook.phase !== "response") return false;
|
|
861
|
+
if (hook.outcome === "error") return true;
|
|
862
|
+
if (hook.outcome === "cancelled" || hook.outcome === "success") return false;
|
|
863
|
+
return hook.exitCode !== void 0 && hook.exitCode !== 0;
|
|
864
|
+
}
|
|
865
|
+
var HOOK_STDERR_CAP = 200;
|
|
866
|
+
function describeHookFailure(hook) {
|
|
867
|
+
const how = hook.exitCode !== void 0 ? `exited ${hook.exitCode}` : `reported \`${hook.outcome ?? "error"}\``;
|
|
868
|
+
const tail = hook.stderr?.trim();
|
|
869
|
+
const detail = tail ? ` It wrote to stderr: ${tail.length > HOOK_STDERR_CAP ? `${tail.slice(0, HOOK_STDERR_CAP)}...` : tail}` : " It wrote nothing to stderr.";
|
|
870
|
+
return `Claude Code's "${hook.hookName}" hook (${hook.hookEvent}) ${how}, so whatever it contributes to the session is missing and every turn on this process runs without it. Fix or remove the hook in your Claude Code settings.${detail}`;
|
|
871
|
+
}
|
|
872
|
+
var warnedHookFailures = /* @__PURE__ */ new Set();
|
|
873
|
+
var lastHookFailures = /* @__PURE__ */ new Map();
|
|
874
|
+
function snapshotHookFailures() {
|
|
875
|
+
return [...lastHookFailures.values()];
|
|
876
|
+
}
|
|
877
|
+
function reportHookEvent(msg) {
|
|
878
|
+
const hook = parseHookEvent(msg);
|
|
879
|
+
if (!hook) return;
|
|
880
|
+
const data = {
|
|
881
|
+
hook: hook.hookName,
|
|
882
|
+
event: hook.hookEvent,
|
|
883
|
+
...hook.exitCode === void 0 ? {} : { exitCode: hook.exitCode },
|
|
884
|
+
...hook.outcome ? { outcome: hook.outcome } : {}
|
|
885
|
+
};
|
|
886
|
+
if (!isHookFailure(hook)) {
|
|
887
|
+
log.debug(`claude code hook ${hook.phase}`, data);
|
|
888
|
+
return;
|
|
889
|
+
}
|
|
890
|
+
const failure = {
|
|
891
|
+
hookName: hook.hookName,
|
|
892
|
+
hookEvent: hook.hookEvent,
|
|
893
|
+
exitCode: hook.exitCode,
|
|
894
|
+
outcome: hook.outcome,
|
|
895
|
+
stderr: hook.stderr?.trim().slice(0, HOOK_STDERR_CAP) ?? ""
|
|
896
|
+
};
|
|
897
|
+
lastHookFailures.set(`${hook.hookEvent}:${hook.hookName}`, failure);
|
|
898
|
+
const key = `${hook.hookEvent}:${hook.hookName}:${hook.outcome ?? "?"}:${hook.exitCode ?? "?"}`;
|
|
899
|
+
const message = describeHookFailure(hook);
|
|
900
|
+
if (warnedHookFailures.has(key)) {
|
|
901
|
+
log.debug(message, data);
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
warnedHookFailures.add(key);
|
|
905
|
+
log.warn(message, data);
|
|
906
|
+
}
|
|
907
|
+
function parseToolProgress(msg) {
|
|
908
|
+
if (msg.type !== "tool_progress") return null;
|
|
909
|
+
const raw = msg;
|
|
910
|
+
const frameToolUseId = str(raw.tool_use_id);
|
|
911
|
+
const toolName = str(raw.tool_name);
|
|
912
|
+
const elapsedSeconds = num(raw.elapsed_time_seconds);
|
|
913
|
+
if (!frameToolUseId || !toolName || elapsedSeconds === void 0) return null;
|
|
914
|
+
const retry = isRecord(raw.subagent_retry) ? raw.subagent_retry : void 0;
|
|
915
|
+
return {
|
|
916
|
+
toolUseId: str(raw.parent_tool_use_id) ?? frameToolUseId,
|
|
917
|
+
frameToolUseId,
|
|
918
|
+
toolName,
|
|
919
|
+
elapsedSeconds,
|
|
920
|
+
heartbeat: raw.heartbeat === true,
|
|
921
|
+
taskId: str(raw.task_id),
|
|
922
|
+
subagentType: str(raw.subagent_type),
|
|
923
|
+
subagentRetry: retry ? {
|
|
924
|
+
agentId: str(retry.agent_id) ?? "unknown",
|
|
925
|
+
attempt: num(retry.attempt) ?? 0,
|
|
926
|
+
maxRetries: num(retry.max_retries) ?? 0,
|
|
927
|
+
errorStatus: num(retry.error_status),
|
|
928
|
+
errorCategory: str(retry.error_category) ?? "unknown"
|
|
929
|
+
} : void 0
|
|
930
|
+
};
|
|
931
|
+
}
|
|
932
|
+
function describeToolProgress(progress) {
|
|
933
|
+
if (progress.subagentRetry) {
|
|
934
|
+
const retry = progress.subagentRetry;
|
|
935
|
+
return `Claude Code is retrying a subagent's API call (${retry.errorCategory}${retry.errorStatus === void 0 ? "" : ` ${retry.errorStatus}`}), attempt ${retry.attempt} of ${retry.maxRetries}. The turn is still running.`;
|
|
936
|
+
}
|
|
937
|
+
return `claude code tool still running: ${progress.toolName} at ${progress.elapsedSeconds}s`;
|
|
938
|
+
}
|
|
939
|
+
var reportedSubagentRetries = /* @__PURE__ */ new Set();
|
|
940
|
+
function reportToolProgress(msg) {
|
|
941
|
+
const progress = parseToolProgress(msg);
|
|
942
|
+
if (!progress) return;
|
|
943
|
+
const data = {
|
|
944
|
+
tool: progress.toolName,
|
|
945
|
+
toolUseId: progress.toolUseId,
|
|
946
|
+
elapsedSeconds: progress.elapsedSeconds,
|
|
947
|
+
...progress.taskId ? { taskId: progress.taskId } : {},
|
|
948
|
+
...progress.subagentType ? { subagentType: progress.subagentType } : {}
|
|
949
|
+
};
|
|
950
|
+
const message = describeToolProgress(progress);
|
|
951
|
+
if (!progress.subagentRetry) {
|
|
952
|
+
log.info(message, data);
|
|
953
|
+
return;
|
|
954
|
+
}
|
|
955
|
+
const retry = progress.subagentRetry;
|
|
956
|
+
const key = `${retry.agentId}:${retry.errorCategory}`;
|
|
957
|
+
const retryData = { ...data, ...retry };
|
|
958
|
+
if (reportedSubagentRetries.has(key)) {
|
|
959
|
+
log.debug(message, retryData);
|
|
960
|
+
return;
|
|
961
|
+
}
|
|
962
|
+
reportedSubagentRetries.add(key);
|
|
963
|
+
log.notice(message, retryData);
|
|
964
|
+
}
|
|
833
965
|
|
|
834
966
|
// src/plan-mode-question.ts
|
|
835
967
|
var QUESTION_TOOL_NAME = "question";
|
|
@@ -4996,6 +5128,621 @@ async function handleBtwCommand(client, input, options = {}) {
|
|
|
4996
5128
|
}
|
|
4997
5129
|
}
|
|
4998
5130
|
|
|
5131
|
+
// src/diagnostic-bundle.ts
|
|
5132
|
+
import { createHash as createHash3, randomBytes as randomBytes2 } from "crypto";
|
|
5133
|
+
import { openSync, readSync, closeSync, fstatSync, realpathSync } from "fs";
|
|
5134
|
+
import { homedir as homedir4 } from "os";
|
|
5135
|
+
|
|
5136
|
+
// src/log-messages.ts
|
|
5137
|
+
var PLUGIN_LOG_MESSAGES = /* @__PURE__ */ new Set([
|
|
5138
|
+
"ANTHROPIC_API_KEY/ANTHROPIC_AUTH_TOKEN detected; claude may bill as pay-as-you-go API usage instead of your subscription. Set provider option `ignoreAnthropicApiKey: true` to force subscription auth.",
|
|
5139
|
+
"ANTHROPIC_API_KEY/ANTHROPIC_AUTH_TOKEN detected; stripping it from claude spawns (ignoreAnthropicApiKey) so requests use your subscription auth, not pay-as-you-go API billing.",
|
|
5140
|
+
"Code Mode execute not forwarded: no model-visible input schema",
|
|
5141
|
+
"Code Mode execute not forwarded: read-only permission preset",
|
|
5142
|
+
"MCP tool not routed through the proxy: another proxy tool already holds that name, and it keeps it",
|
|
5143
|
+
"account failover declined; ending the turn",
|
|
5144
|
+
"agent effort override refused: unknown level",
|
|
5145
|
+
"agent model override refused: unknown model",
|
|
5146
|
+
"agent prompt cache ttl refused: unknown value",
|
|
5147
|
+
"auto-continuation stopped",
|
|
5148
|
+
"auto-continuing incomplete claude result",
|
|
5149
|
+
"btw: a turn is running but no claude process appeared for it",
|
|
5150
|
+
"btw: early aside failed; the message will ask again",
|
|
5151
|
+
"cannot interrupt this transport; waiting for the turn to end",
|
|
5152
|
+
"claude --version output unparseable",
|
|
5153
|
+
"claude already registers a different skill under this name; not bridging ours",
|
|
5154
|
+
"claude cli < 2.1.142 detected; Opus 4.7 thinking summaries unavailable. Run `npm i -g @anthropic-ai/claude-code` to upgrade.",
|
|
5155
|
+
"claude cli does not support --plugin-dir; opencode skills will not be bridged. Run `npm i -g @anthropic-ai/claude-code` to upgrade.",
|
|
5156
|
+
"claude code compacted its own context",
|
|
5157
|
+
"claude code reset its conversation",
|
|
5158
|
+
"claude finished the turn without a reply",
|
|
5159
|
+
"claude kept missing the probe deadline; keeping the conservative answer for this process",
|
|
5160
|
+
"claude process belongs to another account; starting fresh",
|
|
5161
|
+
"claude process closed without a result",
|
|
5162
|
+
"claude process did not exit; starting a fresh session",
|
|
5163
|
+
"claude process error",
|
|
5164
|
+
"claude process stdin error",
|
|
5165
|
+
"claude process still silent after respawn; ending turn",
|
|
5166
|
+
"claude session ID error, clearing session",
|
|
5167
|
+
"claude-code doctor failed to build its report",
|
|
5168
|
+
"claude-code plugin ready",
|
|
5169
|
+
"cleanup-stale: cache package.json update failed",
|
|
5170
|
+
"cleanup-stale: could not record the sweep marker",
|
|
5171
|
+
"cleanup-stale: error processing cache root",
|
|
5172
|
+
"cleanup-stale: rmSync failed",
|
|
5173
|
+
"delivering proxy results after interrupted continuation",
|
|
5174
|
+
"draining proxy calls queued between turns",
|
|
5175
|
+
"empty user content; sending sentinel to satisfy CLI",
|
|
5176
|
+
"every claude process is mid-turn; skipping LRU eviction",
|
|
5177
|
+
"failed to abort opencode session",
|
|
5178
|
+
"failed to build the agent registry for opencode 2",
|
|
5179
|
+
"failed to close the proxy server of an aborted turn",
|
|
5180
|
+
"failed to detect claude cli version",
|
|
5181
|
+
"failed to expand account provider",
|
|
5182
|
+
"failed to fetch opencode MCP runtime status",
|
|
5183
|
+
"failed to fetch opencode session directory",
|
|
5184
|
+
"failed to fetch opencode session messages",
|
|
5185
|
+
"failed to fetch opencode session parent",
|
|
5186
|
+
"failed to fetch opencode tool list",
|
|
5187
|
+
"failed to parse opencode config",
|
|
5188
|
+
"failed to prepare the failover account runtime; staying put",
|
|
5189
|
+
"failed to probe claude cli flag support",
|
|
5190
|
+
"failed to re-send envelope after respawn",
|
|
5191
|
+
"failed to set up doStream",
|
|
5192
|
+
"failed to stage opencode skill plugin dir",
|
|
5193
|
+
"failed to symlink shared capabilities; continuing anyway",
|
|
5194
|
+
"failed to write bridged MCP config",
|
|
5195
|
+
"failed to write control response",
|
|
5196
|
+
"failed to write interrupt control request",
|
|
5197
|
+
"failed to write system prompt file",
|
|
5198
|
+
"fallback model refused: unknown model",
|
|
5199
|
+
"falling back to the next model in the chain",
|
|
5200
|
+
"fast mode is in cooldown after a rate limit; this turn runs at standard speed and is billed at standard Opus rates, not the fast price shown in the model picker.",
|
|
5201
|
+
"file part without data, skipping",
|
|
5202
|
+
"ignoring a failover reset time that is not in the future",
|
|
5203
|
+
"ignoring unknown proxyOpencodeTools entries",
|
|
5204
|
+
"ignoring unknown proxyTools entries",
|
|
5205
|
+
"interactive permissionMode bypassPermissions ignored: Claude Code prompts for confirmation in the TUI",
|
|
5206
|
+
"interactive system prompt disabled; opencode agent prompts will not be appended",
|
|
5207
|
+
"interactive transport dropped non-text content blocks",
|
|
5208
|
+
"interactive turn failed",
|
|
5209
|
+
"interactiveBypass ignored: Claude Code prompts for bypassPermissions confirmation in the interactive TUI",
|
|
5210
|
+
"malformed data URI, skipping file part",
|
|
5211
|
+
"no active process to respawn (start watchdog); ending turn",
|
|
5212
|
+
"no proxyTools entry was recognised; nothing will be proxied this turn",
|
|
5213
|
+
"no stdout after envelope write; respawning claude process to resume conversation",
|
|
5214
|
+
"opencode 2 event subscription ended; deleted sessions keep their claude process until idle eviction",
|
|
5215
|
+
"pending proxy call arrived after stream close; rejecting",
|
|
5216
|
+
'permissionMode "plan" is enforced: claude cannot edit files or run commands, and --dangerously-skip-permissions is deliberately not passed so it stays that way. Headless Claude Code is not offered an ExitPlanMode tool, so nothing releases plan mode mid-session; approving a plan in chat does not unlock writes. Leaving plan mode means changing the config and restarting opencode.',
|
|
5217
|
+
`permissionPreset "read-only": this claude CLI has no --permission-prompts (2.1.263+), so permission requests are denied by the plugin's own can_use_tool handler instead of by the CLI. Same outcome, one layer fewer.`,
|
|
5218
|
+
'permissionPreset "read-only": this claude CLI has no --restricted (2.1.258+), so file reads are not confined to the working directory. The mutating tools are still refused via --disallowedTools and every permission request is denied.',
|
|
5219
|
+
"previous turn did not stop in time; this turn may see stale output",
|
|
5220
|
+
"previous turn still in flight; interrupting it",
|
|
5221
|
+
"process error",
|
|
5222
|
+
"provider model entry is partial; completing it from the pass-through template",
|
|
5223
|
+
"proxy call past its deadline, but opencode is still serving it; waiting",
|
|
5224
|
+
"proxy call still waiting, deadline approaching",
|
|
5225
|
+
"proxy call still waiting, no deadline",
|
|
5226
|
+
"proxy-mcp client closed a tool call before its result",
|
|
5227
|
+
"proxy-mcp dropping result for a closed tool call",
|
|
5228
|
+
"proxy-mcp interceptor failed",
|
|
5229
|
+
"proxy-mcp rejected a request",
|
|
5230
|
+
"proxy-mcp tool call timed out",
|
|
5231
|
+
"proxyOpencodeTools entry dropped: a proxy tool already holds that name, and it keeps it",
|
|
5232
|
+
"proxyOpencodeTools is set but opencode's tool registry did not answer; forwarding nothing this spawn",
|
|
5233
|
+
"refusing the pid-named scratch directory",
|
|
5234
|
+
"rejected pending proxy call",
|
|
5235
|
+
"remote URL images are not supported by Claude CLI, skipping",
|
|
5236
|
+
"replaying stdout the child emitted between turns",
|
|
5237
|
+
"result fallback timer fired \u2014 closing stream without result event",
|
|
5238
|
+
"shared Claude capability already exists; leaving untouched",
|
|
5239
|
+
"skipping MCP server with unknown type",
|
|
5240
|
+
"skipping local MCP server with no command",
|
|
5241
|
+
"skipping remote MCP server with no url",
|
|
5242
|
+
"stale scratch directory sweep failed",
|
|
5243
|
+
"task_batch resolving with child results missing",
|
|
5244
|
+
"timed out pending proxy call",
|
|
5245
|
+
"turn abort listener threw",
|
|
5246
|
+
"two different skills share a name; bridging the one the nearest root claimed",
|
|
5247
|
+
"unknown permissionPreset; no preset applied and every permission setting is left exactly as configured",
|
|
5248
|
+
"unsupported file part data type",
|
|
5249
|
+
"unsupported media type for Claude image block, skipping"
|
|
5250
|
+
]);
|
|
5251
|
+
|
|
5252
|
+
// src/diagnostic-bundle.ts
|
|
5253
|
+
var BUNDLE_ARGUMENTS = /* @__PURE__ */ new Set(["bundle", "issue", "report", "paste"]);
|
|
5254
|
+
function wantsDiagnosticBundle(argument) {
|
|
5255
|
+
return BUNDLE_ARGUMENTS.has(argument.trim().toLowerCase());
|
|
5256
|
+
}
|
|
5257
|
+
var BUNDLE_LEVELS = /* @__PURE__ */ new Set(["NOTICE", "WARN", "ERROR"]);
|
|
5258
|
+
var BUNDLE_MAX_LINES = 120;
|
|
5259
|
+
var BUNDLE_MAX_BYTES = 24e3;
|
|
5260
|
+
var BUNDLE_TAIL_BYTES = 512 * 1024;
|
|
5261
|
+
var BUNDLE_MAX_VALUE_CHARS = 200;
|
|
5262
|
+
var BUNDLE_MAX_ENUM_CHARS = 40;
|
|
5263
|
+
var BUNDLE_MAX_VERSION_CHARS = 60;
|
|
5264
|
+
var BUNDLE_MAX_NAME_CHARS = 64;
|
|
5265
|
+
var BUNDLE_MAX_ARRAY_ITEMS = 20;
|
|
5266
|
+
var BUNDLE_DATA_ALLOWLIST = {
|
|
5267
|
+
// booleans: every one of these is a decision the plugin made
|
|
5268
|
+
applied: "flag",
|
|
5269
|
+
attached: "flag",
|
|
5270
|
+
bridgeSkipNativeSkills: "flag",
|
|
5271
|
+
channelClosed: "flag",
|
|
5272
|
+
compaction: "flag",
|
|
5273
|
+
compactionMode: "flag",
|
|
5274
|
+
emitted: "flag",
|
|
5275
|
+
enabled: "flag",
|
|
5276
|
+
executed: "flag",
|
|
5277
|
+
isUsingOverage: "flag",
|
|
5278
|
+
hadProxyActivity: "flag",
|
|
5279
|
+
hadReasoning: "flag",
|
|
5280
|
+
hadStreamThinking: "flag",
|
|
5281
|
+
hadToolActivity: "flag",
|
|
5282
|
+
hasActiveProcess: "flag",
|
|
5283
|
+
hasInput: "flag",
|
|
5284
|
+
hasText: "flag",
|
|
5285
|
+
inFlight: "flag",
|
|
5286
|
+
anthropicApiKeyInEnv: "flag",
|
|
5287
|
+
includeHistoryContext: "flag",
|
|
5288
|
+
interactive: "flag",
|
|
5289
|
+
interactiveTransport: "flag",
|
|
5290
|
+
isError: "flag",
|
|
5291
|
+
planModeQuestion: "flag",
|
|
5292
|
+
kept: "flag",
|
|
5293
|
+
listsAgentTypes: "flag",
|
|
5294
|
+
opencodeHasQuestion: "flag",
|
|
5295
|
+
registryResolved: "flag",
|
|
5296
|
+
sse: "flag",
|
|
5297
|
+
strictMcpConfig: "flag",
|
|
5298
|
+
supported: "flag",
|
|
5299
|
+
turnStats: "flag",
|
|
5300
|
+
// counts and sizes: a length is a shape, never content
|
|
5301
|
+
attempts: "count",
|
|
5302
|
+
cacheReadTokens: "count",
|
|
5303
|
+
cacheWriteTokens: "count",
|
|
5304
|
+
code: "count",
|
|
5305
|
+
count: "count",
|
|
5306
|
+
dropped: "count",
|
|
5307
|
+
exitCode: "count",
|
|
5308
|
+
historyLength: "count",
|
|
5309
|
+
inputTokens: "count",
|
|
5310
|
+
lastTextLength: "count",
|
|
5311
|
+
lines: "count",
|
|
5312
|
+
liveDescriptionLength: "count",
|
|
5313
|
+
numTurns: "count",
|
|
5314
|
+
outputTokens: "count",
|
|
5315
|
+
permissionDenials: "count",
|
|
5316
|
+
pid: "count",
|
|
5317
|
+
port: "count",
|
|
5318
|
+
postTokens: "count",
|
|
5319
|
+
preTokens: "count",
|
|
5320
|
+
removed: "count",
|
|
5321
|
+
skills: "count",
|
|
5322
|
+
stderrBytes: "count",
|
|
5323
|
+
textLength: "count",
|
|
5324
|
+
tools: "count",
|
|
5325
|
+
total: "count",
|
|
5326
|
+
ageMs: "duration",
|
|
5327
|
+
delayMs: "duration",
|
|
5328
|
+
deadlineMs: "duration",
|
|
5329
|
+
durationApiMs: "duration",
|
|
5330
|
+
durationMs: "duration",
|
|
5331
|
+
elapsedMs: "duration",
|
|
5332
|
+
remainingMs: "duration",
|
|
5333
|
+
timeoutMs: "duration",
|
|
5334
|
+
waitedMs: "duration",
|
|
5335
|
+
costUsd: "money",
|
|
5336
|
+
// enums: a fixed vocabulary this package or the CLI defines
|
|
5337
|
+
apiKeySource: "enum",
|
|
5338
|
+
delivery: "enum",
|
|
5339
|
+
effort: "enum",
|
|
5340
|
+
finishReason: "enum",
|
|
5341
|
+
hash: "enum",
|
|
5342
|
+
hostApi: "enum",
|
|
5343
|
+
kind: "enum",
|
|
5344
|
+
level: "enum",
|
|
5345
|
+
mode: "enum",
|
|
5346
|
+
overageDisabledReason: "enum",
|
|
5347
|
+
overageStatus: "enum",
|
|
5348
|
+
permissionMode: "enum",
|
|
5349
|
+
preset: "enum",
|
|
5350
|
+
rateLimitType: "enum",
|
|
5351
|
+
reason: "enum",
|
|
5352
|
+
reasoningEffort: "enum",
|
|
5353
|
+
scope: "enum",
|
|
5354
|
+
signal: "enum",
|
|
5355
|
+
source: "enum",
|
|
5356
|
+
state: "enum",
|
|
5357
|
+
status: "enum",
|
|
5358
|
+
stopReason: "enum",
|
|
5359
|
+
subtype: "enum",
|
|
5360
|
+
transport: "enum",
|
|
5361
|
+
trigger: "enum",
|
|
5362
|
+
type: "enum",
|
|
5363
|
+
verdict: "enum",
|
|
5364
|
+
// names: identifiers the operator configured or Claude Code published. The
|
|
5365
|
+
// doctor table already prints the same class of value (providers, accounts,
|
|
5366
|
+
// proxyTools, MCP servers), so a bundle is no more revealing than the report
|
|
5367
|
+
// it is attached to.
|
|
5368
|
+
accounts: "name",
|
|
5369
|
+
agent: "name",
|
|
5370
|
+
bundled: "name",
|
|
5371
|
+
excluded: "name",
|
|
5372
|
+
excludeServers: "name",
|
|
5373
|
+
from: "name",
|
|
5374
|
+
joined: "name",
|
|
5375
|
+
left: "name",
|
|
5376
|
+
mappedName: "name",
|
|
5377
|
+
model: "name",
|
|
5378
|
+
name: "name",
|
|
5379
|
+
names: "name",
|
|
5380
|
+
opencodeAgent: "name",
|
|
5381
|
+
provider: "name",
|
|
5382
|
+
providerOptionsKeys: "name",
|
|
5383
|
+
providers: "name",
|
|
5384
|
+
proxyTools: "name",
|
|
5385
|
+
server: "name",
|
|
5386
|
+
servers: "name",
|
|
5387
|
+
skipped: "name",
|
|
5388
|
+
toolName: "name",
|
|
5389
|
+
toolNames: "name",
|
|
5390
|
+
cliFloor: "version",
|
|
5391
|
+
cliVersion: "version",
|
|
5392
|
+
opencode: "version",
|
|
5393
|
+
plugin: "version",
|
|
5394
|
+
version: "version",
|
|
5395
|
+
// ids: hashed, never printed. Correlation survives, identity does not.
|
|
5396
|
+
callId: "id",
|
|
5397
|
+
claudeSessionId: "id",
|
|
5398
|
+
id: "id",
|
|
5399
|
+
messageId: "id",
|
|
5400
|
+
newConversationId: "id",
|
|
5401
|
+
previousSessionId: "id",
|
|
5402
|
+
sessionId: "id",
|
|
5403
|
+
sessionID: "id",
|
|
5404
|
+
sessionKey: "id",
|
|
5405
|
+
toolCallId: "id",
|
|
5406
|
+
toolCallIds: "id",
|
|
5407
|
+
toolUseId: "id",
|
|
5408
|
+
// paths: home becomes `~`. The doctor table prints cwd and the CLI path
|
|
5409
|
+
// already, so withholding them here would buy nothing and cost the one
|
|
5410
|
+
// field that explains most "it picked the wrong directory" reports.
|
|
5411
|
+
claudeLoads: "path",
|
|
5412
|
+
cliPath: "path",
|
|
5413
|
+
configDir: "path",
|
|
5414
|
+
cwd: "path",
|
|
5415
|
+
dir: "path",
|
|
5416
|
+
notBridged: "path",
|
|
5417
|
+
path: "path",
|
|
5418
|
+
pluginDir: "path",
|
|
5419
|
+
resolved: "path",
|
|
5420
|
+
target: "path",
|
|
5421
|
+
url: "url",
|
|
5422
|
+
cliArgs: "argv",
|
|
5423
|
+
// The hook and tool_progress reporters (#g185), added when the two lanes
|
|
5424
|
+
// merged: their message text is built at runtime and redacted, so these
|
|
5425
|
+
// fields are what keeps a failed-hook WARN readable in a bundle. `stderr`
|
|
5426
|
+
// is deliberately absent, because a hook can print anything to it.
|
|
5427
|
+
hook: "name",
|
|
5428
|
+
hookName: "name",
|
|
5429
|
+
event: "enum",
|
|
5430
|
+
hookEvent: "enum",
|
|
5431
|
+
outcome: "enum",
|
|
5432
|
+
tool: "name",
|
|
5433
|
+
subagentType: "name",
|
|
5434
|
+
errorCategory: "enum",
|
|
5435
|
+
errorStatus: "count",
|
|
5436
|
+
elapsedSeconds: "count",
|
|
5437
|
+
attempt: "count",
|
|
5438
|
+
maxRetries: "count",
|
|
5439
|
+
taskId: "id",
|
|
5440
|
+
agentId: "id"
|
|
5441
|
+
};
|
|
5442
|
+
function shape(value) {
|
|
5443
|
+
if (typeof value === "string") return `[redacted, ${value.length} chars]`;
|
|
5444
|
+
let size;
|
|
5445
|
+
try {
|
|
5446
|
+
size = JSON.stringify(value)?.length ?? 0;
|
|
5447
|
+
} catch {
|
|
5448
|
+
size = 0;
|
|
5449
|
+
}
|
|
5450
|
+
return `[redacted, ${size} chars]`;
|
|
5451
|
+
}
|
|
5452
|
+
function createIdHasher(salt = randomBytes2(16).toString("hex")) {
|
|
5453
|
+
return (raw) => createHash3("sha256").update(salt).update("\0").update(raw).digest("hex").slice(0, 8);
|
|
5454
|
+
}
|
|
5455
|
+
function createRedactionContext(options = {}) {
|
|
5456
|
+
const home = options.home ?? homedir4();
|
|
5457
|
+
const homes = /* @__PURE__ */ new Set();
|
|
5458
|
+
if (home) homes.add(home);
|
|
5459
|
+
if (home) {
|
|
5460
|
+
try {
|
|
5461
|
+
homes.add(realpathSync.native(home));
|
|
5462
|
+
} catch {
|
|
5463
|
+
}
|
|
5464
|
+
}
|
|
5465
|
+
return {
|
|
5466
|
+
homes: [...homes].filter(Boolean).sort((a, b) => b.length - a.length),
|
|
5467
|
+
hash: createIdHasher(options.salt)
|
|
5468
|
+
};
|
|
5469
|
+
}
|
|
5470
|
+
function redactHome(text, context) {
|
|
5471
|
+
let out = text;
|
|
5472
|
+
for (const home of context.homes) out = out.split(home).join("~");
|
|
5473
|
+
return out;
|
|
5474
|
+
}
|
|
5475
|
+
var OPENCODE_SESSION_ID = /\bses_[A-Za-z0-9]{6,}/g;
|
|
5476
|
+
var UUID = /\b[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\b/g;
|
|
5477
|
+
function redactSessionIds(text, context) {
|
|
5478
|
+
return text.replace(OPENCODE_SESSION_ID, (raw) => `ses_${context.hash(raw)}`).replace(UUID, (raw) => `uuid_${context.hash(raw)}`);
|
|
5479
|
+
}
|
|
5480
|
+
function redactForPaste(text, context) {
|
|
5481
|
+
return redactSessionIds(redactHome(text, context), context);
|
|
5482
|
+
}
|
|
5483
|
+
var SAFE_NAME = /^[A-Za-z0-9][\w.:@+/-]*$/;
|
|
5484
|
+
var SAFE_ENUM = /^[A-Za-z0-9][\w.:@+/-]*$/;
|
|
5485
|
+
var SAFE_VERSION = /^[v0-9][\w.()+ -]*$/;
|
|
5486
|
+
var VERSION_PLACEHOLDERS = /* @__PURE__ */ new Set(["unknown", "none", "not detected", "unset"]);
|
|
5487
|
+
var SAFE_PATH = /^(?:[/~.]|[A-Za-z]:[\\/])/;
|
|
5488
|
+
var CLI_FLAG = /^-{1,2}[A-Za-z][\w-]*$/;
|
|
5489
|
+
var SUSPICIOUS = [
|
|
5490
|
+
/sk-[A-Za-z0-9]/,
|
|
5491
|
+
// Anthropic and OpenAI style API keys
|
|
5492
|
+
/\b(?:gh[pousr]_|xox[baprs]-|github_pat_)/,
|
|
5493
|
+
// GitHub and Slack tokens
|
|
5494
|
+
/[0-9a-f]{32,}/i,
|
|
5495
|
+
// hex secrets; the proxy authToken is 64 of these
|
|
5496
|
+
/[A-Za-z0-9+/]{40,}={0,2}/,
|
|
5497
|
+
// base64 blobs
|
|
5498
|
+
/BEGIN [A-Z ]*PRIVATE KEY/,
|
|
5499
|
+
/^bearer\b/i,
|
|
5500
|
+
/=/
|
|
5501
|
+
// any assignment: ANTHROPIC_API_KEY=…, token=…
|
|
5502
|
+
];
|
|
5503
|
+
function looksSecret(value) {
|
|
5504
|
+
return SUSPICIOUS.some((pattern) => pattern.test(value));
|
|
5505
|
+
}
|
|
5506
|
+
function sanitizeScalar(kind, value, context) {
|
|
5507
|
+
if (value === null) return null;
|
|
5508
|
+
switch (kind) {
|
|
5509
|
+
case "flag":
|
|
5510
|
+
return typeof value === "boolean" ? value : shape(value);
|
|
5511
|
+
case "count":
|
|
5512
|
+
case "duration":
|
|
5513
|
+
return typeof value === "number" && Number.isFinite(value) ? value : shape(value);
|
|
5514
|
+
case "money":
|
|
5515
|
+
return typeof value === "number" && Number.isFinite(value) ? Math.round(value * 1e4) / 1e4 : shape(value);
|
|
5516
|
+
case "enum": {
|
|
5517
|
+
if (typeof value === "boolean" || typeof value === "number") return value;
|
|
5518
|
+
if (typeof value !== "string") return shape(value);
|
|
5519
|
+
return value.length <= BUNDLE_MAX_ENUM_CHARS && SAFE_ENUM.test(value) && !looksSecret(value) ? value : shape(value);
|
|
5520
|
+
}
|
|
5521
|
+
case "name": {
|
|
5522
|
+
if (typeof value !== "string") return shape(value);
|
|
5523
|
+
return value.length <= BUNDLE_MAX_NAME_CHARS && SAFE_NAME.test(value) && !looksSecret(value) ? value : shape(value);
|
|
5524
|
+
}
|
|
5525
|
+
case "version": {
|
|
5526
|
+
if (typeof value !== "string") return shape(value);
|
|
5527
|
+
if (VERSION_PLACEHOLDERS.has(value)) return value;
|
|
5528
|
+
return value.length <= BUNDLE_MAX_VERSION_CHARS && SAFE_VERSION.test(value) && !looksSecret(value) ? value : shape(value);
|
|
5529
|
+
}
|
|
5530
|
+
case "id":
|
|
5531
|
+
return typeof value === "string" ? context.hash(value) : shape(value);
|
|
5532
|
+
case "path": {
|
|
5533
|
+
if (typeof value !== "string") return shape(value);
|
|
5534
|
+
if (!SAFE_PATH.test(value)) return sanitizeScalar("name", value, context);
|
|
5535
|
+
if (looksSecret(value)) return shape(value);
|
|
5536
|
+
const rewritten = redactHome(value, context);
|
|
5537
|
+
return rewritten.length <= BUNDLE_MAX_VALUE_CHARS && !/\s{2,}|[\n\r]/.test(rewritten) ? rewritten : shape(value);
|
|
5538
|
+
}
|
|
5539
|
+
case "url":
|
|
5540
|
+
return typeof value === "string" ? sanitizeUrl(value) : shape(value);
|
|
5541
|
+
case "argv":
|
|
5542
|
+
return shape(value);
|
|
5543
|
+
}
|
|
5544
|
+
}
|
|
5545
|
+
function sanitizeUrl(raw) {
|
|
5546
|
+
let parsed;
|
|
5547
|
+
try {
|
|
5548
|
+
parsed = new URL(raw);
|
|
5549
|
+
} catch {
|
|
5550
|
+
return shape(raw);
|
|
5551
|
+
}
|
|
5552
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return shape(raw);
|
|
5553
|
+
if (looksSecret(parsed.pathname)) return shape(raw);
|
|
5554
|
+
const credentials = parsed.username || parsed.password ? "[redacted]@" : "";
|
|
5555
|
+
const query = parsed.search ? `?[redacted, ${parsed.search.length - 1} chars]` : "";
|
|
5556
|
+
return `${parsed.protocol}//${credentials}${parsed.host}${parsed.pathname}${query}`;
|
|
5557
|
+
}
|
|
5558
|
+
function sanitizeArgv(value) {
|
|
5559
|
+
if (!Array.isArray(value)) return shape(value);
|
|
5560
|
+
const out = [];
|
|
5561
|
+
for (const item of value.slice(0, BUNDLE_MAX_ARRAY_ITEMS * 2)) {
|
|
5562
|
+
if (typeof item !== "string") {
|
|
5563
|
+
out.push(shape(item));
|
|
5564
|
+
continue;
|
|
5565
|
+
}
|
|
5566
|
+
if (!item.startsWith("-")) {
|
|
5567
|
+
out.push(`[redacted, ${item.length} chars]`);
|
|
5568
|
+
continue;
|
|
5569
|
+
}
|
|
5570
|
+
const equals = item.indexOf("=");
|
|
5571
|
+
if (equals === -1) {
|
|
5572
|
+
out.push(CLI_FLAG.test(item) ? item : shape(item));
|
|
5573
|
+
continue;
|
|
5574
|
+
}
|
|
5575
|
+
const flag = item.slice(0, equals);
|
|
5576
|
+
out.push(
|
|
5577
|
+
`${CLI_FLAG.test(flag) ? flag : "[redacted]"}=[redacted, ${item.length - equals - 1} chars]`
|
|
5578
|
+
);
|
|
5579
|
+
}
|
|
5580
|
+
if (value.length > out.length) out.push(`[+${value.length - out.length} more]`);
|
|
5581
|
+
return out;
|
|
5582
|
+
}
|
|
5583
|
+
var BUNDLE_MAX_DEPTH = 4;
|
|
5584
|
+
function kindFor(key) {
|
|
5585
|
+
return Object.prototype.hasOwnProperty.call(BUNDLE_DATA_ALLOWLIST, key) ? BUNDLE_DATA_ALLOWLIST[key] : void 0;
|
|
5586
|
+
}
|
|
5587
|
+
function sanitizeValue(key, value, context, depth = 0) {
|
|
5588
|
+
if (kindFor(key) === "argv") return sanitizeArgv(value);
|
|
5589
|
+
if (depth > BUNDLE_MAX_DEPTH) return shape(value);
|
|
5590
|
+
if (Array.isArray(value)) {
|
|
5591
|
+
const out = value.slice(0, BUNDLE_MAX_ARRAY_ITEMS).map((item) => sanitizeValue(key, item, context, depth + 1));
|
|
5592
|
+
if (value.length > out.length) out.push(`[+${value.length - out.length} more]`);
|
|
5593
|
+
return out;
|
|
5594
|
+
}
|
|
5595
|
+
if (value !== null && typeof value === "object") {
|
|
5596
|
+
return sanitizeLogData(value, context, depth + 1);
|
|
5597
|
+
}
|
|
5598
|
+
const kind = kindFor(key);
|
|
5599
|
+
return kind === void 0 ? shape(value) : sanitizeScalar(kind, value, context);
|
|
5600
|
+
}
|
|
5601
|
+
function sanitizeLogData(data, context, depth = 0) {
|
|
5602
|
+
const out = {};
|
|
5603
|
+
for (const [key, value] of Object.entries(data)) {
|
|
5604
|
+
const known = kindFor(key) !== void 0;
|
|
5605
|
+
const safeKey = known || key.length <= BUNDLE_MAX_NAME_CHARS && SAFE_NAME.test(key) && !looksSecret(key) ? key : `[redacted key, ${key.length} chars]`;
|
|
5606
|
+
out[safeKey] = sanitizeValue(key, value, context, depth);
|
|
5607
|
+
}
|
|
5608
|
+
return out;
|
|
5609
|
+
}
|
|
5610
|
+
var LOG_LINE = /^\[([^\]]+)\] \[opencode-claude-code\] (DEBUG|INFO|NOTICE|WARN|ERROR): ([\s\S]*)$/;
|
|
5611
|
+
function parseLogLine(raw) {
|
|
5612
|
+
const match = LOG_LINE.exec(raw);
|
|
5613
|
+
if (!match) return null;
|
|
5614
|
+
const rest = match[3];
|
|
5615
|
+
for (let index = rest.indexOf("{"); index !== -1; index = rest.indexOf("{", index + 1)) {
|
|
5616
|
+
let parsed;
|
|
5617
|
+
try {
|
|
5618
|
+
parsed = JSON.parse(rest.slice(index));
|
|
5619
|
+
} catch {
|
|
5620
|
+
continue;
|
|
5621
|
+
}
|
|
5622
|
+
if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
5623
|
+
return {
|
|
5624
|
+
timestamp: match[1],
|
|
5625
|
+
level: match[2],
|
|
5626
|
+
message: rest.slice(0, index).trimEnd(),
|
|
5627
|
+
data: parsed
|
|
5628
|
+
};
|
|
5629
|
+
}
|
|
5630
|
+
}
|
|
5631
|
+
return { timestamp: match[1], level: match[2], message: rest, data: null };
|
|
5632
|
+
}
|
|
5633
|
+
function redactLogLine(raw, context) {
|
|
5634
|
+
const parsed = parseLogLine(raw);
|
|
5635
|
+
if (!parsed || !BUNDLE_LEVELS.has(parsed.level)) return null;
|
|
5636
|
+
const message = PLUGIN_LOG_MESSAGES.has(parsed.message) ? parsed.message : `[redacted message, ${parsed.message.length} chars]`;
|
|
5637
|
+
const head = `[${parsed.timestamp}] ${parsed.level}: ${message}`;
|
|
5638
|
+
if (!parsed.data || Object.keys(parsed.data).length === 0) return head;
|
|
5639
|
+
return `${head} ${JSON.stringify(sanitizeLogData(parsed.data, context))}`;
|
|
5640
|
+
}
|
|
5641
|
+
function readLogTail(path10, maxBytes = BUNDLE_TAIL_BYTES) {
|
|
5642
|
+
const fd = openSync(path10, "r");
|
|
5643
|
+
try {
|
|
5644
|
+
const size = fstatSync(fd).size;
|
|
5645
|
+
const length = Math.min(size, maxBytes);
|
|
5646
|
+
const buffer = Buffer.allocUnsafe(length);
|
|
5647
|
+
readSync(fd, buffer, 0, length, size - length);
|
|
5648
|
+
const text = buffer.toString("utf8");
|
|
5649
|
+
if (length < size) {
|
|
5650
|
+
const newline = text.indexOf("\n");
|
|
5651
|
+
return newline === -1 ? "" : text.slice(newline + 1);
|
|
5652
|
+
}
|
|
5653
|
+
return text;
|
|
5654
|
+
} finally {
|
|
5655
|
+
closeSync(fd);
|
|
5656
|
+
}
|
|
5657
|
+
}
|
|
5658
|
+
var BUNDLE_HEADER = "**Redacted log bundle**";
|
|
5659
|
+
var BUNDLE_PREAMBLE = [
|
|
5660
|
+
"Safe to paste into a GitHub issue. Built by an allowlist, not a filter: a line",
|
|
5661
|
+
"keeps its timestamp, its level, its message **only** when that message is a",
|
|
5662
|
+
"constant in this package's own source, and only those data fields whose values",
|
|
5663
|
+
"are non-secret by type (versions, counts, flags, enums, durations, exit codes,",
|
|
5664
|
+
"model and tool and server names). Everything else, including every unknown",
|
|
5665
|
+
"field, is replaced by `[redacted, N chars]`. Session ids are a per-bundle hash,",
|
|
5666
|
+
"so lines correlate here and nowhere else, and your home directory is `~`.",
|
|
5667
|
+
"",
|
|
5668
|
+
"Never included: prompt or reply text, system prompts, tool inputs or outputs,",
|
|
5669
|
+
"file contents, environment values, bearer tokens, API keys, `Authorization`",
|
|
5670
|
+
"headers, MCP server env or headers, URL credentials or query strings, or the",
|
|
5671
|
+
"raw spawn argv."
|
|
5672
|
+
].join("\n");
|
|
5673
|
+
var BUNDLE_LOGGING_OFF = [
|
|
5674
|
+
"File logging is **off**, so there is nothing to bundle. The report above still",
|
|
5675
|
+
"answers versions, config shape and live processes.",
|
|
5676
|
+
"",
|
|
5677
|
+
"Turn it on for one run and reproduce the problem:",
|
|
5678
|
+
"",
|
|
5679
|
+
"```sh",
|
|
5680
|
+
"OPENCODE_CLAUDE_CODE_LOG_FILE=1 opencode",
|
|
5681
|
+
"```",
|
|
5682
|
+
"",
|
|
5683
|
+
"or set it permanently in `opencode.json` under",
|
|
5684
|
+
"`provider.claude-code.options.logging`:",
|
|
5685
|
+
"",
|
|
5686
|
+
"```json",
|
|
5687
|
+
'{ "logging": { "file": true } }',
|
|
5688
|
+
"```",
|
|
5689
|
+
"",
|
|
5690
|
+
"Then run `/claude-code-doctor bundle` again. Logging is read once at process",
|
|
5691
|
+
"start, so a running window has to be relaunched."
|
|
5692
|
+
].join("\n");
|
|
5693
|
+
function buildLogBundleSection(input) {
|
|
5694
|
+
const lines = [BUNDLE_HEADER, "", BUNDLE_PREAMBLE, ""];
|
|
5695
|
+
if (!input.fileLogging) {
|
|
5696
|
+
lines.push(BUNDLE_LOGGING_OFF);
|
|
5697
|
+
return lines.join("\n");
|
|
5698
|
+
}
|
|
5699
|
+
let tail;
|
|
5700
|
+
try {
|
|
5701
|
+
tail = (input.readTailImpl ?? readLogTail)(input.logPath, BUNDLE_TAIL_BYTES);
|
|
5702
|
+
} catch (error) {
|
|
5703
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
5704
|
+
lines.push(
|
|
5705
|
+
`File logging is on, but the log could not be read: ${redactHome(reason, input.context)}`
|
|
5706
|
+
);
|
|
5707
|
+
return lines.join("\n");
|
|
5708
|
+
}
|
|
5709
|
+
const raw = tail.split("\n");
|
|
5710
|
+
let scanned = 0;
|
|
5711
|
+
const kept = [];
|
|
5712
|
+
for (let index = raw.length - 1; index >= 0; index--) {
|
|
5713
|
+
const line = raw[index];
|
|
5714
|
+
if (!line) continue;
|
|
5715
|
+
if (parseLogLine(line)) scanned++;
|
|
5716
|
+
const redacted = redactLogLine(line, input.context);
|
|
5717
|
+
if (redacted === null) continue;
|
|
5718
|
+
if (kept.length >= BUNDLE_MAX_LINES) break;
|
|
5719
|
+
if (kept.reduce((total, entry) => total + entry.length + 1, 0) + redacted.length > BUNDLE_MAX_BYTES) {
|
|
5720
|
+
break;
|
|
5721
|
+
}
|
|
5722
|
+
kept.push(redacted);
|
|
5723
|
+
}
|
|
5724
|
+
kept.reverse();
|
|
5725
|
+
const dropped = Math.max(0, scanned - kept.length);
|
|
5726
|
+
lines.push(
|
|
5727
|
+
`Log: \`${redactHome(input.logPath, input.context)}\`. ${kept.length} NOTICE/WARN/ERROR line${kept.length === 1 ? "" : "s"} kept of ${scanned} scanned (caps: ${BUNDLE_MAX_LINES} lines, ${BUNDLE_MAX_BYTES} bytes, last ${BUNDLE_TAIL_BYTES} bytes of the file).`
|
|
5728
|
+
);
|
|
5729
|
+
if (dropped > 0) {
|
|
5730
|
+
lines.push("");
|
|
5731
|
+
lines.push(
|
|
5732
|
+
`${dropped} earlier or lower-level line${dropped === 1 ? " was" : "s were"} not included.`
|
|
5733
|
+
);
|
|
5734
|
+
}
|
|
5735
|
+
lines.push("");
|
|
5736
|
+
lines.push("```text");
|
|
5737
|
+
if (kept.length === 0) {
|
|
5738
|
+
lines.push("No NOTICE, WARN or ERROR line in the retained log.");
|
|
5739
|
+
} else {
|
|
5740
|
+
lines.push(...kept);
|
|
5741
|
+
}
|
|
5742
|
+
lines.push("```");
|
|
5743
|
+
return lines.join("\n");
|
|
5744
|
+
}
|
|
5745
|
+
|
|
4999
5746
|
// src/plan-usage.ts
|
|
5000
5747
|
import { execFile as execFile2 } from "child_process";
|
|
5001
5748
|
var PLAN_USAGE_ARGUMENTS = /* @__PURE__ */ new Set(["usage", "cost", "stats", "limits"]);
|
|
@@ -5219,7 +5966,7 @@ function logStartupDiagnostics(providers, opencodeVersion) {
|
|
|
5219
5966
|
|
|
5220
5967
|
// src/doctor.ts
|
|
5221
5968
|
var DOCTOR_COMMAND = "claude-code-doctor";
|
|
5222
|
-
var DOCTOR_COMMAND_DESCRIPTION = "Report what the Claude Code plugin sees: versions, cwd, live processes, pending proxy calls. Add `usage` for plan windows";
|
|
5969
|
+
var DOCTOR_COMMAND_DESCRIPTION = "Report what the Claude Code plugin sees: versions, cwd, live processes, pending proxy calls. Add `usage` for plan windows, or `bundle` for a redacted log you can paste into an issue";
|
|
5223
5970
|
var DOCTOR_MARKER = "\u258C **claude-code doctor**";
|
|
5224
5971
|
function isRecord3(value) {
|
|
5225
5972
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
@@ -5278,6 +6025,9 @@ function describePermissionPresets(rows) {
|
|
|
5278
6025
|
return `${row.provider}: ${row.preset}${suffix}`;
|
|
5279
6026
|
}).join(", ");
|
|
5280
6027
|
}
|
|
6028
|
+
function tableCell(text) {
|
|
6029
|
+
return text.replace(/\r?\n/g, " ").replace(/\|/g, "\\|");
|
|
6030
|
+
}
|
|
5281
6031
|
function formatDoctorReport(report) {
|
|
5282
6032
|
const lines = [];
|
|
5283
6033
|
lines.push(DOCTOR_MARKER);
|
|
@@ -5356,7 +6106,7 @@ function formatDoctorReport(report) {
|
|
|
5356
6106
|
lines.push("| server | category | Claude Code said |");
|
|
5357
6107
|
lines.push("|---|---|---|");
|
|
5358
6108
|
for (const error of report.mcpServerErrors) {
|
|
5359
|
-
lines.push(`| ${error.name} | \`${error.type}\` | ${error.message || "no detail"} |`);
|
|
6109
|
+
lines.push(`| ${error.name} | \`${error.type}\` | ${tableCell(error.message) || "no detail"} |`);
|
|
5360
6110
|
}
|
|
5361
6111
|
lines.push("");
|
|
5362
6112
|
lines.push("A skipped server is missing from the model's tools with no other sign of it.");
|
|
@@ -5369,9 +6119,25 @@ function formatDoctorReport(report) {
|
|
|
5369
6119
|
lines.push("|---|---|---|---|");
|
|
5370
6120
|
for (const failure of report.pluginLoadFailures) {
|
|
5371
6121
|
lines.push(
|
|
5372
|
-
`| ${failure.plugin} | ${failure.kind} | \`${failure.type}\` | ${failure.message || "no detail"} |`
|
|
6122
|
+
`| ${failure.plugin} | ${failure.kind} | \`${failure.type}\` | ${tableCell(failure.message) || "no detail"} |`
|
|
6123
|
+
);
|
|
6124
|
+
}
|
|
6125
|
+
}
|
|
6126
|
+
if (report.hookFailures.length > 0) {
|
|
6127
|
+
lines.push("");
|
|
6128
|
+
lines.push("**Hooks Claude Code ran that failed**");
|
|
6129
|
+
lines.push("");
|
|
6130
|
+
lines.push("| hook | event | exit | outcome | its stderr |");
|
|
6131
|
+
lines.push("|---|---|---|---|---|");
|
|
6132
|
+
for (const failure of report.hookFailures) {
|
|
6133
|
+
lines.push(
|
|
6134
|
+
`| ${failure.hookName} | ${failure.hookEvent} | ${failure.exitCode ?? "n/a"} | ${failure.outcome ?? "unknown"} | ${tableCell(failure.stderr) || "nothing"} |`
|
|
5373
6135
|
);
|
|
5374
6136
|
}
|
|
6137
|
+
lines.push("");
|
|
6138
|
+
lines.push(
|
|
6139
|
+
"These are your own Claude Code hooks, not opencode's. A failed hook's contribution to the session is missing and the turn succeeds anyway. Only the hook's stderr is shown: its stdout is spliced into the model's context and has no business in a bug report."
|
|
6140
|
+
);
|
|
5375
6141
|
}
|
|
5376
6142
|
lines.push("");
|
|
5377
6143
|
lines.push("**Background subagents**");
|
|
@@ -5529,6 +6295,7 @@ async function gatherDoctorReport(options) {
|
|
|
5529
6295
|
proxyServers,
|
|
5530
6296
|
mcpServerErrors: snapshotMcpServerErrors(),
|
|
5531
6297
|
pluginLoadFailures: snapshotPluginLoadFailures(),
|
|
6298
|
+
hookFailures: snapshotHookFailures(),
|
|
5532
6299
|
planUsage,
|
|
5533
6300
|
backgroundSubagents: {
|
|
5534
6301
|
gate: snapshotBackgroundSubagentGate(),
|
|
@@ -5536,6 +6303,42 @@ async function gatherDoctorReport(options) {
|
|
|
5536
6303
|
}
|
|
5537
6304
|
};
|
|
5538
6305
|
}
|
|
6306
|
+
function decorateDoctorReport(report, options) {
|
|
6307
|
+
if (!wantsDiagnosticBundle(options.argument ?? "")) return report;
|
|
6308
|
+
const context = options.redactionContextImpl ?? createRedactionContext();
|
|
6309
|
+
const logFile = (options.logFileImpl ?? describeLogFile)();
|
|
6310
|
+
const section = buildLogBundleSection({
|
|
6311
|
+
logPath: logFile.path,
|
|
6312
|
+
fileLogging: logFile.enabled,
|
|
6313
|
+
context,
|
|
6314
|
+
readTailImpl: options.readLogTailImpl
|
|
6315
|
+
});
|
|
6316
|
+
return redactForPaste(`${report}
|
|
6317
|
+
|
|
6318
|
+
${section}`, context);
|
|
6319
|
+
}
|
|
6320
|
+
function withholdFreeText(report) {
|
|
6321
|
+
const withhold = (text) => text ? `[redacted, ${text.length} chars]` : text;
|
|
6322
|
+
return {
|
|
6323
|
+
...report,
|
|
6324
|
+
mcpServerErrors: report.mcpServerErrors.map((error) => ({
|
|
6325
|
+
...error,
|
|
6326
|
+
message: withhold(error.message)
|
|
6327
|
+
})),
|
|
6328
|
+
pluginLoadFailures: report.pluginLoadFailures.map((failure) => ({
|
|
6329
|
+
...failure,
|
|
6330
|
+
message: withhold(failure.message)
|
|
6331
|
+
})),
|
|
6332
|
+
hookFailures: report.hookFailures.map((failure) => ({
|
|
6333
|
+
...failure,
|
|
6334
|
+
stderr: withhold(failure.stderr)
|
|
6335
|
+
}))
|
|
6336
|
+
};
|
|
6337
|
+
}
|
|
6338
|
+
function renderDoctorReport(report, options) {
|
|
6339
|
+
const bundle = wantsDiagnosticBundle(options.argument ?? "");
|
|
6340
|
+
return decorateDoctorReport(formatDoctorReport(bundle ? withholdFreeText(report) : report), options);
|
|
6341
|
+
}
|
|
5539
6342
|
async function buildDoctorReport(options) {
|
|
5540
6343
|
try {
|
|
5541
6344
|
const report = await gatherDoctorReport(options);
|
|
@@ -5548,10 +6351,11 @@ async function buildDoctorReport(options) {
|
|
|
5548
6351
|
proxyServers: report.proxyServers.map((server2) => server2.auth.status),
|
|
5549
6352
|
mcpServerErrors: report.mcpServerErrors.length,
|
|
5550
6353
|
pluginLoadFailures: report.pluginLoadFailures.length,
|
|
6354
|
+
hookFailures: report.hookFailures.length,
|
|
5551
6355
|
planUsage: report.planUsage.status,
|
|
5552
6356
|
backgroundSubagents: report.backgroundSubagents.gate?.supported ?? "not read"
|
|
5553
6357
|
});
|
|
5554
|
-
return
|
|
6358
|
+
return renderDoctorReport(report, options);
|
|
5555
6359
|
} catch (error) {
|
|
5556
6360
|
const message = error instanceof Error ? error.message : String(error);
|
|
5557
6361
|
log.warn("claude-code doctor failed to build its report", { error: message });
|
|
@@ -7673,7 +8477,7 @@ function spawnInteractiveProcess(opts) {
|
|
|
7673
8477
|
|
|
7674
8478
|
// src/prompts.ts
|
|
7675
8479
|
import { readFileSync as readFileSync5, writeFileSync as writeFileSync4 } from "fs";
|
|
7676
|
-
import { homedir as
|
|
8480
|
+
import { homedir as homedir7 } from "os";
|
|
7677
8481
|
import { randomUUID as randomUUID5 } from "crypto";
|
|
7678
8482
|
import { dirname as dirname5, join as join8 } from "path";
|
|
7679
8483
|
function readPromptFileIfPresent(path10) {
|
|
@@ -7796,7 +8600,7 @@ ${options.compressionSummary.trim()}`
|
|
|
7796
8600
|
for (const s of extraSystemContent) {
|
|
7797
8601
|
if (s.trim()) parts.push(s.trim());
|
|
7798
8602
|
}
|
|
7799
|
-
const configRoot = process.env.XDG_CONFIG_HOME ?? join8(
|
|
8603
|
+
const configRoot = process.env.XDG_CONFIG_HOME ?? join8(homedir7(), ".config");
|
|
7800
8604
|
const globalAgents = readPromptFileIfPresent(join8(configRoot, "opencode", "AGENTS.md"));
|
|
7801
8605
|
const workspaceAgents = nearestWorkspaceAgentsPrompt(cwd);
|
|
7802
8606
|
const forwarded = extraSystemContent.join("\n\n");
|
|
@@ -9343,6 +10147,13 @@ function createLineHandler(state, ctx) {
|
|
|
9343
10147
|
state.endTextBlock();
|
|
9344
10148
|
}
|
|
9345
10149
|
}
|
|
10150
|
+
if (msg.type === "system") {
|
|
10151
|
+
reportHookEvent(msg);
|
|
10152
|
+
}
|
|
10153
|
+
if (msg.type === "tool_progress") {
|
|
10154
|
+
reportToolProgress(msg);
|
|
10155
|
+
return;
|
|
10156
|
+
}
|
|
9346
10157
|
if (msg.type === "conversation_reset") {
|
|
9347
10158
|
const note = reportConversationReset(msg);
|
|
9348
10159
|
if (note) {
|
|
@@ -11663,11 +12474,11 @@ import {
|
|
|
11663
12474
|
existsSync as existsSync3,
|
|
11664
12475
|
mkdirSync as mkdirSync4,
|
|
11665
12476
|
readFileSync as readFileSync6,
|
|
11666
|
-
realpathSync as
|
|
12477
|
+
realpathSync as realpathSync4,
|
|
11667
12478
|
rmSync as rmSync3,
|
|
11668
12479
|
writeFileSync as writeFileSync5
|
|
11669
12480
|
} from "fs";
|
|
11670
|
-
import { homedir as
|
|
12481
|
+
import { homedir as homedir8 } from "os";
|
|
11671
12482
|
import { dirname as dirname6, join as join9, resolve as resolve5 } from "path";
|
|
11672
12483
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
11673
12484
|
var STALE_PACKAGE_NAME = "opencode-claude-code-plugin";
|
|
@@ -11677,12 +12488,12 @@ function candidateCacheRoots() {
|
|
|
11677
12488
|
const xdg = process.env.XDG_CACHE_HOME;
|
|
11678
12489
|
return [
|
|
11679
12490
|
xdg ? join9(xdg, "opencode") : null,
|
|
11680
|
-
join9(
|
|
11681
|
-
join9(
|
|
12491
|
+
join9(homedir8(), ".cache", "opencode"),
|
|
12492
|
+
join9(homedir8(), "Library", "Caches", "opencode")
|
|
11682
12493
|
].filter((p) => Boolean(p));
|
|
11683
12494
|
}
|
|
11684
12495
|
function userOpencodeJsonPath() {
|
|
11685
|
-
const xdgConfig = process.env.XDG_CONFIG_HOME ?? join9(
|
|
12496
|
+
const xdgConfig = process.env.XDG_CONFIG_HOME ?? join9(homedir8(), ".config");
|
|
11686
12497
|
return join9(xdgConfig, "opencode", "opencode.json");
|
|
11687
12498
|
}
|
|
11688
12499
|
function userIntendsToUseUnscoped() {
|
|
@@ -11702,7 +12513,7 @@ function userIntendsToUseUnscoped() {
|
|
|
11702
12513
|
function ourLoadedDir() {
|
|
11703
12514
|
try {
|
|
11704
12515
|
const filePath = fileURLToPath3(import.meta.url);
|
|
11705
|
-
return
|
|
12516
|
+
return realpathSync4(resolve5(filePath, "..", ".."));
|
|
11706
12517
|
} catch {
|
|
11707
12518
|
return null;
|
|
11708
12519
|
}
|
|
@@ -11717,7 +12528,7 @@ function ourVersion(dir) {
|
|
|
11717
12528
|
}
|
|
11718
12529
|
}
|
|
11719
12530
|
function markerPath() {
|
|
11720
|
-
const stateRoot = process.env.XDG_STATE_HOME ?? join9(
|
|
12531
|
+
const stateRoot = process.env.XDG_STATE_HOME ?? join9(homedir8(), ".local", "state");
|
|
11721
12532
|
return join9(stateRoot, "opencode-claude-code-plugin", "cleanup-stale.json");
|
|
11722
12533
|
}
|
|
11723
12534
|
function markerVersion() {
|
|
@@ -11771,7 +12582,7 @@ function cleanupOne(cacheRoot, ourDir) {
|
|
|
11771
12582
|
if (!existsSync3(stalePath)) return;
|
|
11772
12583
|
let realStalePath = stalePath;
|
|
11773
12584
|
try {
|
|
11774
|
-
realStalePath =
|
|
12585
|
+
realStalePath = realpathSync4(stalePath);
|
|
11775
12586
|
} catch {
|
|
11776
12587
|
}
|
|
11777
12588
|
if (ourDir && realStalePath === ourDir) return;
|