charness 4.1.0 → 4.2.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/CHANGELOG.md +52 -0
- package/DEVELOPMENT.md +11 -5
- package/{COMMERCIAL-LICENSE.md → LICENSE-COMMERCIAL.md} +1 -1
- package/MIGRATION_3_TO_4.md +1 -1
- package/README.md +4 -1
- package/SETUP.md +37 -9
- package/agent-plugin/skills/charness-delegate-claude/SKILL.md +1 -0
- package/agent-plugin/skills/charness-orchestration/SKILL.md +1 -0
- package/dist/adapters/adapterNames.d.ts +2 -0
- package/dist/adapters/adapterNames.d.ts.map +1 -1
- package/dist/adapters/adapterNames.js +3 -1
- package/dist/adapters/adapterNames.js.map +1 -1
- package/dist/adapters/claudeJsonStreamAdapter.d.ts +74 -5
- package/dist/adapters/claudeJsonStreamAdapter.d.ts.map +1 -1
- package/dist/adapters/claudeJsonStreamAdapter.js +164 -20
- package/dist/adapters/claudeJsonStreamAdapter.js.map +1 -1
- package/dist/adapters/openCodeAdapter.d.ts +31 -2
- package/dist/adapters/openCodeAdapter.d.ts.map +1 -1
- package/dist/adapters/openCodeAdapter.js +84 -8
- package/dist/adapters/openCodeAdapter.js.map +1 -1
- package/dist/adapters/terminalAdapter.d.ts.map +1 -1
- package/dist/adapters/terminalAdapter.js +2 -1
- package/dist/adapters/terminalAdapter.js.map +1 -1
- package/dist/bot.d.ts.map +1 -1
- package/dist/bot.js +769 -118
- package/dist/bot.js.map +1 -1
- package/dist/cli/claudeProfiles.d.ts +3 -0
- package/dist/cli/claudeProfiles.d.ts.map +1 -1
- package/dist/cli/claudeProfiles.js +8 -0
- package/dist/cli/claudeProfiles.js.map +1 -1
- package/dist/connectors/jira/answerSink.d.ts +8 -0
- package/dist/connectors/jira/answerSink.d.ts.map +1 -1
- package/dist/connectors/jira/answerSink.js +15 -0
- package/dist/connectors/jira/answerSink.js.map +1 -1
- package/dist/connectors/jira/config.d.ts +16 -0
- package/dist/connectors/jira/config.d.ts.map +1 -1
- package/dist/connectors/jira/config.js +21 -2
- package/dist/connectors/jira/config.js.map +1 -1
- package/dist/connectors/jira/connector.d.ts +10 -3
- package/dist/connectors/jira/connector.d.ts.map +1 -1
- package/dist/connectors/jira/connector.js +21 -3
- package/dist/connectors/jira/connector.js.map +1 -1
- package/dist/connectors/jira/inbound.d.ts +200 -18
- package/dist/connectors/jira/inbound.d.ts.map +1 -1
- package/dist/connectors/jira/inbound.js +814 -43
- package/dist/connectors/jira/inbound.js.map +1 -1
- package/dist/connectors/jira/prompt.d.ts +46 -0
- package/dist/connectors/jira/prompt.d.ts.map +1 -1
- package/dist/connectors/jira/prompt.js +123 -15
- package/dist/connectors/jira/prompt.js.map +1 -1
- package/dist/connectors/jira/trigger.d.ts +27 -4
- package/dist/connectors/jira/trigger.d.ts.map +1 -1
- package/dist/connectors/jira/trigger.js +35 -1
- package/dist/connectors/jira/trigger.js.map +1 -1
- package/dist/connectors/jira/triggerLog.d.ts +60 -5
- package/dist/connectors/jira/triggerLog.d.ts.map +1 -1
- package/dist/connectors/jira/triggerLog.js +116 -7
- package/dist/connectors/jira/triggerLog.js.map +1 -1
- package/dist/connectors/telegram/commands/botCore.d.ts +5 -2
- package/dist/connectors/telegram/commands/botCore.d.ts.map +1 -1
- package/dist/connectors/telegram/commands/claudeAccounts.d.ts +5 -0
- package/dist/connectors/telegram/commands/claudeAccounts.d.ts.map +1 -1
- package/dist/connectors/telegram/commands/claudeAccounts.js +15 -39
- package/dist/connectors/telegram/commands/claudeAccounts.js.map +1 -1
- package/dist/connectors/telegram/commands/compaction.d.ts +6 -0
- package/dist/connectors/telegram/commands/compaction.d.ts.map +1 -1
- package/dist/connectors/telegram/commands/compaction.js +8 -1
- package/dist/connectors/telegram/commands/compaction.js.map +1 -1
- package/dist/connectors/telegram/commands/questionSetAside.d.ts +111 -0
- package/dist/connectors/telegram/commands/questionSetAside.d.ts.map +1 -0
- package/dist/connectors/telegram/commands/questionSetAside.js +637 -0
- package/dist/connectors/telegram/commands/questionSetAside.js.map +1 -0
- package/dist/connectors/telegram/commands/questionWait.d.ts +21 -0
- package/dist/connectors/telegram/commands/questionWait.d.ts.map +1 -0
- package/dist/connectors/telegram/commands/questionWait.js +109 -0
- package/dist/connectors/telegram/commands/questionWait.js.map +1 -0
- package/dist/connectors/telegram/commands/runners.d.ts +28 -1
- package/dist/connectors/telegram/commands/runners.d.ts.map +1 -1
- package/dist/connectors/telegram/commands/runners.js +75 -40
- package/dist/connectors/telegram/commands/runners.js.map +1 -1
- package/dist/connectors/telegram/commands/topicAccess.js +1 -1
- package/dist/connectors/telegram/commands/topicAccess.js.map +1 -1
- package/dist/connectors/telegram/commands/topicCommand.d.ts +0 -2
- package/dist/connectors/telegram/commands/topicCommand.d.ts.map +1 -1
- package/dist/connectors/telegram/commands/topicCommand.js +4 -5
- package/dist/connectors/telegram/commands/topicCommand.js.map +1 -1
- package/dist/connectors/telegram/commands/topicStatus.d.ts +24 -0
- package/dist/connectors/telegram/commands/topicStatus.d.ts.map +1 -0
- package/dist/connectors/telegram/commands/topicStatus.js +148 -0
- package/dist/connectors/telegram/commands/topicStatus.js.map +1 -0
- package/dist/connectors/telegram/firstUpdateBatchNote.d.ts +30 -0
- package/dist/connectors/telegram/firstUpdateBatchNote.d.ts.map +1 -0
- package/dist/connectors/telegram/firstUpdateBatchNote.js +39 -0
- package/dist/connectors/telegram/firstUpdateBatchNote.js.map +1 -0
- package/dist/connectors/telegram/inbound.d.ts +12 -0
- package/dist/connectors/telegram/inbound.d.ts.map +1 -1
- package/dist/connectors/telegram/inbound.js +31 -3
- package/dist/connectors/telegram/inbound.js.map +1 -1
- package/dist/connectors/telegram/sendOutcome.d.ts +3 -1
- package/dist/connectors/telegram/sendOutcome.d.ts.map +1 -1
- package/dist/connectors/telegram/sendOutcome.js.map +1 -1
- package/dist/connectors/telegram/telegramFailureRetry.d.ts +8 -0
- package/dist/connectors/telegram/telegramFailureRetry.d.ts.map +1 -1
- package/dist/connectors/telegram/telegramFailureRetry.js +8 -0
- package/dist/connectors/telegram/telegramFailureRetry.js.map +1 -1
- package/dist/connectors/telegram/topicIndicator.d.ts +86 -0
- package/dist/connectors/telegram/topicIndicator.d.ts.map +1 -0
- package/dist/connectors/telegram/topicIndicator.js +490 -0
- package/dist/connectors/telegram/topicIndicator.js.map +1 -0
- package/dist/connectors/telegram/waitingTopicRenames.d.ts +39 -0
- package/dist/connectors/telegram/waitingTopicRenames.d.ts.map +1 -0
- package/dist/connectors/telegram/waitingTopicRenames.js +48 -0
- package/dist/connectors/telegram/waitingTopicRenames.js.map +1 -0
- package/dist/i18n/de.d.ts.map +1 -1
- package/dist/i18n/de.js +51 -0
- package/dist/i18n/de.js.map +1 -1
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +51 -0
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/es.d.ts.map +1 -1
- package/dist/i18n/es.js +51 -0
- package/dist/i18n/es.js.map +1 -1
- package/dist/i18n/fr.d.ts.map +1 -1
- package/dist/i18n/fr.js +51 -0
- package/dist/i18n/fr.js.map +1 -1
- package/dist/i18n/hi.d.ts.map +1 -1
- package/dist/i18n/hi.js +51 -0
- package/dist/i18n/hi.js.map +1 -1
- package/dist/i18n/ja.d.ts.map +1 -1
- package/dist/i18n/ja.js +51 -0
- package/dist/i18n/ja.js.map +1 -1
- package/dist/i18n/ka.d.ts.map +1 -1
- package/dist/i18n/ka.js +51 -0
- package/dist/i18n/ka.js.map +1 -1
- package/dist/i18n/pt.d.ts.map +1 -1
- package/dist/i18n/pt.js +51 -0
- package/dist/i18n/pt.js.map +1 -1
- package/dist/i18n/ru.d.ts.map +1 -1
- package/dist/i18n/ru.js +51 -0
- package/dist/i18n/ru.js.map +1 -1
- package/dist/i18n/uk.d.ts.map +1 -1
- package/dist/i18n/uk.js +51 -0
- package/dist/i18n/uk.js.map +1 -1
- package/dist/i18n/uz.d.ts.map +1 -1
- package/dist/i18n/uz.js +51 -0
- package/dist/i18n/uz.js.map +1 -1
- package/dist/i18n/zh.d.ts.map +1 -1
- package/dist/i18n/zh.js +51 -0
- package/dist/i18n/zh.js.map +1 -1
- package/dist/i18n.d.ts.map +1 -1
- package/dist/i18n.js +2 -1
- package/dist/i18n.js.map +1 -1
- package/dist/instanceSettings.d.ts +19 -1
- package/dist/instanceSettings.d.ts.map +1 -1
- package/dist/instanceSettings.js +35 -2
- package/dist/instanceSettings.js.map +1 -1
- package/dist/openCodeOpenQuestion.d.ts +12 -4
- package/dist/openCodeOpenQuestion.d.ts.map +1 -1
- package/dist/openCodeOpenQuestion.js +16 -7
- package/dist/openCodeOpenQuestion.js.map +1 -1
- package/dist/openCodeQuestionFlow.d.ts +10 -2
- package/dist/openCodeQuestionFlow.d.ts.map +1 -1
- package/dist/openCodeQuestionFlow.js +27 -5
- package/dist/openCodeQuestionFlow.js.map +1 -1
- package/dist/postToSession.d.ts +9 -0
- package/dist/postToSession.d.ts.map +1 -1
- package/dist/postToSession.js +15 -2
- package/dist/postToSession.js.map +1 -1
- package/dist/requests/requestHeader.d.ts.map +1 -1
- package/dist/requests/requestHeader.js +1 -0
- package/dist/requests/requestHeader.js.map +1 -1
- package/dist/requests/types.d.ts +4 -1
- package/dist/requests/types.d.ts.map +1 -1
- package/dist/requests/wakeUpEngine.d.ts +31 -1
- package/dist/requests/wakeUpEngine.d.ts.map +1 -1
- package/dist/requests/wakeUpEngine.js +94 -2
- package/dist/requests/wakeUpEngine.js.map +1 -1
- package/dist/requests/wakeUpRules.d.ts +7 -0
- package/dist/requests/wakeUpRules.d.ts.map +1 -1
- package/dist/requests/wakeUpRules.js +14 -0
- package/dist/requests/wakeUpRules.js.map +1 -1
- package/dist/scheduler/engine.d.ts +17 -4
- package/dist/scheduler/engine.d.ts.map +1 -1
- package/dist/scheduler/engine.js +55 -10
- package/dist/scheduler/engine.js.map +1 -1
- package/dist/scheduler/mcpBoot.d.ts +6 -2
- package/dist/scheduler/mcpBoot.d.ts.map +1 -1
- package/dist/scheduler/mcpBoot.js +7 -1
- package/dist/scheduler/mcpBoot.js.map +1 -1
- package/dist/scheduler/mcpSurface.d.ts.map +1 -1
- package/dist/scheduler/mcpSurface.js +18 -9
- package/dist/scheduler/mcpSurface.js.map +1 -1
- package/dist/sendErrorClassifier.d.ts +6 -0
- package/dist/sendErrorClassifier.d.ts.map +1 -1
- package/dist/sendErrorClassifier.js +9 -0
- package/dist/sendErrorClassifier.js.map +1 -1
- package/dist/startupPromptBuffer.d.ts +8 -8
- package/dist/startupPromptBuffer.d.ts.map +1 -1
- package/dist/startupPromptBuffer.js +7 -5
- package/dist/startupPromptBuffer.js.map +1 -1
- package/dist/state.d.ts +98 -6
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +149 -7
- package/dist/state.js.map +1 -1
- package/dist/testTimings.d.ts +12 -3
- package/dist/testTimings.d.ts.map +1 -1
- package/dist/testTimings.js +23 -2
- package/dist/testTimings.js.map +1 -1
- package/dist/threadRouting.d.ts +23 -0
- package/dist/threadRouting.d.ts.map +1 -1
- package/dist/threadRouting.js +28 -0
- package/dist/threadRouting.js.map +1 -1
- package/dist/todos/registry.d.ts +2 -0
- package/dist/todos/registry.d.ts.map +1 -1
- package/dist/todos/registry.js +3 -1
- package/dist/todos/registry.js.map +1 -1
- package/dist/trackers/taskAgentSlots.d.ts +42 -3
- package/dist/trackers/taskAgentSlots.d.ts.map +1 -1
- package/dist/trackers/taskAgentSlots.js +31 -11
- package/dist/trackers/taskAgentSlots.js.map +1 -1
- package/dist/types.d.ts +95 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/claudeCompactHook.d.ts +3 -1
- package/dist/utils/claudeCompactHook.d.ts.map +1 -1
- package/dist/utils/claudeCompactHook.js +3 -1
- package/dist/utils/claudeCompactHook.js.map +1 -1
- package/dist/utils/claudeLimitSwitch.d.ts +1 -1
- package/dist/utils/claudeLimitSwitch.d.ts.map +1 -1
- package/dist/utils/claudeLimitSwitch.js +1 -1
- package/dist/utils/claudeLimitSwitch.js.map +1 -1
- package/dist/utils/claudeProfileSync.d.ts +88 -0
- package/dist/utils/claudeProfileSync.d.ts.map +1 -0
- package/dist/utils/claudeProfileSync.js +198 -0
- package/dist/utils/claudeProfileSync.js.map +1 -0
- package/dist/utils/claudeProfiles.d.ts +101 -6
- package/dist/utils/claudeProfiles.d.ts.map +1 -1
- package/dist/utils/claudeProfiles.js +288 -23
- package/dist/utils/claudeProfiles.js.map +1 -1
- package/dist/utils/claudeUsageRefresher.d.ts +8 -1
- package/dist/utils/claudeUsageRefresher.d.ts.map +1 -1
- package/dist/utils/claudeUsageRefresher.js +11 -1
- package/dist/utils/claudeUsageRefresher.js.map +1 -1
- package/dist/utils/cutButtonLabel.d.ts +7 -0
- package/dist/utils/cutButtonLabel.d.ts.map +1 -0
- package/dist/utils/cutButtonLabel.js +17 -0
- package/dist/utils/cutButtonLabel.js.map +1 -0
- package/dist/utils/fileSendPlan.d.ts +30 -8
- package/dist/utils/fileSendPlan.d.ts.map +1 -1
- package/dist/utils/fileSendPlan.js +37 -12
- package/dist/utils/fileSendPlan.js.map +1 -1
- package/dist/utils/fileSendService.d.ts +1 -1
- package/dist/utils/fileSendService.d.ts.map +1 -1
- package/dist/utils/fileSendService.js +9 -1
- package/dist/utils/fileSendService.js.map +1 -1
- package/dist/utils/imageDimensions.d.ts +32 -0
- package/dist/utils/imageDimensions.d.ts.map +1 -0
- package/dist/utils/imageDimensions.js +181 -0
- package/dist/utils/imageDimensions.js.map +1 -0
- package/dist/utils/jsonStreamHost.d.ts +35 -9
- package/dist/utils/jsonStreamHost.d.ts.map +1 -1
- package/dist/utils/jsonStreamHost.js +59 -16
- package/dist/utils/jsonStreamHost.js.map +1 -1
- package/dist/utils/limitSwitchPlan.d.ts +44 -0
- package/dist/utils/limitSwitchPlan.d.ts.map +1 -0
- package/dist/utils/limitSwitchPlan.js +54 -0
- package/dist/utils/limitSwitchPlan.js.map +1 -0
- package/dist/utils/lostWork.d.ts +8 -2
- package/dist/utils/lostWork.d.ts.map +1 -1
- package/dist/utils/lostWork.js +9 -5
- package/dist/utils/lostWork.js.map +1 -1
- package/dist/utils/promptDelivery.d.ts +11 -2
- package/dist/utils/promptDelivery.d.ts.map +1 -1
- package/dist/utils/promptDelivery.js +3 -3
- package/dist/utils/promptDelivery.js.map +1 -1
- package/dist/utils/questionWaitChoices.d.ts +20 -0
- package/dist/utils/questionWaitChoices.d.ts.map +1 -0
- package/dist/utils/questionWaitChoices.js +31 -0
- package/dist/utils/questionWaitChoices.js.map +1 -0
- package/dist/utils/questionWaitPlan.d.ts +166 -0
- package/dist/utils/questionWaitPlan.d.ts.map +1 -0
- package/dist/utils/questionWaitPlan.js +237 -0
- package/dist/utils/questionWaitPlan.js.map +1 -0
- package/dist/utils/replyQuote.d.ts +10 -0
- package/dist/utils/replyQuote.d.ts.map +1 -1
- package/dist/utils/replyQuote.js +18 -7
- package/dist/utils/replyQuote.js.map +1 -1
- package/dist/utils/talkerAccess.d.ts +2 -2
- package/dist/utils/talkerAccess.d.ts.map +1 -1
- package/dist/utils/talkerAccess.js +5 -4
- package/dist/utils/talkerAccess.js.map +1 -1
- package/dist/utils/telegramError.d.ts +6 -0
- package/dist/utils/telegramError.d.ts.map +1 -1
- package/dist/utils/telegramError.js +12 -0
- package/dist/utils/telegramError.js.map +1 -1
- package/dist/utils/topicAccessScreenPlan.d.ts +1 -1
- package/dist/utils/topicAccessScreenPlan.d.ts.map +1 -1
- package/dist/utils/topicAccessScreenPlan.js +3 -7
- package/dist/utils/topicAccessScreenPlan.js.map +1 -1
- package/dist/utils/topicIndicatorPlan.d.ts +143 -0
- package/dist/utils/topicIndicatorPlan.d.ts.map +1 -0
- package/dist/utils/topicIndicatorPlan.js +202 -0
- package/dist/utils/topicIndicatorPlan.js.map +1 -0
- package/dist/utils/topicIndicatorSources.d.ts +40 -0
- package/dist/utils/topicIndicatorSources.d.ts.map +1 -0
- package/dist/utils/topicIndicatorSources.js +31 -0
- package/dist/utils/topicIndicatorSources.js.map +1 -0
- package/dist/utils/topicStatusPlan.d.ts +90 -0
- package/dist/utils/topicStatusPlan.d.ts.map +1 -0
- package/dist/utils/topicStatusPlan.js +160 -0
- package/dist/utils/topicStatusPlan.js.map +1 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -2
|
@@ -91,6 +91,15 @@ exports.claudeJsonStreamUsageLogPrefix = '[ClaudeJson] usage ';
|
|
|
91
91
|
/** How long to wait for the `initialize` control-response handshake before
|
|
92
92
|
* proceeding without the interactive control channel (questions unavailable). */
|
|
93
93
|
const initializeHandshakeTimeoutMs = 15000;
|
|
94
|
+
/** The first request id a prompt names (its header, or a reminder's): what a re-post with rebuilt text has in common. */
|
|
95
|
+
const promptRequestIdRe = /\breq_[A-Za-z0-9_-]+/;
|
|
96
|
+
/** The key of a prompt in the torn-prompt counts: its conversation and the request it names, else its text. */
|
|
97
|
+
function getTornPromptKey(session, text) {
|
|
98
|
+
const requestId = promptRequestIdRe.exec(text)?.[0];
|
|
99
|
+
return `${(0, sessionKey_1.keyToString)(session.key)}\u0000${requestId ?? (0, crypto_1.createHash)('sha256').update(text).digest('hex')}`;
|
|
100
|
+
}
|
|
101
|
+
/** How often a user turn held for a CLI that does not read yet looks again (`waitForReadingInput`). */
|
|
102
|
+
const readingInputPollMs = 100;
|
|
94
103
|
/** Whether an adopted session's live state is not rebuilt yet: held until the boot's release, or replaying its downtime tail. */
|
|
95
104
|
function checkIsSessionReplayPending(session) {
|
|
96
105
|
return session.isTailHeld || session.adoptCatchUpOffset !== null;
|
|
@@ -144,10 +153,16 @@ class ClaudeJsonStreamAdapter extends events_1.EventEmitter {
|
|
|
144
153
|
lifecycle;
|
|
145
154
|
/** How long the agent's own pending work holds the process after its last turn (`utils/jsonStreamPendingWork.ts`). */
|
|
146
155
|
pendingWorkHoldMs;
|
|
156
|
+
/**
|
|
157
|
+
* `writeFifo` replaces the stdin FIFO write (tests only: a reader that stalls or stops mid-frame cannot be made
|
|
158
|
+
* portably with a real pipe).
|
|
159
|
+
*/
|
|
147
160
|
constructor(options = { lifecycle: 'idle' }) {
|
|
148
161
|
super();
|
|
149
162
|
this.lifecycle = options.lifecycle;
|
|
150
163
|
this.pendingWorkHoldMs = options.backgroundHoldMs ?? jsonStreamPendingWork_1.pendingWorkHoldDefaultMs;
|
|
164
|
+
this.writeFifo = options.writeFifo ?? jsonStreamHost_1.writeFifoText;
|
|
165
|
+
this.stdinStallTimeoutMs = options.stdinStallTimeoutMs ?? jsonStreamHost_1.fifoWriteStallTimeoutMs;
|
|
151
166
|
this.name = options.lifecycle === 'perTurn' ? adapterNames_1.claudePerTurnAdapterName : adapterNames_1.claudeJsonStreamAdapterName;
|
|
152
167
|
this.label = options.lifecycle === 'perTurn' ? 'Claude Code (per-turn)' : 'Claude Code (stream)';
|
|
153
168
|
}
|
|
@@ -158,6 +173,14 @@ class ClaudeJsonStreamAdapter extends events_1.EventEmitter {
|
|
|
158
173
|
selfGreetsOnStart = false;
|
|
159
174
|
sessions = new Map();
|
|
160
175
|
claudePath = (0, resolveBinary_1.resolveClaudeBinary)();
|
|
176
|
+
writeFifo;
|
|
177
|
+
/** How long a user turn waits for a CLI that reads nothing, and a write for a reader that takes nothing (tests shorten it). */
|
|
178
|
+
stdinStallTimeoutMs;
|
|
179
|
+
/**
|
|
180
|
+
* How often each user prompt was left half-written, by conversation and the request it names (else its text): a second tear
|
|
181
|
+
* of the same request's prompt — a re-post may be rebuilt with other text — is logged loudly. Dropped once one of its writes lands.
|
|
182
|
+
*/
|
|
183
|
+
tornPromptCounts = new Map();
|
|
161
184
|
displayPrefsReader = null;
|
|
162
185
|
seenWatermarkWriter = null;
|
|
163
186
|
jsonStreamTailWriter = null;
|
|
@@ -349,7 +372,7 @@ class ClaudeJsonStreamAdapter extends events_1.EventEmitter {
|
|
|
349
372
|
const session = {
|
|
350
373
|
key, workDir, sessionId,
|
|
351
374
|
pid, paths, fifoFd,
|
|
352
|
-
stdinWriteChain: Promise.resolve(),
|
|
375
|
+
stdinWriteChain: Promise.resolve(), isStdinBroken: false, isReadingInput: false,
|
|
353
376
|
tail: (0, jsonStreamHost_1.createStdoutTailState)(0),
|
|
354
377
|
pollTimer: null, pollDelayMs: pollBackoff_1.basePollIntervalMs, unchangedStreak: 0,
|
|
355
378
|
isOversizeWarned: false, lastPersistedTailOffset: 0,
|
|
@@ -686,7 +709,7 @@ class ClaudeJsonStreamAdapter extends events_1.EventEmitter {
|
|
|
686
709
|
const session = {
|
|
687
710
|
key, workDir, sessionId: claudeSessionId,
|
|
688
711
|
pid, paths, fifoFd,
|
|
689
|
-
stdinWriteChain: Promise.resolve(),
|
|
712
|
+
stdinWriteChain: Promise.resolve(), isStdinBroken: false, isReadingInput: true,
|
|
690
713
|
tail: (0, jsonStreamHost_1.createStdoutTailState)(startOffset),
|
|
691
714
|
pollTimer: null, pollDelayMs: pollBackoff_1.basePollIntervalMs, unchangedStreak: 0,
|
|
692
715
|
isOversizeWarned: false, lastPersistedTailOffset: startOffset,
|
|
@@ -1164,11 +1187,23 @@ class ClaudeJsonStreamAdapter extends events_1.EventEmitter {
|
|
|
1164
1187
|
// Input (S3)
|
|
1165
1188
|
// ─────────────────────────────────────────────────────────────────────────
|
|
1166
1189
|
sendInput(key, input) {
|
|
1190
|
+
// A failed write is logged by the write itself; a caller that must know awaits `sendInputAndWait`.
|
|
1191
|
+
void this.sendInputAndWait(key, input).catch(() => { });
|
|
1192
|
+
}
|
|
1193
|
+
/**
|
|
1194
|
+
* @description {@link sendInput} that resolves once the user turn is written WHOLE into the CLI's stdin, and rejects
|
|
1195
|
+
* when it could not be (`EAGAIN` past the stall budget, a dead reader, a broken stream): the prompt never reached the
|
|
1196
|
+
* agent, and its caller is told so instead of believing it delivered. The state a turn start sets is set before the
|
|
1197
|
+
* first await, as `sendInput` always did; a write that failed takes back its unconsumed-input count, and the busy flag
|
|
1198
|
+
* when nothing of the CLI was seen since. A session that is not active drops the input, as before (logged).
|
|
1199
|
+
*/
|
|
1200
|
+
sendInputAndWait(key, input) {
|
|
1167
1201
|
const session = this.sessions.get((0, sessionKey_1.keyToString)(key));
|
|
1168
1202
|
if (!session?.isActive) {
|
|
1169
1203
|
console.warn(`[ClaudeJson] sendInput to inactive session ${(0, sessionKey_1.keyToString)(key)} dropped`);
|
|
1170
|
-
return;
|
|
1204
|
+
return Promise.resolve();
|
|
1171
1205
|
}
|
|
1206
|
+
const wasBusy = session.isBusy;
|
|
1172
1207
|
// A fresh user turn begins → reset the answer cursor so its first tail is a
|
|
1173
1208
|
// new message (the bot also flips `needsNewMessage` for delta adapters).
|
|
1174
1209
|
session.currentResponseText = '';
|
|
@@ -1178,11 +1213,18 @@ class ClaudeJsonStreamAdapter extends events_1.EventEmitter {
|
|
|
1178
1213
|
// A fresh turn resets the idle-watchdog clock: without this a session that
|
|
1179
1214
|
// sat idle for minutes (busy=false, clock stale) would trip the watchdog on
|
|
1180
1215
|
// its very next poll — before claude has a chance to emit the first token.
|
|
1181
|
-
|
|
1216
|
+
const turnStartedAt = Date.now();
|
|
1217
|
+
session.lastStdoutActivityAt = turnStartedAt;
|
|
1182
1218
|
// The turn in flight is persisted at once (same offset, flipped flag): a restart
|
|
1183
1219
|
// during a long, silent tool call finds no frame after the offset to rebuild it.
|
|
1184
1220
|
this.jsonStreamTailWriter?.(key, buildTailRecord(session, session.lastPersistedTailOffset));
|
|
1185
|
-
this.writeUserMessage(session, input)
|
|
1221
|
+
return this.writeUserMessage(session, input).catch((error) => {
|
|
1222
|
+
// Nothing of this turn reached the CLI: it is not owed an echo, and — unless the CLI showed life since — it is as busy as it was.
|
|
1223
|
+
session.unconsumedInputCount = Math.max(0, session.unconsumedInputCount - 1);
|
|
1224
|
+
if (session.lastStdoutActivityAt === turnStartedAt)
|
|
1225
|
+
session.isBusy = wasBusy;
|
|
1226
|
+
throw error;
|
|
1227
|
+
});
|
|
1186
1228
|
}
|
|
1187
1229
|
sendSignal(key, _signal) {
|
|
1188
1230
|
this.sendInterrupt(key);
|
|
@@ -1213,21 +1255,90 @@ class ClaudeJsonStreamAdapter extends events_1.EventEmitter {
|
|
|
1213
1255
|
// and any bare `/esc` mid-turn). Consumed by the next `handleTurnEnd`.
|
|
1214
1256
|
session.swallowNextAbortError = true;
|
|
1215
1257
|
}
|
|
1216
|
-
/** Write one user turn, counting it until Claude echoes it back (it has read it). */
|
|
1258
|
+
/** Write one user turn, counting it until Claude echoes it back (it has read it); settles as its write does. */
|
|
1217
1259
|
writeUserMessage(session, content) {
|
|
1218
1260
|
session.unconsumedInputCount += 1;
|
|
1219
|
-
this.writeStdin(session, { type: 'user', message: { role: 'user', content } });
|
|
1261
|
+
return this.writeStdin(session, { type: 'user', message: { role: 'user', content } }, { userText: content });
|
|
1220
1262
|
}
|
|
1221
|
-
/**
|
|
1222
|
-
*
|
|
1223
|
-
*
|
|
1224
|
-
|
|
1263
|
+
/**
|
|
1264
|
+
* Enqueue one stream-json frame onto the stdin FIFO. The per-session chain keeps wire order and waits out a full
|
|
1265
|
+
* buffer (see `writeFifoText`); the returned promise is THIS frame's write — it resolves once the frame is written
|
|
1266
|
+
* whole and rejects when it is not (logged here, so a caller may leave it: the chain's own handler keeps it from being
|
|
1267
|
+
* an unhandled rejection). A frame left half-written breaks the stream: see {@link StreamSession.isStdinBroken}.
|
|
1268
|
+
*/
|
|
1269
|
+
writeStdin(session, obj, options = {}) {
|
|
1225
1270
|
const line = JSON.stringify(obj) + '\n';
|
|
1226
|
-
session.
|
|
1227
|
-
|
|
1228
|
-
|
|
1271
|
+
const checkIsAbandoned = () => session.isStopping || !session.isActive;
|
|
1272
|
+
const write = session.stdinWriteChain.then(async () => {
|
|
1273
|
+
if (session.isStdinBroken)
|
|
1274
|
+
throw new Error('the stdin stream is broken: a frame before this one was left half-written');
|
|
1275
|
+
// A user turn waits for a CLI that reads: written into a FIFO nobody drains, a big prompt is left half-written.
|
|
1276
|
+
if (options.userText !== undefined)
|
|
1277
|
+
await this.waitForReadingInput(session, checkIsAbandoned);
|
|
1278
|
+
return this.writeFifo(session.fifoFd, line, { checkIsAbandoned, stallTimeoutMs: this.stdinStallTimeoutMs });
|
|
1279
|
+
});
|
|
1280
|
+
if (options.userText !== undefined) {
|
|
1281
|
+
const promptKey = getTornPromptKey(session, options.userText);
|
|
1282
|
+
void write.then(() => this.tornPromptCounts.delete(promptKey), () => { });
|
|
1283
|
+
}
|
|
1284
|
+
session.stdinWriteChain = write.catch((e) => {
|
|
1285
|
+
console.error(`[ClaudeJson] stdin write failed for ${(0, sessionKey_1.keyToString)(session.key)}:`, e instanceof Error ? e.message : e);
|
|
1286
|
+
if (e instanceof jsonStreamHost_1.FifoWriteError && e.isTorn && !session.isStopping && session.isActive) {
|
|
1287
|
+
if (options.userText !== undefined)
|
|
1288
|
+
this.noteTornPrompt(session, options.userText);
|
|
1289
|
+
this.breakStdin(session);
|
|
1290
|
+
}
|
|
1291
|
+
});
|
|
1229
1292
|
// New input → output expected shortly; snap the tail poll back to base.
|
|
1230
1293
|
this.snapPollToBase(session);
|
|
1294
|
+
return write;
|
|
1295
|
+
}
|
|
1296
|
+
/**
|
|
1297
|
+
* Hold a user turn until the CLI shows it reads its stdin ({@link StreamSession.isReadingInput}). After the stall budget
|
|
1298
|
+
* the turn is written anyway — a CLI that never answers the handshake must still get its prompts — and the write then
|
|
1299
|
+
* has the budget of its own; a stop under way ends the wait (nothing was written).
|
|
1300
|
+
*/
|
|
1301
|
+
async waitForReadingInput(session, checkIsAbandoned) {
|
|
1302
|
+
const startedAt = Date.now();
|
|
1303
|
+
while (!session.isReadingInput) {
|
|
1304
|
+
if (checkIsAbandoned())
|
|
1305
|
+
throw new jsonStreamHost_1.FifoWriteError('the write was abandoned: the process is being stopped', 0, 1);
|
|
1306
|
+
if (Date.now() - startedAt >= this.stdinStallTimeoutMs) {
|
|
1307
|
+
console.warn(`[ClaudeJson] ${(0, sessionKey_1.keyToString)(session.key)}: the CLI showed no sign of reading its input for ${Math.round(this.stdinStallTimeoutMs / 1000)} s (no handshake answer, no output); the prompt is written anyway`);
|
|
1308
|
+
return;
|
|
1309
|
+
}
|
|
1310
|
+
await new Promise((resolve) => setTimeout(resolve, readingInputPollMs));
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
/**
|
|
1314
|
+
* A user prompt was left half-written. Counted per conversation and text: the same prompt torn again means the CLI
|
|
1315
|
+
* keeps stopping mid-prompt on every retry — said loudly, while the prompt stays pending with its request's retries.
|
|
1316
|
+
*/
|
|
1317
|
+
noteTornPrompt(session, text) {
|
|
1318
|
+
const promptKey = getTornPromptKey(session, text);
|
|
1319
|
+
const count = (this.tornPromptCounts.get(promptKey) ?? 0) + 1;
|
|
1320
|
+
this.tornPromptCounts.set(promptKey, count);
|
|
1321
|
+
if (count >= 2) {
|
|
1322
|
+
console.error(`[ClaudeJson] ${(0, sessionKey_1.keyToString)(session.key)}: the SAME prompt (${text.length} chars) was left half-written ${count} times: its CLI stops reading its input in the middle of it. It stays pending — its request keeps its retries — but it will not get through until that is fixed`);
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
/**
|
|
1326
|
+
* A frame was left half-written: nothing more is written into the stream, and the process is suspended — the
|
|
1327
|
+
* conversation keeps its id and its next trigger resumes it in a fresh process, with a stdin of its own. A suspend that
|
|
1328
|
+
* fails must not leave a live process nobody can write to: it is killed, and the tail poll's exit check ends the session.
|
|
1329
|
+
*/
|
|
1330
|
+
breakStdin(session) {
|
|
1331
|
+
session.isStdinBroken = true;
|
|
1332
|
+
console.error(`[ClaudeJson] ${(0, sessionKey_1.keyToString)(session.key)}: a stdin frame was left half-written; nothing more is written to this process, it is suspended and its next prompt resumes the conversation`);
|
|
1333
|
+
void this.suspendSession(session.key).catch((e) => {
|
|
1334
|
+
console.warn(`[ClaudeJson] suspending ${(0, sessionKey_1.keyToString)(session.key)} after its broken stdin failed (${e instanceof Error ? e.message : String(e)}); killing its process`);
|
|
1335
|
+
try {
|
|
1336
|
+
process.kill(session.pid, 'SIGKILL');
|
|
1337
|
+
}
|
|
1338
|
+
catch {
|
|
1339
|
+
// Gone already: the tail poll's exit check finds that too.
|
|
1340
|
+
}
|
|
1341
|
+
});
|
|
1231
1342
|
}
|
|
1232
1343
|
// ─────────────────────────────────────────────────────────────────────────
|
|
1233
1344
|
// Output parsing (S2) + control channel (S4)
|
|
@@ -1251,6 +1362,8 @@ class ClaudeJsonStreamAdapter extends events_1.EventEmitter {
|
|
|
1251
1362
|
const msg = (0, claudeStreamJson_1.parseStreamJsonLine)(line);
|
|
1252
1363
|
if (!msg)
|
|
1253
1364
|
continue;
|
|
1365
|
+
// Any output: the CLI is up, and a user turn held for it may be written.
|
|
1366
|
+
session.isReadingInput = true;
|
|
1254
1367
|
for (const action of (0, claudeStreamJson_1.classifyClaudeStreamMessage)(msg)) {
|
|
1255
1368
|
this.applyAction(session, action);
|
|
1256
1369
|
}
|
|
@@ -1278,6 +1391,7 @@ class ClaudeJsonStreamAdapter extends events_1.EventEmitter {
|
|
|
1278
1391
|
*/
|
|
1279
1392
|
handleControlResponse(session, action) {
|
|
1280
1393
|
if (session.pendingInitResolve && action.requestId === session.initRequestId) {
|
|
1394
|
+
session.isReadingInput = true;
|
|
1281
1395
|
session.pendingInitResolve();
|
|
1282
1396
|
return;
|
|
1283
1397
|
}
|
|
@@ -1948,11 +2062,11 @@ class ClaudeJsonStreamAdapter extends events_1.EventEmitter {
|
|
|
1948
2062
|
}
|
|
1949
2063
|
answerQuestion(key, answers) {
|
|
1950
2064
|
const session = this.sessions.get((0, sessionKey_1.keyToString)(key));
|
|
1951
|
-
if (!session?.isActive
|
|
2065
|
+
if (!session?.isActive)
|
|
2066
|
+
return;
|
|
2067
|
+
const pending = this.takePendingQuestion(session);
|
|
2068
|
+
if (!pending)
|
|
1952
2069
|
return;
|
|
1953
|
-
const pending = session.pendingQuestion;
|
|
1954
|
-
session.pendingQuestion = null;
|
|
1955
|
-
this.clearQuestionSidecar(session);
|
|
1956
2070
|
// The turn resumes now; reset the idle-watchdog clock so the (possibly long)
|
|
1957
2071
|
// wait for the user's answer doesn't instantly trip it before output resumes.
|
|
1958
2072
|
session.lastStdoutActivityAt = Date.now();
|
|
@@ -1967,12 +2081,42 @@ class ClaudeJsonStreamAdapter extends events_1.EventEmitter {
|
|
|
1967
2081
|
}
|
|
1968
2082
|
rejectQuestion(key) {
|
|
1969
2083
|
const session = this.sessions.get((0, sessionKey_1.keyToString)(key));
|
|
1970
|
-
|
|
2084
|
+
const pending = session ? this.takePendingQuestion(session) : null;
|
|
2085
|
+
if (!session || !pending)
|
|
1971
2086
|
return;
|
|
2087
|
+
this.writeControlResponse(session, pending.requestId, (0, claudeStreamJson_1.buildCanUseToolDeny)('User declined to answer the question.', pending.toolUseId));
|
|
2088
|
+
}
|
|
2089
|
+
/**
|
|
2090
|
+
* @description Set the question `requestId` aside: DENY its `can_use_tool` with `text` as the message. The CLI hands the model
|
|
2091
|
+
* a denied tool call's message as the tool's result and the turn goes on — no interrupt, unlike {@link rejectQuestion}'s
|
|
2092
|
+
* abandonment (the Agent SDK: «When denying, provide a message explaining why. Claude sees this message and may adjust its
|
|
2093
|
+
* approach»). The answers already given travel in `text` itself, so `givenAnswers` is not read here. Does nothing, and says
|
|
2094
|
+
* so (`false`), unless `requestId` is the question pending now.
|
|
2095
|
+
*/
|
|
2096
|
+
setQuestionAside(key, requestId, text) {
|
|
2097
|
+
const session = this.sessions.get((0, sessionKey_1.keyToString)(key));
|
|
2098
|
+
if (!session?.isActive || session.pendingQuestion?.requestId !== requestId)
|
|
2099
|
+
return false;
|
|
2100
|
+
const pending = this.takePendingQuestion(session);
|
|
2101
|
+
if (!pending)
|
|
2102
|
+
return false;
|
|
2103
|
+
// The turn resumes now, as after an answer: restart the idle-watchdog clock the wait for the person had run down.
|
|
2104
|
+
session.lastStdoutActivityAt = Date.now();
|
|
2105
|
+
this.writeControlResponse(session, pending.requestId, (0, claudeStreamJson_1.buildCanUseToolDeny)(text, pending.toolUseId));
|
|
2106
|
+
return true;
|
|
2107
|
+
}
|
|
2108
|
+
/**
|
|
2109
|
+
* Take the pending question out of the session — its sidecar goes too, so a restart cannot resurface it — and hand it to the
|
|
2110
|
+
* caller, who answers, denies or sets aside its `can_use_tool` request. `null` when none is pending (already resolved: a
|
|
2111
|
+
* second resolution is a no-op, never a second control_response).
|
|
2112
|
+
*/
|
|
2113
|
+
takePendingQuestion(session) {
|
|
1972
2114
|
const pending = session.pendingQuestion;
|
|
2115
|
+
if (!pending)
|
|
2116
|
+
return null;
|
|
1973
2117
|
session.pendingQuestion = null;
|
|
1974
2118
|
this.clearQuestionSidecar(session);
|
|
1975
|
-
|
|
2119
|
+
return pending;
|
|
1976
2120
|
}
|
|
1977
2121
|
writeControlResponse(session, requestId, response) {
|
|
1978
2122
|
this.writeStdin(session, { type: 'control_response', response: { subtype: 'success', request_id: requestId, response } });
|