@scotthuang/agent-knock-knock 0.13.2 → 0.13.4
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 +36 -0
- package/README.md +27 -6
- package/dist/src/callback-outbox-policy.js +27 -6
- package/dist/src/callback-outbox-policy.js.map +1 -1
- package/dist/src/callback-outbox-service.d.ts +4 -30
- package/dist/src/callback-outbox-service.js +21 -154
- package/dist/src/callback-outbox-service.js.map +1 -1
- package/dist/src/callback-outbox-settlement.js +13 -8
- package/dist/src/callback-outbox-settlement.js.map +1 -1
- package/dist/src/callback-route-service.d.ts +46 -0
- package/dist/src/callback-route-service.js +155 -0
- package/dist/src/callback-route-service.js.map +1 -0
- package/dist/src/claude-terminal-agent-adapter.js +4 -0
- package/dist/src/claude-terminal-agent-adapter.js.map +1 -1
- package/dist/src/cli-core.js +9 -1
- package/dist/src/cli-core.js.map +1 -1
- package/dist/src/codex-process-incarnation.d.ts +8 -0
- package/dist/src/codex-process-incarnation.js +36 -0
- package/dist/src/codex-process-incarnation.js.map +1 -0
- package/dist/src/codex-terminal-agent-adapter.js +4 -0
- package/dist/src/codex-terminal-agent-adapter.js.map +1 -1
- package/dist/src/deferred-foreground-conflict-policy.d.ts +22 -0
- package/dist/src/deferred-foreground-conflict-policy.js +52 -0
- package/dist/src/deferred-foreground-conflict-policy.js.map +1 -0
- package/dist/src/durable-notification-kernel.d.ts +94 -0
- package/dist/src/durable-notification-kernel.js +68 -0
- package/dist/src/durable-notification-kernel.js.map +1 -0
- package/dist/src/herdr-socket-transport.d.ts +43 -0
- package/dist/src/herdr-socket-transport.js +170 -0
- package/dist/src/herdr-socket-transport.js.map +1 -0
- package/dist/src/herdr-terminal-control-provider.d.ts +2 -45
- package/dist/src/herdr-terminal-control-provider.js +8 -173
- package/dist/src/herdr-terminal-control-provider.js.map +1 -1
- package/dist/src/host-adapter-capabilities.d.ts +35 -0
- package/dist/src/host-adapter-capabilities.js +146 -0
- package/dist/src/host-adapter-capabilities.js.map +1 -0
- package/dist/src/host-adapter.d.ts +9 -3
- package/dist/src/host-adapter.js +33 -9
- package/dist/src/host-adapter.js.map +1 -1
- package/dist/src/host-bridge-tools.d.ts +3 -4
- package/dist/src/host-bridge-tools.js +49 -92
- package/dist/src/host-bridge-tools.js.map +1 -1
- package/dist/src/host-bridge.js +5 -5
- package/dist/src/host-bridge.js.map +1 -1
- package/dist/src/host-monitor-reconciliation.d.ts +6 -0
- package/dist/src/host-monitor-reconciliation.js +96 -0
- package/dist/src/host-monitor-reconciliation.js.map +1 -0
- package/dist/src/managed-session.js +2 -18
- package/dist/src/managed-session.js.map +1 -1
- package/dist/src/native-thread-lifecycle-cli-adapter.d.ts +13 -0
- package/dist/src/native-thread-lifecycle-cli-adapter.js +635 -3
- package/dist/src/native-thread-lifecycle-cli-adapter.js.map +1 -1
- package/dist/src/openclaw-list-projection.d.ts +2 -0
- package/dist/src/openclaw-list-projection.js +3 -0
- package/dist/src/openclaw-list-projection.js.map +1 -0
- package/dist/src/openclaw-model-facing-field-policy.d.ts +2 -0
- package/dist/src/openclaw-model-facing-field-policy.js +3 -0
- package/dist/src/openclaw-model-facing-field-policy.js.map +1 -0
- package/dist/src/openclaw-plugin-command-adapter.d.ts +6 -29
- package/dist/src/openclaw-plugin-command-adapter.js +7 -2370
- package/dist/src/openclaw-plugin-command-adapter.js.map +1 -1
- package/dist/src/openclaw-plugin-helpers.d.ts +2 -121
- package/dist/src/openclaw-plugin-helpers.js +2 -1164
- package/dist/src/openclaw-plugin-helpers.js.map +1 -1
- package/dist/src/openclaw-plugin-schemas.d.ts +2 -510
- package/dist/src/openclaw-plugin-schemas.js +2 -519
- package/dist/src/openclaw-plugin-schemas.js.map +1 -1
- package/dist/src/openclaw-plugin-supervisor.d.ts +4 -5
- package/dist/src/openclaw-plugin-supervisor.js +5 -94
- package/dist/src/openclaw-plugin-supervisor.js.map +1 -1
- package/dist/src/openclaw-plugin-value-helpers.d.ts +2 -0
- package/dist/src/openclaw-plugin-value-helpers.js +3 -0
- package/dist/src/openclaw-plugin-value-helpers.js.map +1 -0
- package/dist/src/openclaw-private-authority-offers.d.ts +4 -39
- package/dist/src/openclaw-private-authority-offers.js +3 -258
- package/dist/src/openclaw-private-authority-offers.js.map +1 -1
- package/dist/src/semantic-private-authority-offers.d.ts +41 -0
- package/dist/src/semantic-private-authority-offers.js +261 -0
- package/dist/src/semantic-private-authority-offers.js.map +1 -0
- package/dist/src/semantic-tool-arguments.d.ts +9 -0
- package/dist/src/semantic-tool-arguments.js +64 -0
- package/dist/src/semantic-tool-arguments.js.map +1 -0
- package/dist/src/semantic-tool-catalog.d.ts +48 -0
- package/dist/src/semantic-tool-catalog.js +105 -0
- package/dist/src/semantic-tool-catalog.js.map +1 -0
- package/dist/src/semantic-tool-command-helpers.d.ts +145 -0
- package/dist/src/semantic-tool-command-helpers.js +1272 -0
- package/dist/src/semantic-tool-command-helpers.js.map +1 -0
- package/dist/src/semantic-tool-list-projection.d.ts +10 -0
- package/dist/src/semantic-tool-list-projection.js +497 -0
- package/dist/src/semantic-tool-list-projection.js.map +1 -0
- package/dist/src/semantic-tool-model-facing-field-policy.d.ts +3 -0
- package/dist/src/semantic-tool-model-facing-field-policy.js +66 -0
- package/dist/src/semantic-tool-model-facing-field-policy.js.map +1 -0
- package/dist/src/semantic-tool-presentation.d.ts +37 -0
- package/dist/src/semantic-tool-presentation.js +680 -0
- package/dist/src/semantic-tool-presentation.js.map +1 -0
- package/dist/src/semantic-tool-private-authority.d.ts +39 -0
- package/dist/src/semantic-tool-private-authority.js +602 -0
- package/dist/src/semantic-tool-private-authority.js.map +1 -0
- package/dist/src/semantic-tool-relay.d.ts +16 -0
- package/dist/src/semantic-tool-relay.js +175 -0
- package/dist/src/semantic-tool-relay.js.map +1 -0
- package/dist/src/semantic-tool-runtime.d.ts +10 -0
- package/dist/src/semantic-tool-runtime.js +1157 -0
- package/dist/src/semantic-tool-runtime.js.map +1 -0
- package/dist/src/semantic-tool-schemas.d.ts +563 -0
- package/dist/src/semantic-tool-schemas.js +573 -0
- package/dist/src/semantic-tool-schemas.js.map +1 -0
- package/dist/src/semantic-tool-value-helpers.d.ts +5 -0
- package/dist/src/semantic-tool-value-helpers.js +27 -0
- package/dist/src/semantic-tool-value-helpers.js.map +1 -0
- package/dist/src/store-event-presentation.d.ts +17 -0
- package/dist/src/store-event-presentation.js +33 -0
- package/dist/src/store-event-presentation.js.map +1 -0
- package/dist/src/store.d.ts +3 -16
- package/dist/src/store.js +2 -30
- package/dist/src/store.js.map +1 -1
- package/dist/src/terminal-action-projection.d.ts +3 -17
- package/dist/src/terminal-action-projection.js +13 -41
- package/dist/src/terminal-action-projection.js.map +1 -1
- package/dist/src/terminal-agent-adapter.d.ts +7 -0
- package/dist/src/terminal-agent-adapter.js +8 -0
- package/dist/src/terminal-agent-adapter.js.map +1 -1
- package/dist/src/terminal-agent-bridge.d.ts +35 -332
- package/dist/src/terminal-agent-bridge.js +293 -2798
- package/dist/src/terminal-agent-bridge.js.map +1 -1
- package/dist/src/terminal-approval-cli-adapter.d.ts +17 -0
- package/dist/src/terminal-approval-cli-adapter.js +921 -0
- package/dist/src/terminal-approval-cli-adapter.js.map +1 -0
- package/dist/src/terminal-command-cli-adapter.d.ts +2 -429
- package/dist/src/terminal-command-cli-adapter.js +344 -6061
- package/dist/src/terminal-command-cli-adapter.js.map +1 -1
- package/dist/src/terminal-command-cli-ports.d.ts +443 -0
- package/dist/src/terminal-command-cli-ports.js +2 -0
- package/dist/src/terminal-command-cli-ports.js.map +1 -0
- package/dist/src/terminal-command-dispatch-preparation.d.ts +81 -0
- package/dist/src/terminal-command-dispatch-preparation.js +209 -0
- package/dist/src/terminal-command-dispatch-preparation.js.map +1 -0
- package/dist/src/terminal-command-dispatch-transport.d.ts +35 -0
- package/dist/src/terminal-command-dispatch-transport.js +859 -0
- package/dist/src/terminal-command-dispatch-transport.js.map +1 -0
- package/dist/src/terminal-command-foreground-proof.d.ts +32 -0
- package/dist/src/terminal-command-foreground-proof.js +72 -0
- package/dist/src/terminal-command-foreground-proof.js.map +1 -0
- package/dist/src/terminal-command-send-preflight.d.ts +41 -0
- package/dist/src/terminal-command-send-preflight.js +86 -0
- package/dist/src/terminal-command-send-preflight.js.map +1 -0
- package/dist/src/terminal-composer-classifier.d.ts +55 -0
- package/dist/src/terminal-composer-classifier.js +638 -0
- package/dist/src/terminal-composer-classifier.js.map +1 -0
- package/dist/src/terminal-control-ref.d.ts +23 -0
- package/dist/src/terminal-control-ref.js +32 -0
- package/dist/src/terminal-control-ref.js.map +1 -1
- package/dist/src/terminal-dispatch-recovery-authority.d.ts +56 -0
- package/dist/src/terminal-dispatch-recovery-authority.js +251 -0
- package/dist/src/terminal-dispatch-recovery-authority.js.map +1 -0
- package/dist/src/terminal-dispatch-recovery-cli-adapter.d.ts +1 -9
- package/dist/src/terminal-dispatch-recovery-cli-adapter.js +5 -240
- package/dist/src/terminal-dispatch-recovery-cli-adapter.js.map +1 -1
- package/dist/src/terminal-handoff-cli-adapter.d.ts +1 -11
- package/dist/src/terminal-handoff-cli-adapter.js +2 -39
- package/dist/src/terminal-handoff-cli-adapter.js.map +1 -1
- package/dist/src/terminal-human-explicit-send-cli-adapter.d.ts +25 -0
- package/dist/src/terminal-human-explicit-send-cli-adapter.js +903 -0
- package/dist/src/terminal-human-explicit-send-cli-adapter.js.map +1 -0
- package/dist/src/terminal-identity-authority-cli-adapter.d.ts +1 -6
- package/dist/src/terminal-identity-authority-cli-adapter.js +3 -33
- package/dist/src/terminal-identity-authority-cli-adapter.js.map +1 -1
- package/dist/src/terminal-interaction-cli-adapter.js +209 -210
- package/dist/src/terminal-interaction-cli-adapter.js.map +1 -1
- package/dist/src/terminal-interaction-core.d.ts +0 -2
- package/dist/src/terminal-interaction-core.js +4 -3
- package/dist/src/terminal-interaction-core.js.map +1 -1
- package/dist/src/terminal-interaction-protocol.d.ts +21 -0
- package/dist/src/terminal-interaction-protocol.js +74 -0
- package/dist/src/terminal-interaction-protocol.js.map +1 -1
- package/dist/src/terminal-interaction-response-bridge.d.ts +126 -0
- package/dist/src/terminal-interaction-response-bridge.js +579 -0
- package/dist/src/terminal-interaction-response-bridge.js.map +1 -0
- package/dist/src/terminal-interaction-response-transaction.d.ts +44 -0
- package/dist/src/terminal-interaction-response-transaction.js +56 -0
- package/dist/src/terminal-interaction-response-transaction.js.map +1 -0
- package/dist/src/terminal-list-action-policy.d.ts +43 -0
- package/dist/src/terminal-list-action-policy.js +164 -0
- package/dist/src/terminal-list-action-policy.js.map +1 -0
- package/dist/src/terminal-list-cli-adapter.d.ts +6 -36
- package/dist/src/terminal-list-cli-adapter.js +314 -1711
- package/dist/src/terminal-list-cli-adapter.js.map +1 -1
- package/dist/src/terminal-list-facts.d.ts +129 -0
- package/dist/src/terminal-list-facts.js +179 -0
- package/dist/src/terminal-list-facts.js.map +1 -0
- package/dist/src/terminal-list-inventory.d.ts +59 -0
- package/dist/src/terminal-list-inventory.js +194 -0
- package/dist/src/terminal-list-inventory.js.map +1 -0
- package/dist/src/terminal-list-ownership-service.d.ts +118 -0
- package/dist/src/terminal-list-ownership-service.js +1003 -0
- package/dist/src/terminal-list-ownership-service.js.map +1 -0
- package/dist/src/terminal-list-projection-service.d.ts +49 -0
- package/dist/src/terminal-list-projection-service.js +407 -0
- package/dist/src/terminal-list-projection-service.js.map +1 -0
- package/dist/src/terminal-list-renderer.d.ts +12 -11
- package/dist/src/terminal-list-renderer.js +237 -104
- package/dist/src/terminal-list-renderer.js.map +1 -1
- package/dist/src/terminal-managed-send-cli-adapter.d.ts +33 -0
- package/dist/src/terminal-managed-send-cli-adapter.js +994 -0
- package/dist/src/terminal-managed-send-cli-adapter.js.map +1 -0
- package/dist/src/terminal-managed-turn-list-action-policy.d.ts +47 -0
- package/dist/src/terminal-managed-turn-list-action-policy.js +64 -0
- package/dist/src/terminal-managed-turn-list-action-policy.js.map +1 -0
- package/dist/src/terminal-model-control-action-policy.d.ts +60 -0
- package/dist/src/terminal-model-control-action-policy.js +96 -0
- package/dist/src/terminal-model-control-action-policy.js.map +1 -0
- package/dist/src/terminal-model-control-availability.d.ts +68 -0
- package/dist/src/terminal-model-control-availability.js +157 -0
- package/dist/src/terminal-model-control-availability.js.map +1 -0
- package/dist/src/terminal-model-control-bridge.d.ts +48 -0
- package/dist/src/terminal-model-control-bridge.js +259 -0
- package/dist/src/terminal-model-control-bridge.js.map +1 -0
- package/dist/src/terminal-model-control-profile.d.ts +55 -0
- package/dist/src/terminal-model-control-profile.js +137 -0
- package/dist/src/terminal-model-control-profile.js.map +1 -0
- package/dist/src/terminal-model-control-subject.d.ts +34 -0
- package/dist/src/terminal-model-control-subject.js +58 -0
- package/dist/src/terminal-model-control-subject.js.map +1 -0
- package/dist/src/terminal-model-control-transaction.d.ts +19 -0
- package/dist/src/terminal-model-control-transaction.js +39 -0
- package/dist/src/terminal-model-control-transaction.js.map +1 -0
- package/dist/src/terminal-model-control.d.ts +331 -0
- package/dist/src/terminal-model-control.js +1686 -0
- package/dist/src/terminal-model-control.js.map +1 -0
- package/dist/src/terminal-monitor-application-service.js +50 -17
- package/dist/src/terminal-monitor-application-service.js.map +1 -1
- package/dist/src/terminal-native-inspection-bridge.d.ts +211 -0
- package/dist/src/terminal-native-inspection-bridge.js +1127 -0
- package/dist/src/terminal-native-inspection-bridge.js.map +1 -0
- package/dist/src/terminal-runtime-cli-adapter.d.ts +2 -0
- package/dist/src/terminal-runtime-cli-adapter.js +59 -17
- package/dist/src/terminal-runtime-cli-adapter.js.map +1 -1
- package/dist/src/terminal-submission-retry-application.d.ts +24 -0
- package/dist/src/terminal-submission-retry-application.js +402 -0
- package/dist/src/terminal-submission-retry-application.js.map +1 -0
- package/dist/src/terminal-submission-retry-ports.d.ts +30 -0
- package/dist/src/terminal-submission-retry-ports.js +2 -0
- package/dist/src/terminal-submission-retry-ports.js.map +1 -0
- package/dist/src/terminal-submission-retry-reconciliation.d.ts +236 -0
- package/dist/src/terminal-submission-retry-reconciliation.js +1130 -0
- package/dist/src/terminal-submission-retry-reconciliation.js.map +1 -0
- package/dist/src/terminal-submission-retry-transport.d.ts +58 -0
- package/dist/src/terminal-submission-retry-transport.js +675 -0
- package/dist/src/terminal-submission-retry-transport.js.map +1 -0
- package/dist/src/terminal-text-submission-bridge.d.ts +200 -0
- package/dist/src/terminal-text-submission-bridge.js +632 -0
- package/dist/src/terminal-text-submission-bridge.js.map +1 -0
- package/dist/src/terminal-user-explicit-send-policy.d.ts +29 -0
- package/dist/src/terminal-user-explicit-send-policy.js +46 -0
- package/dist/src/terminal-user-explicit-send-policy.js.map +1 -0
- package/dist/src/terminal-watch-cli-adapter.js +91 -143
- package/dist/src/terminal-watch-cli-adapter.js.map +1 -1
- package/dist/src/terminal-watch-codec.d.ts +9 -0
- package/dist/src/terminal-watch-codec.js +1051 -0
- package/dist/src/terminal-watch-codec.js.map +1 -0
- package/dist/src/terminal-watch-interaction-response-store.d.ts +19 -0
- package/dist/src/terminal-watch-interaction-response-store.js +87 -0
- package/dist/src/terminal-watch-interaction-response-store.js.map +1 -0
- package/dist/src/terminal-watch-record.d.ts +319 -0
- package/dist/src/terminal-watch-record.js +742 -0
- package/dist/src/terminal-watch-record.js.map +1 -0
- package/dist/src/terminal-watch-service.js +48 -27
- package/dist/src/terminal-watch-service.js.map +1 -1
- package/dist/src/terminal-watch-store.d.ts +3 -279
- package/dist/src/terminal-watch-store.js +5 -1779
- package/dist/src/terminal-watch-store.js.map +1 -1
- package/docs/quickstart-herdr.md +1 -1
- package/docs/quickstart-tmux.md +27 -2
- package/openclaw.plugin.json +13 -1
- package/package.json +7 -2
- package/templates/openclaw-skills/agent-knock-knock/SKILL.md +54 -11
|
@@ -0,0 +1,680 @@
|
|
|
1
|
+
import { executorDefinitionForKind } from "./executors.js";
|
|
2
|
+
import { isRecord, nonBlankString as stringValue } from "./value-guards.js";
|
|
3
|
+
import { formatAkkTerminalWatchHint, formatAkkWatchStatusCommandResult, isAkkModelFacingDiagnosticField, isAkkModelFacingPrivateAuthorityField, isAkkNativeSubmissionAccepted, normalizeAkkModelFacingFieldName, sanitizeAkkModelFacingDiagnosticText, sanitizeAkkModelFacingLegacyAuthorityInstructionText } from "./semantic-tool-command-helpers.js";
|
|
4
|
+
import { validateAnyTerminalInteractionProjection } from "./terminal-interaction-protocol.js";
|
|
5
|
+
import { terminalSendEnterDispatched } from "./terminal-dispatch-presenter.js";
|
|
6
|
+
const hostBridgePresentationApis = new WeakSet();
|
|
7
|
+
/** Select compact Host-neutral callback presentation for one runtime owner. */
|
|
8
|
+
export function bindHostBridgeToolPresentation(api) {
|
|
9
|
+
hostBridgePresentationApis.add(api);
|
|
10
|
+
}
|
|
11
|
+
/** Read presentation mode without exposing the owner-local binding set. */
|
|
12
|
+
export function usesHostBridgeToolPresentation(api) {
|
|
13
|
+
return hostBridgePresentationApis.has(api);
|
|
14
|
+
}
|
|
15
|
+
export function sendCommandResultIsError(result) {
|
|
16
|
+
return isSuccessfulTerminalDispatch(result)
|
|
17
|
+
? false
|
|
18
|
+
: terminalSubmissionReported(result)
|
|
19
|
+
? !isAkkNativeSubmissionAccepted(result)
|
|
20
|
+
: result.status === "delivered_unfenced";
|
|
21
|
+
}
|
|
22
|
+
function isSuccessfulTerminalDispatch(result) {
|
|
23
|
+
return isRecord(result) && terminalSendEnterDispatched(result);
|
|
24
|
+
}
|
|
25
|
+
export function formatDelegateCommandResult(result) {
|
|
26
|
+
const agent = executorDisplayName(result.agent);
|
|
27
|
+
const { sessionId, turnId } = publicTurnIdentity(result);
|
|
28
|
+
if (result.status === "submission_unfenced") {
|
|
29
|
+
return [
|
|
30
|
+
`AKK sent the terminal input to ${agent}, but could not bind later side effects to an exact native session.`,
|
|
31
|
+
`session: ${sessionId}`,
|
|
32
|
+
`turn: ${turnId}`,
|
|
33
|
+
"next: do not retry or continue automatically; inspect the named pane and close this Turn before sending more work."
|
|
34
|
+
].join("\n");
|
|
35
|
+
}
|
|
36
|
+
if (result.status === "submission_uncertain") {
|
|
37
|
+
return [
|
|
38
|
+
`AKK could not prove whether ${agent} received the terminal task.`,
|
|
39
|
+
`session: ${sessionId}`,
|
|
40
|
+
`turn: ${turnId}`,
|
|
41
|
+
"next: do not retry automatically; inspect AKK status and the named terminal pane."
|
|
42
|
+
].join("\n");
|
|
43
|
+
}
|
|
44
|
+
if (result.status === "submission_aborted") {
|
|
45
|
+
const safeToRetry = result.safe_to_retry === true && result.do_not_retry !== true;
|
|
46
|
+
return [
|
|
47
|
+
`AKK stopped before sending the terminal task to ${agent}.`,
|
|
48
|
+
`session: ${sessionId}`,
|
|
49
|
+
`turn: ${turnId}`,
|
|
50
|
+
safeToRetry
|
|
51
|
+
? "next: no terminal input was sent and the aborted receipt is durable, so this request may be retried."
|
|
52
|
+
: "next: do not retry automatically; AKK could not prove a durable safe abort, so inspect this Turn and its terminal dispatch ledger."
|
|
53
|
+
].join("\n");
|
|
54
|
+
}
|
|
55
|
+
if (result.status === "submission_pending_acceptance") {
|
|
56
|
+
return [
|
|
57
|
+
`AKK dispatched terminal input to ${agent}, but native acceptance is still pending.`,
|
|
58
|
+
`session: ${sessionId}`,
|
|
59
|
+
`turn: ${turnId}`,
|
|
60
|
+
"next: do not retry or report success; wait for acceptance or inspect the shared terminal pane."
|
|
61
|
+
].join("\n");
|
|
62
|
+
}
|
|
63
|
+
if (result.status === "submission_not_accepted") {
|
|
64
|
+
return [
|
|
65
|
+
`AKK proved that ${agent} did not accept the terminal draft.`,
|
|
66
|
+
`session: ${sessionId}`,
|
|
67
|
+
`turn: ${turnId}`,
|
|
68
|
+
"next: do not retry automatically; inspect the exact draft in the shared terminal pane."
|
|
69
|
+
].join("\n");
|
|
70
|
+
}
|
|
71
|
+
return [
|
|
72
|
+
`AKK sent the task to ${agent} in the shared terminal.`,
|
|
73
|
+
`session: ${sessionId}`,
|
|
74
|
+
`turn: ${turnId}`,
|
|
75
|
+
`status: ${result.conversation_status ?? result.status ?? "unknown"}`,
|
|
76
|
+
"The result will return to this controller session through the callback."
|
|
77
|
+
].join("\n");
|
|
78
|
+
}
|
|
79
|
+
function executorDisplayName(kind) {
|
|
80
|
+
try {
|
|
81
|
+
return executorDefinitionForKind(String(kind ?? "codex")).displayName;
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return String(kind ?? "agent");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
export function formatStatusCommandResult(result) {
|
|
88
|
+
if (stringValue(result.watch_id) ||
|
|
89
|
+
(isRecord(result.watch) && stringValue(result.watch.watch_id)) ||
|
|
90
|
+
(isRecord(result.terminal_watch) &&
|
|
91
|
+
stringValue(result.terminal_watch.watch_id))) {
|
|
92
|
+
return formatAkkWatchStatusCommandResult(result);
|
|
93
|
+
}
|
|
94
|
+
const summary = result.summary ?? result.conversation ?? result ?? {};
|
|
95
|
+
const terminalStatus = isRecord(result.terminal_status) ? result.terminal_status : {};
|
|
96
|
+
const rawCallbackDelivery = isRecord(result.conversation?.callback_delivery)
|
|
97
|
+
? result.conversation.callback_delivery
|
|
98
|
+
: undefined;
|
|
99
|
+
const summarizedCallbackDelivery = isRecord(summary.callback_delivery)
|
|
100
|
+
? summary.callback_delivery
|
|
101
|
+
: undefined;
|
|
102
|
+
const callbackDelivery = rawCallbackDelivery || summarizedCallbackDelivery
|
|
103
|
+
? {
|
|
104
|
+
...(rawCallbackDelivery ?? {}),
|
|
105
|
+
...(summarizedCallbackDelivery ?? {})
|
|
106
|
+
}
|
|
107
|
+
: undefined;
|
|
108
|
+
const { sessionId, turnId } = publicTurnIdentity(result);
|
|
109
|
+
const lines = [
|
|
110
|
+
"AKK status:",
|
|
111
|
+
`session: ${sessionId}`,
|
|
112
|
+
`turn: ${turnId}`,
|
|
113
|
+
`agent: ${summary.agent ?? summary.executor?.kind ?? terminalStatus.agent ?? "unknown"}`,
|
|
114
|
+
`turn status: ${summary.status ?? result.conversation_status ?? result.status ?? "not managed"}`,
|
|
115
|
+
`terminal activity: ${terminalStatus.activity_state ?? "unavailable"}`,
|
|
116
|
+
...formatAkkTerminalWatchHint(result)
|
|
117
|
+
];
|
|
118
|
+
if (callbackDelivery) {
|
|
119
|
+
const callbackParts = [
|
|
120
|
+
String(callbackDelivery.status ?? "unknown"),
|
|
121
|
+
Number.isSafeInteger(Number(callbackDelivery.attempts))
|
|
122
|
+
? `attempt ${Number(callbackDelivery.attempts)}`
|
|
123
|
+
: undefined,
|
|
124
|
+
callbackDelivery.attempt_state === "in_flight"
|
|
125
|
+
? "in flight"
|
|
126
|
+
: undefined,
|
|
127
|
+
stringValue(callbackDelivery.next_attempt_at)
|
|
128
|
+
? `next retry ${stringValue(callbackDelivery.next_attempt_at)}`
|
|
129
|
+
: undefined
|
|
130
|
+
].filter(Boolean);
|
|
131
|
+
lines.push(`callback: ${callbackParts.join(", ")}`);
|
|
132
|
+
}
|
|
133
|
+
if (summary.request) {
|
|
134
|
+
lines.push(`request: ${truncateText(summary.request, 180)}`);
|
|
135
|
+
}
|
|
136
|
+
if (result.about) {
|
|
137
|
+
lines.push(`about: ${truncateText(result.about, 500)}`);
|
|
138
|
+
}
|
|
139
|
+
if (result.confidence) {
|
|
140
|
+
lines.push(`confidence: ${result.confidence}`);
|
|
141
|
+
}
|
|
142
|
+
const limitations = Array.isArray(result.limitations)
|
|
143
|
+
? result.limitations.filter(Boolean)
|
|
144
|
+
: [];
|
|
145
|
+
if (limitations.length > 0) {
|
|
146
|
+
lines.push(`limitations: ${limitations.slice(0, 3).join("; ")}`);
|
|
147
|
+
}
|
|
148
|
+
const screen = terminalScreenExcerpt(result);
|
|
149
|
+
if (screen) {
|
|
150
|
+
lines.push(`terminal screen:\n${screen}`);
|
|
151
|
+
}
|
|
152
|
+
return lines.join("\n");
|
|
153
|
+
}
|
|
154
|
+
export function formatDoctorCommandResult(result) {
|
|
155
|
+
const capabilities = isRecord(result.capabilities) ? result.capabilities : {};
|
|
156
|
+
const tmux = isRecord(capabilities.tmux) ? capabilities.tmux : {};
|
|
157
|
+
const herdr = isRecord(capabilities.herdr) ? capabilities.herdr : {};
|
|
158
|
+
const dependencyChecks = Array.isArray(result.checks)
|
|
159
|
+
? result.checks.filter(isRecord)
|
|
160
|
+
: [];
|
|
161
|
+
const codingAgentLines = [
|
|
162
|
+
["Codex", "codex"],
|
|
163
|
+
["Claude Code", "claude"]
|
|
164
|
+
].map(([label, command]) => {
|
|
165
|
+
const check = dependencyChecks.find((entry) => entry.command === command);
|
|
166
|
+
const version = typeof check?.version === "string"
|
|
167
|
+
? check.version
|
|
168
|
+
: "unavailable";
|
|
169
|
+
const nativeProfile = check?.native_profile_supported === true &&
|
|
170
|
+
typeof check.native_profile === "string"
|
|
171
|
+
? `native profile ${check.native_profile}`
|
|
172
|
+
: check?.native_actions_available === true
|
|
173
|
+
? "native lifecycle/status available with compatibility warning"
|
|
174
|
+
: check?.available === true
|
|
175
|
+
? "native lifecycle/status unavailable: unrecognized version format"
|
|
176
|
+
: "unavailable";
|
|
177
|
+
return `${label}: ${version} (${nativeProfile})`;
|
|
178
|
+
});
|
|
179
|
+
const openclaw = isRecord(result.openclaw) ? result.openclaw : {};
|
|
180
|
+
const checks = Array.isArray(openclaw.checks) ? openclaw.checks : [];
|
|
181
|
+
const failures = checks
|
|
182
|
+
.filter((check) => isRecord(check) && check.ok !== true)
|
|
183
|
+
.map((check) => String(check.name ?? "unknown"));
|
|
184
|
+
const remediation = [...new Set(checks.flatMap((check) => isRecord(check) && Array.isArray(check.remediation)
|
|
185
|
+
? check.remediation.filter((command) => typeof command === "string" && command.trim().length > 0)
|
|
186
|
+
: []))].slice(0, 3);
|
|
187
|
+
return [
|
|
188
|
+
`AKK doctor: ${result.ok === true ? "ready" : "needs attention"}`,
|
|
189
|
+
`tmux: ${tmux.status ?? "unknown"}`,
|
|
190
|
+
`Herdr: ${herdr.status ?? "unknown"}`,
|
|
191
|
+
...codingAgentLines,
|
|
192
|
+
`OpenClaw package: ${openclaw.package_ready === true ? "ready" : "not ready"}`,
|
|
193
|
+
`Gateway: ${openclaw.gateway_ready === true ? "healthy" : "unavailable"}`,
|
|
194
|
+
...(failures.length > 0 ? [`check: ${failures.join(", ")}`] : []),
|
|
195
|
+
...remediation.map((command) => `next: ${command}`)
|
|
196
|
+
].join("\n");
|
|
197
|
+
}
|
|
198
|
+
export function formatRenewCommandResult(result) {
|
|
199
|
+
const { sessionId, turnId } = publicTurnIdentity(result);
|
|
200
|
+
return [
|
|
201
|
+
"AKK monitoring renewed.",
|
|
202
|
+
`session: ${sessionId}`,
|
|
203
|
+
`turn: ${turnId}`,
|
|
204
|
+
`inactivity timeout: ${result.agent_timeout_minutes ?? "unknown"} minutes`,
|
|
205
|
+
`hard lifetime: ${result.agent_hard_timeout_minutes ?? "unknown"} minutes`,
|
|
206
|
+
"No message or key was sent to the coding agent."
|
|
207
|
+
].join("\n");
|
|
208
|
+
}
|
|
209
|
+
export function formatRetryCallbackCommandResult(result) {
|
|
210
|
+
const { sessionId, turnId } = publicTurnIdentity(result);
|
|
211
|
+
return [
|
|
212
|
+
"AKK callback delivered.",
|
|
213
|
+
`session: ${sessionId}`,
|
|
214
|
+
`turn: ${turnId}`,
|
|
215
|
+
`status: ${result.conversation?.status ?? "unknown"}`,
|
|
216
|
+
`attempts: ${result.conversation?.callback_delivery?.attempts ?? "unknown"}`
|
|
217
|
+
].join("\n");
|
|
218
|
+
}
|
|
219
|
+
function formatUnconfirmedTerminalUserExplicitSendResult(result) {
|
|
220
|
+
const terminalInputDispatched = result.terminal_input_dispatched === true;
|
|
221
|
+
const enterDispatched = terminalSendEnterDispatched(result);
|
|
222
|
+
if (!enterDispatched) {
|
|
223
|
+
return [
|
|
224
|
+
terminalInputDispatched
|
|
225
|
+
? "AKK started this terminal Send, but could not prove that Enter was dispatched."
|
|
226
|
+
: "AKK stopped this terminal Send before any terminal input was proven.",
|
|
227
|
+
`terminal: ${result.terminal_id ?? "unknown"}`,
|
|
228
|
+
`message: ${result.message_id ?? "unknown"}`,
|
|
229
|
+
terminalInputDispatched
|
|
230
|
+
? "delivery: text input may be present; do not resend this message id."
|
|
231
|
+
: "delivery: no terminal input proven.",
|
|
232
|
+
"next: inspect AKK status and the terminal before deciding whether to continue."
|
|
233
|
+
].join("\n");
|
|
234
|
+
}
|
|
235
|
+
return [
|
|
236
|
+
"AKK already dispatched this managed terminal Send; native acceptance is still pending.",
|
|
237
|
+
`terminal: ${result.terminal_id ?? "unknown"}`,
|
|
238
|
+
`message: ${result.message_id ?? "unknown"}`,
|
|
239
|
+
"delivery: Enter dispatched; do not resend this message id.",
|
|
240
|
+
"next: inspect AKK status or the terminal; wait for the existing managed Turn."
|
|
241
|
+
].join("\n");
|
|
242
|
+
}
|
|
243
|
+
function formatTerminalUserExplicitSendResult(result) {
|
|
244
|
+
if (!terminalSendEnterDispatched(result)) {
|
|
245
|
+
return formatUnconfirmedTerminalUserExplicitSendResult(result);
|
|
246
|
+
}
|
|
247
|
+
const unmanaged = result.delivered_unmanaged === true;
|
|
248
|
+
const replayed = result.replayed === true;
|
|
249
|
+
const watchCallback = unmanaged &&
|
|
250
|
+
result.callback_expected === true &&
|
|
251
|
+
result.callback_mode === "terminal_watch" &&
|
|
252
|
+
typeof result.watch_id === "string"
|
|
253
|
+
? result.watch_id
|
|
254
|
+
: undefined;
|
|
255
|
+
return [
|
|
256
|
+
unmanaged
|
|
257
|
+
? replayed
|
|
258
|
+
? "AKK confirmed this direct terminal Send was already delivered."
|
|
259
|
+
: "AKK delivered the user's request directly to the coding agent."
|
|
260
|
+
: replayed
|
|
261
|
+
? "AKK confirmed this managed terminal Send was already delivered."
|
|
262
|
+
: "AKK delivered the user's terminal Send through managed routing.",
|
|
263
|
+
`terminal: ${result.terminal_id ?? "unknown"}`,
|
|
264
|
+
`message: ${result.message_id ?? "unknown"}`,
|
|
265
|
+
`delivery: ${unmanaged ? "unmanaged fallback" : "managed"}`,
|
|
266
|
+
...(unmanaged
|
|
267
|
+
? [watchCallback
|
|
268
|
+
? `callback: Terminal Watch ${watchCallback}; no managed AKK Turn was created.`
|
|
269
|
+
: "callback: unavailable; no managed AKK Turn was created."]
|
|
270
|
+
: []),
|
|
271
|
+
unmanaged
|
|
272
|
+
? watchCallback
|
|
273
|
+
? "next: wait for the Terminal Watch callback; watch-status is the recovery path."
|
|
274
|
+
: "next: refresh AKK list and use Watch to observe the still-running coding-agent task."
|
|
275
|
+
: "next: refresh AKK list; do not resend this message id."
|
|
276
|
+
].join("\n");
|
|
277
|
+
}
|
|
278
|
+
function formatManagedSendCommandResult(result) {
|
|
279
|
+
const conversation = result.conversation ?? {};
|
|
280
|
+
const conversationId = conversation.conversation_id ?? result.conversation_id ?? "unknown";
|
|
281
|
+
const sessionId = conversation.session_id ?? result.session_id ?? conversationId;
|
|
282
|
+
const turnId = conversation.turn_id ?? result.turn_id ?? conversationId;
|
|
283
|
+
const status = conversation.status ?? result.status ?? "unknown";
|
|
284
|
+
const nextAction = isRecord(result.openclaw_next_action) ? result.openclaw_next_action : undefined;
|
|
285
|
+
if (result.status === "delivered_unfenced") {
|
|
286
|
+
return [
|
|
287
|
+
"AKK sent the terminal input but could not bind an exact native session.",
|
|
288
|
+
`session: ${sessionId}`,
|
|
289
|
+
`turn: ${turnId}`,
|
|
290
|
+
`status: ${status}`,
|
|
291
|
+
"next: do not retry or continue automatically; inspect the shared terminal pane and close this Turn before sending more work."
|
|
292
|
+
].join("\n");
|
|
293
|
+
}
|
|
294
|
+
if (result.submission_outcome === "uncertain") {
|
|
295
|
+
return [
|
|
296
|
+
"AKK terminal submission outcome is uncertain.",
|
|
297
|
+
`session: ${sessionId}`,
|
|
298
|
+
`turn: ${turnId}`,
|
|
299
|
+
`status: ${result.status ?? status}`,
|
|
300
|
+
"next: do not retry automatically; inspect AKK status and the named terminal pane."
|
|
301
|
+
].join("\n");
|
|
302
|
+
}
|
|
303
|
+
if (result.submission_outcome === "aborted") {
|
|
304
|
+
const safeToRetry = result.safe_to_retry === true && result.do_not_retry !== true;
|
|
305
|
+
return [
|
|
306
|
+
"AKK terminal submission was aborted before terminal input.",
|
|
307
|
+
`session: ${sessionId}`,
|
|
308
|
+
`turn: ${turnId}`,
|
|
309
|
+
`status: ${result.status ?? status}`,
|
|
310
|
+
safeToRetry
|
|
311
|
+
? "next: this request was not sent, the aborted receipt is durable, and it may be retried."
|
|
312
|
+
: "next: do not retry automatically; inspect the Turn because a durable safe abort was not proven."
|
|
313
|
+
].join("\n");
|
|
314
|
+
}
|
|
315
|
+
if (result.submission_outcome === "pending_acceptance") {
|
|
316
|
+
return [
|
|
317
|
+
"AKK dispatched the terminal input but native acceptance is still pending.",
|
|
318
|
+
`session: ${sessionId}`,
|
|
319
|
+
`turn: ${turnId}`,
|
|
320
|
+
`status: ${result.status ?? status}`,
|
|
321
|
+
"next: do not retry or report success; wait for acceptance or inspect the shared terminal pane."
|
|
322
|
+
].join("\n");
|
|
323
|
+
}
|
|
324
|
+
if (result.submission_outcome === "not_accepted") {
|
|
325
|
+
return [
|
|
326
|
+
"AKK proved that the agent did not accept the terminal draft.",
|
|
327
|
+
`session: ${sessionId}`,
|
|
328
|
+
`turn: ${turnId}`,
|
|
329
|
+
`status: ${result.status ?? status}`,
|
|
330
|
+
"next: do not retry automatically; inspect the exact draft in the shared terminal pane."
|
|
331
|
+
].join("\n");
|
|
332
|
+
}
|
|
333
|
+
if (terminalSubmissionReported(result) &&
|
|
334
|
+
!isAkkNativeSubmissionAccepted(result)) {
|
|
335
|
+
return [
|
|
336
|
+
"AKK could not verify native agent acceptance for this terminal input.",
|
|
337
|
+
`session: ${sessionId}`,
|
|
338
|
+
`turn: ${turnId}`,
|
|
339
|
+
`status: ${result.status ?? status}`,
|
|
340
|
+
"next: do not retry or report success; inspect the exact Turn receipt and shared terminal pane."
|
|
341
|
+
].join("\n");
|
|
342
|
+
}
|
|
343
|
+
const lines = [
|
|
344
|
+
"AKK turn sent.",
|
|
345
|
+
`session: ${sessionId}`,
|
|
346
|
+
`turn: ${turnId}`,
|
|
347
|
+
`status: ${status}`
|
|
348
|
+
];
|
|
349
|
+
if (result.source) {
|
|
350
|
+
lines.push(`source: ${result.source}`);
|
|
351
|
+
}
|
|
352
|
+
return [
|
|
353
|
+
...lines,
|
|
354
|
+
nextAction?.action === "yield"
|
|
355
|
+
? "next: yield now and wait for the AKK callback or an explicit status request."
|
|
356
|
+
: `launched: ${result.launched === true ? "yes" : "no"}`
|
|
357
|
+
].join("\n");
|
|
358
|
+
}
|
|
359
|
+
export function formatSendCommandResult(result) {
|
|
360
|
+
return result.scope === "terminal_user_explicit"
|
|
361
|
+
? formatTerminalUserExplicitSendResult(result)
|
|
362
|
+
: formatManagedSendCommandResult(result);
|
|
363
|
+
}
|
|
364
|
+
export function formatCancelCommandResult(result) {
|
|
365
|
+
const conversation = result.conversation ?? {};
|
|
366
|
+
const { sessionId, turnId } = publicTurnIdentity(result);
|
|
367
|
+
return [
|
|
368
|
+
"AKK cancel requested.",
|
|
369
|
+
`session: ${sessionId}`,
|
|
370
|
+
`turn: ${turnId}`,
|
|
371
|
+
`agent: ${result.executor?.kind ?? conversation.executor?.kind ?? "unknown"}`,
|
|
372
|
+
`status: ${conversation.status ?? (result.cancel_requested === true ? "cancel requested" : "not cancelled")}`
|
|
373
|
+
].join("\n");
|
|
374
|
+
}
|
|
375
|
+
export function formatApproveCommandResult(result) {
|
|
376
|
+
const conversation = result.conversation ?? {};
|
|
377
|
+
const { sessionId, turnId } = publicTurnIdentity(result);
|
|
378
|
+
return [
|
|
379
|
+
result.approved === true
|
|
380
|
+
? "AKK approved the current terminal request."
|
|
381
|
+
: "AKK did not approve the terminal request.",
|
|
382
|
+
`session: ${sessionId}`,
|
|
383
|
+
`turn: ${turnId}`,
|
|
384
|
+
`status: ${conversation.status ?? "unknown"}`,
|
|
385
|
+
...(result.reason
|
|
386
|
+
? [`reason: ${sanitizeAkkModelFacingDiagnosticText(String(result.reason))}`]
|
|
387
|
+
: [])
|
|
388
|
+
].join("\n");
|
|
389
|
+
}
|
|
390
|
+
export function formatCloseCommandResult(result) {
|
|
391
|
+
if (result.source === "terminal_control") {
|
|
392
|
+
const terminalControl = isRecord(result.terminal_control)
|
|
393
|
+
? result.terminal_control
|
|
394
|
+
: {};
|
|
395
|
+
if (result.terminal_dispatch_resolved !== true) {
|
|
396
|
+
return [
|
|
397
|
+
"AKK did not clear the unresolved terminal dispatch fence.",
|
|
398
|
+
`terminal: ${terminalControl.target ?? "unknown"}`,
|
|
399
|
+
...(stringValue(result.transition_id)
|
|
400
|
+
? [`transition: ${stringValue(result.transition_id)}`]
|
|
401
|
+
: []),
|
|
402
|
+
`reason: ${sanitizeAkkModelFacingDiagnosticText(stringValue(result.reason) ??
|
|
403
|
+
"the recorded lifecycle outcome could not be verified")}`,
|
|
404
|
+
"This terminal remains blocked. Do not retry or continue automatically; inspect the pane and use the fresh recovery action from /akk list."
|
|
405
|
+
].join("\n");
|
|
406
|
+
}
|
|
407
|
+
return [
|
|
408
|
+
"AKK cleared the unresolved terminal dispatch fence.",
|
|
409
|
+
`terminal: ${terminalControl.target ?? "unknown"}`,
|
|
410
|
+
...(stringValue(result.transition_id)
|
|
411
|
+
? [`transition: ${stringValue(result.transition_id)}`]
|
|
412
|
+
: [
|
|
413
|
+
`previous turn: ${result.owner_turn_id ?? result.owner_conversation_id ?? "unknown"}`
|
|
414
|
+
]),
|
|
415
|
+
"The coding agent and terminal pane remain open."
|
|
416
|
+
].join("\n");
|
|
417
|
+
}
|
|
418
|
+
const conversation = result.conversation ?? {};
|
|
419
|
+
const { sessionId, turnId } = publicTurnIdentity(result);
|
|
420
|
+
return [
|
|
421
|
+
"AKK Turn record closed.",
|
|
422
|
+
`session: ${sessionId}`,
|
|
423
|
+
`turn: ${turnId}`,
|
|
424
|
+
`status: ${conversation.status ?? "unknown"}`,
|
|
425
|
+
"AKK management was released; the coding agent and terminal pane were not stopped.",
|
|
426
|
+
...(Array.isArray(result.warnings) && result.warnings.length > 0
|
|
427
|
+
? [`cleanup warnings: ${result.warnings.map((warning) => sanitizeAkkModelFacingDiagnosticText(String(warning))).join("; ")}`]
|
|
428
|
+
: []),
|
|
429
|
+
"Refresh the AKK list; if the coding agent is still working, Watch can attach to it again."
|
|
430
|
+
].join("\n");
|
|
431
|
+
}
|
|
432
|
+
export function publicTurnIdentity(result) {
|
|
433
|
+
const conversation = isRecord(result.conversation) ? result.conversation : {};
|
|
434
|
+
const summary = isRecord(result.summary) ? result.summary : {};
|
|
435
|
+
const compatibilityId = stringValue(conversation.conversation_id) ??
|
|
436
|
+
stringValue(summary.conversation_id) ??
|
|
437
|
+
stringValue(result.conversation_id);
|
|
438
|
+
return {
|
|
439
|
+
sessionId: stringValue(conversation.session_id) ??
|
|
440
|
+
stringValue(summary.session_id) ??
|
|
441
|
+
stringValue(result.session_id) ??
|
|
442
|
+
compatibilityId ??
|
|
443
|
+
"unknown",
|
|
444
|
+
turnId: stringValue(conversation.turn_id) ??
|
|
445
|
+
stringValue(summary.turn_id) ??
|
|
446
|
+
stringValue(result.turn_id) ??
|
|
447
|
+
compatibilityId ??
|
|
448
|
+
"unknown"
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
function terminalScreenExcerpt(result) {
|
|
452
|
+
const screen = result.terminal_screen;
|
|
453
|
+
const text = typeof screen === "string"
|
|
454
|
+
? screen
|
|
455
|
+
: isRecord(screen)
|
|
456
|
+
? stringValue(screen.excerpt) ??
|
|
457
|
+
stringValue(screen.text) ??
|
|
458
|
+
stringValue(screen.content)
|
|
459
|
+
: undefined;
|
|
460
|
+
if (!text) {
|
|
461
|
+
return undefined;
|
|
462
|
+
}
|
|
463
|
+
return text.length <= 1600
|
|
464
|
+
? text
|
|
465
|
+
: `…${text.slice(-1599)}`;
|
|
466
|
+
}
|
|
467
|
+
export function toolResult(result, { submissionErrors = false, normalizeTurnIdentity = true, forceError = false, modelProjection = undefined, compactText = false } = {}) {
|
|
468
|
+
const normalized = normalizeTurnIdentity ? withTurnIdentity(result) : result;
|
|
469
|
+
const sanitized = sanitizeModelFacingValue(normalized);
|
|
470
|
+
const modelFacing = modelProjection
|
|
471
|
+
? modelProjection(sanitized)
|
|
472
|
+
: sanitized;
|
|
473
|
+
const submissionError = submissionErrors && isSubmissionError(normalized);
|
|
474
|
+
return {
|
|
475
|
+
content: [
|
|
476
|
+
{
|
|
477
|
+
type: "text",
|
|
478
|
+
text: compactText
|
|
479
|
+
? JSON.stringify(modelFacing)
|
|
480
|
+
: JSON.stringify(modelFacing, null, 2)
|
|
481
|
+
}
|
|
482
|
+
],
|
|
483
|
+
details: modelFacing,
|
|
484
|
+
...(submissionError || forceError ? { isError: true } : {})
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
function sanitizeModelFacingValue(value, parentKey, path = []) {
|
|
488
|
+
if (Array.isArray(value)) {
|
|
489
|
+
if (parentKey === "missing_required") {
|
|
490
|
+
return value.filter((item) => typeof item !== "string" ||
|
|
491
|
+
!isAkkModelFacingPrivateAuthorityField(item));
|
|
492
|
+
}
|
|
493
|
+
return value.map((item, index) => sanitizeModelFacingValue(item, parentKey, [...path, String(index)]));
|
|
494
|
+
}
|
|
495
|
+
if (!isRecord(value)) {
|
|
496
|
+
if (typeof value !== "string") {
|
|
497
|
+
return value;
|
|
498
|
+
}
|
|
499
|
+
if (isAkkModelFacingDiagnosticField(parentKey)) {
|
|
500
|
+
return sanitizeAkkModelFacingDiagnosticText(value);
|
|
501
|
+
}
|
|
502
|
+
return isLegacyAuthorityInstructionPath(path)
|
|
503
|
+
? sanitizeAkkModelFacingLegacyAuthorityInstructionText(value)
|
|
504
|
+
: value;
|
|
505
|
+
}
|
|
506
|
+
const output = {};
|
|
507
|
+
for (const [key, item] of Object.entries(value)) {
|
|
508
|
+
if (isAkkModelFacingPrivateAuthorityField(key) ||
|
|
509
|
+
key === "_user_explicit_composer_ready" ||
|
|
510
|
+
key === "composer_draft" ||
|
|
511
|
+
key === "selection_snapshot" ||
|
|
512
|
+
key === "live_native_thread_id" ||
|
|
513
|
+
(key === "fingerprint" && parentKey === "approval_state")) {
|
|
514
|
+
continue;
|
|
515
|
+
}
|
|
516
|
+
if (key === "interaction_state") {
|
|
517
|
+
try {
|
|
518
|
+
output[key] = sanitizeModelFacingValue(validateAnyTerminalInteractionProjection(item), undefined, [...path, key]);
|
|
519
|
+
}
|
|
520
|
+
catch {
|
|
521
|
+
continue;
|
|
522
|
+
}
|
|
523
|
+
continue;
|
|
524
|
+
}
|
|
525
|
+
output[key] = sanitizeModelFacingValue(item, key, [...path, key]);
|
|
526
|
+
}
|
|
527
|
+
if (output.tool === "agent_knock_knock_send" && isRecord(output.arguments)) {
|
|
528
|
+
const selector = stringValue(output.arguments.selector);
|
|
529
|
+
if (selector && /^terminal:v[0-9]+:\S+$/u.test(selector)) {
|
|
530
|
+
const { selector: _selector, ...argumentsValue } = output.arguments;
|
|
531
|
+
output.arguments = { ...argumentsValue, terminal_id: selector };
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
if (output.tool === "agent_knock_knock_approve" && isRecord(output.arguments)) {
|
|
535
|
+
const conversationId = stringValue(output.arguments.conversation_id);
|
|
536
|
+
if (conversationId && /^terminal:v[0-9]+:\S+$/u.test(conversationId)) {
|
|
537
|
+
const { conversation_id: _conversationId, ...argumentsValue } = output.arguments;
|
|
538
|
+
output.arguments = { ...argumentsValue, terminal_id: conversationId };
|
|
539
|
+
}
|
|
540
|
+
const approvalArguments = isRecord(output.arguments)
|
|
541
|
+
? output.arguments
|
|
542
|
+
: {};
|
|
543
|
+
const terminalId = stringValue(approvalArguments.terminal_id);
|
|
544
|
+
output.before_call = {
|
|
545
|
+
tool: "agent_knock_knock_status",
|
|
546
|
+
arguments: terminalId
|
|
547
|
+
? { conversation_id: terminalId }
|
|
548
|
+
: { ...approvalArguments },
|
|
549
|
+
use: "Show the current approval request to the user. After explicit confirmation, call approve with only this semantic target; AKK revalidates the prompt privately."
|
|
550
|
+
};
|
|
551
|
+
delete output.missing_required;
|
|
552
|
+
}
|
|
553
|
+
if (output.tool === "agent_knock_knock_set_model" &&
|
|
554
|
+
isRecord(output.arguments)) {
|
|
555
|
+
const terminalId = stringValue(output.arguments.terminal_id ?? output.arguments.terminal);
|
|
556
|
+
output.arguments = terminalId && /^terminal:v[0-9]+:\S+$/u.test(terminalId)
|
|
557
|
+
? { terminal_id: terminalId }
|
|
558
|
+
: {};
|
|
559
|
+
if (Array.isArray(output.missing_required)) {
|
|
560
|
+
output.missing_required = output.missing_required.filter((field) => field === "model" || field === "reasoning_effort");
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
return output;
|
|
564
|
+
}
|
|
565
|
+
function isLegacyAuthorityInstructionPath(path) {
|
|
566
|
+
const normalized = path.map(normalizeAkkModelFacingFieldName);
|
|
567
|
+
if (normalized.at(-1) !== "body")
|
|
568
|
+
return false;
|
|
569
|
+
const callbackMessageBody = normalized.slice(-3).join(".") ===
|
|
570
|
+
"callbackdelivery.message.body";
|
|
571
|
+
return callbackMessageBody || normalized.includes("recentevents");
|
|
572
|
+
}
|
|
573
|
+
export function modelFacingToolError(error) {
|
|
574
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
575
|
+
return error;
|
|
576
|
+
}
|
|
577
|
+
return new Error(modelFacingErrorMessage(error));
|
|
578
|
+
}
|
|
579
|
+
export function modelFacingErrorMessage(error) {
|
|
580
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
581
|
+
return sanitizeAkkModelFacingDiagnosticText(message);
|
|
582
|
+
}
|
|
583
|
+
export function isBlockedTerminalDispatchResult(result) {
|
|
584
|
+
return Boolean(isRecord(result) &&
|
|
585
|
+
result.source === "terminal_control" &&
|
|
586
|
+
result.terminal_dispatch_resolved !== true);
|
|
587
|
+
}
|
|
588
|
+
export function isSubmissionError(result) {
|
|
589
|
+
if (!isRecord(result)) {
|
|
590
|
+
return false;
|
|
591
|
+
}
|
|
592
|
+
if (isSuccessfulTerminalDispatch(result)) {
|
|
593
|
+
return false;
|
|
594
|
+
}
|
|
595
|
+
if (terminalSubmissionReported(result)) {
|
|
596
|
+
return !isAkkNativeSubmissionAccepted(result);
|
|
597
|
+
}
|
|
598
|
+
return [
|
|
599
|
+
"submission_unfenced",
|
|
600
|
+
"submission_uncertain",
|
|
601
|
+
"submission_aborted",
|
|
602
|
+
"submission_pending_acceptance",
|
|
603
|
+
"submission_not_accepted"
|
|
604
|
+
].includes(String(result.status ?? "")) ||
|
|
605
|
+
["uncertain", "aborted", "pending_acceptance", "not_accepted"].includes(String(result.submission_outcome ?? "")) ||
|
|
606
|
+
result.status === "delivered_unfenced";
|
|
607
|
+
}
|
|
608
|
+
function terminalSubmissionReported(result) {
|
|
609
|
+
return result.submission_outcome !== undefined ||
|
|
610
|
+
result.delivery_receipt !== undefined ||
|
|
611
|
+
result.delivered !== undefined;
|
|
612
|
+
}
|
|
613
|
+
export function withTurnIdentity(result) {
|
|
614
|
+
if (!isRecord(result)) {
|
|
615
|
+
return result;
|
|
616
|
+
}
|
|
617
|
+
const sources = [
|
|
618
|
+
{ label: "result", value: result },
|
|
619
|
+
{ label: "result.conversation", value: result.conversation },
|
|
620
|
+
{ label: "result.summary", value: result.summary },
|
|
621
|
+
{ label: "result.message", value: result.message }
|
|
622
|
+
];
|
|
623
|
+
const compatibilityId = consistentResultIdentity("conversation_id", sources);
|
|
624
|
+
const explicitSessionId = consistentResultIdentity("session_id", sources);
|
|
625
|
+
const explicitTurnId = consistentResultIdentity("turn_id", sources);
|
|
626
|
+
const hasModernIdentity = Boolean(explicitSessionId || explicitTurnId);
|
|
627
|
+
if (hasModernIdentity && (!explicitSessionId || !explicitTurnId)) {
|
|
628
|
+
throw new Error("agent-knock-knock CLI returned a partial session_id/turn_id identity");
|
|
629
|
+
}
|
|
630
|
+
if (hasModernIdentity && !compatibilityId) {
|
|
631
|
+
throw new Error("agent-knock-knock CLI returned modern identity without conversation_id");
|
|
632
|
+
}
|
|
633
|
+
if (hasModernIdentity && compatibilityId !== explicitTurnId) {
|
|
634
|
+
throw new Error("agent-knock-knock CLI returned conversation_id that differs from turn_id");
|
|
635
|
+
}
|
|
636
|
+
if (!hasModernIdentity && !compatibilityId) {
|
|
637
|
+
return result;
|
|
638
|
+
}
|
|
639
|
+
if (!hasModernIdentity &&
|
|
640
|
+
(compatibilityId?.startsWith("terminal:") ||
|
|
641
|
+
stringValue(result.source) === "terminal" ||
|
|
642
|
+
(isRecord(result.summary) &&
|
|
643
|
+
stringValue(result.summary.source) === "terminal"))) {
|
|
644
|
+
return result;
|
|
645
|
+
}
|
|
646
|
+
const sessionId = explicitSessionId ?? compatibilityId;
|
|
647
|
+
const turnId = explicitTurnId ?? compatibilityId;
|
|
648
|
+
return {
|
|
649
|
+
...result,
|
|
650
|
+
session_id: sessionId,
|
|
651
|
+
turn_id: turnId
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
function consistentResultIdentity(field, sources) {
|
|
655
|
+
const values = sources.flatMap(({ label, value }) => {
|
|
656
|
+
if (!isRecord(value) || !Object.hasOwn(value, field)) {
|
|
657
|
+
return [];
|
|
658
|
+
}
|
|
659
|
+
const identity = stringValue(value[field]);
|
|
660
|
+
if (!identity) {
|
|
661
|
+
throw new Error(`agent-knock-knock CLI returned invalid ${label}.${field}`);
|
|
662
|
+
}
|
|
663
|
+
return [{ label, identity }];
|
|
664
|
+
});
|
|
665
|
+
const expected = values[0];
|
|
666
|
+
for (const candidate of values.slice(1)) {
|
|
667
|
+
if (candidate.identity !== expected.identity) {
|
|
668
|
+
throw new Error(`agent-knock-knock CLI returned conflicting ${field} between ${expected.label} and ${candidate.label}`);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
return expected?.identity;
|
|
672
|
+
}
|
|
673
|
+
function truncateText(value, maxLength) {
|
|
674
|
+
const text = String(value ?? "").replace(/\s+/g, " ").trim();
|
|
675
|
+
if (text.length <= maxLength) {
|
|
676
|
+
return text;
|
|
677
|
+
}
|
|
678
|
+
return `${text.slice(0, Math.max(0, maxLength - 1))}...`;
|
|
679
|
+
}
|
|
680
|
+
//# sourceMappingURL=semantic-tool-presentation.js.map
|