@sema-agent/client-core 0.93.1 → 0.95.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 +554 -0
- package/README.md +89 -55
- package/dist/adapt/arms.js +13 -11
- package/dist/adapt/panelTasks.js +4 -10
- package/dist/adapt/toolCards.js +2 -2
- package/dist/adapt/wireShapes.js +3 -8
- package/dist/adapter/activeRunSelfHeal.d.ts +8 -3
- package/dist/adapter/activeRunSelfHeal.js +20 -12
- package/dist/adapter/downstream/eventToSdkMessage.js +24 -17
- package/dist/adapter/downstream/terminalToSdkResult.js +13 -6
- package/dist/adapter/runStream.js +2 -1
- package/dist/adapter/types.d.ts +7 -0
- package/dist/adapter/types.js +15 -0
- package/dist/agentSession/backgroundView.js +5 -1
- package/dist/agentSession/engineAgentRegistryRead.js +2 -1
- package/dist/agentSession/engineSessionBackgroundStop.js +5 -3
- package/dist/agentsWireCaps.d.ts +17 -0
- package/dist/agentsWireCaps.js +111 -1
- package/dist/approvalDecidedByCapability.d.ts +0 -1
- package/dist/approvalDecidedByCapability.js +2 -7
- package/dist/approvalReachWire.d.ts +18 -0
- package/dist/approvalReachWire.js +58 -0
- package/dist/approvalsStreamLiveCapability.d.ts +0 -1
- package/dist/approvalsStreamLiveCapability.js +15 -14
- package/dist/atMostOnce.d.ts +8 -0
- package/dist/atMostOnce.js +36 -0
- package/dist/attachmentSeatCapability.d.ts +0 -1
- package/dist/attachmentSeatCapability.js +0 -3
- package/dist/attachmentsWireCaps.js +11 -6
- package/dist/bashExitReading.d.ts +10 -0
- package/dist/bashExitReading.js +12 -0
- package/dist/callerCwdCapability.d.ts +15 -0
- package/dist/callerCwdCapability.js +42 -0
- package/dist/centerWiringCapability.d.ts +1 -3
- package/dist/centerWiringCapability.js +18 -21
- package/dist/classifierStatus.js +4 -4
- package/dist/cloudConfigWireCaps.js +43 -21
- package/dist/compensations.js +1 -1
- package/dist/controlRouter.js +3 -10
- package/dist/coreValuePorts.d.ts +64 -1
- package/dist/coreValuePorts.js +30 -0
- package/dist/cycleOrder.d.ts +15 -0
- package/dist/cycleOrder.js +45 -0
- package/dist/decideFailureNote.js +4 -1
- package/dist/decideReceipt.d.ts +2 -1
- package/dist/decideReceipt.js +41 -13
- package/dist/declared/supportFloorDeclared.d.ts +1 -0
- package/dist/declared/supportFloorDeclared.js +5 -0
- package/dist/detachWire.d.ts +1 -4
- package/dist/detachWire.js +1 -1
- package/dist/deviceExecutorManagementCapability.d.ts +0 -1
- package/dist/deviceExecutorManagementCapability.js +36 -40
- package/dist/deviceFlowPolling.d.ts +5 -0
- package/dist/deviceFlowPolling.js +28 -0
- package/dist/deviceRebind.d.ts +88 -0
- package/dist/deviceRebind.js +242 -0
- package/dist/displayUntrusted.d.ts +1 -0
- package/dist/displayUntrusted.js +963 -30
- package/dist/engineAgentAbsence.d.ts +2 -2
- package/dist/engineAgentPanelStore.d.ts +8 -18
- package/dist/engineAgentPanelStore.js +19 -537
- package/dist/engineCapReader.d.ts +6 -6
- package/dist/engineCapReader.js +30 -43
- package/dist/engineCapsCache.d.ts +7 -2
- package/dist/engineCapsCache.js +64 -26
- package/dist/engineCredentialRequirement.d.ts +9 -0
- package/dist/engineCredentialRequirement.js +23 -0
- package/dist/engineEnvSourcing.d.ts +53 -0
- package/dist/engineEnvSourcing.js +81 -0
- package/dist/engineErrorCodes.d.ts +19 -4
- package/dist/engineErrorCodes.js +39 -21
- package/dist/engineIdentity.js +2 -0
- package/dist/engineNoticeCodes.d.ts +22 -2
- package/dist/engineNoticeCodes.js +73 -6
- package/dist/engineRefusedToolName.d.ts +1 -0
- package/dist/engineRefusedToolName.js +8 -0
- package/dist/engineWireSdk.js +2 -2
- package/dist/executionLaneCapability.d.ts +2 -3
- package/dist/executionLaneCapability.js +28 -28
- package/dist/fileHistoryCaptureCapability.d.ts +0 -1
- package/dist/fileHistoryCaptureCapability.js +13 -12
- package/dist/fileHistoryLegNotice.d.ts +14 -2
- package/dist/fileHistoryLegNotice.js +101 -15
- package/dist/fleet/fleetLedger.d.ts +2 -0
- package/dist/fleet/fleetLedger.js +74 -52
- package/dist/fleet/fleetProjection.d.ts +0 -3
- package/dist/fleet/fleetProjection.js +9 -16
- package/dist/fleetAgentPanelProjection.d.ts +4 -17
- package/dist/fleetAgentPanelProjection.js +7 -197
- package/dist/fleetAgentRowLike.d.ts +16 -0
- package/dist/fleetAgentRowLike.js +1 -0
- package/dist/gateOutcome.d.ts +2 -1
- package/dist/gateOutcome.js +33 -18
- package/dist/gateVocabulary.js +1 -1
- package/dist/generated/engineAskFaceTables.d.ts +3 -0
- package/dist/generated/engineAskFaceTables.js +12 -0
- package/dist/generated/engineFactTables.d.ts +4 -2
- package/dist/generated/engineFactTables.js +13 -0
- package/dist/generated/engineNoticeTables.d.ts +5 -0
- package/dist/generated/engineNoticeTables.js +7 -0
- package/dist/generated/sdkFactTables.d.ts +5 -0
- package/dist/generated/sdkFactTables.js +34 -0
- package/dist/generated/settingsSchemaFns.d.ts +10 -0
- package/dist/generated/settingsSchemaFns.js +22 -0
- package/dist/generated/settingsSchemaTables.d.ts +3 -0
- package/dist/generated/settingsSchemaTables.js +3 -0
- package/dist/headlessPermissionModeWire.d.ts +2 -2
- package/dist/headlessPermissionModeWire.js +11 -21
- package/dist/headlessReconnectWire.js +49 -20
- package/dist/hitl/allowRuleShadow.d.ts +1 -1
- package/dist/hitl/allowRuleShadow.js +49 -8
- package/dist/hitl/approvalCompleteParked.d.ts +1 -0
- package/dist/hitl/approvalCompleteParked.js +14 -0
- package/dist/hitl/approvalEndingCause.d.ts +5 -0
- package/dist/hitl/approvalEndingCause.js +61 -0
- package/dist/hitl/approvalHolds.d.ts +46 -0
- package/dist/hitl/approvalHolds.js +140 -0
- package/dist/hitl/approvalOutcomeNote.js +2 -1
- package/dist/hitl/approvalResolution.js +9 -1
- package/dist/hitl/approvalsFeed.js +23 -6
- package/dist/hitl/askGateWire.d.ts +2 -1
- package/dist/hitl/askGateWire.js +29 -1
- package/dist/hitl/automaticAnswerVerdict.d.ts +8 -2
- package/dist/hitl/automaticAnswerVerdict.js +71 -23
- package/dist/hitl/crashConverged.js +2 -0
- package/dist/hitl/decisionConflict.d.ts +3 -0
- package/dist/hitl/decisionConflict.js +43 -0
- package/dist/hitl/decisionRefusal.d.ts +23 -0
- package/dist/hitl/decisionRefusal.js +88 -0
- package/dist/hitl/frameRouter.d.ts +10 -0
- package/dist/hitl/frameRouter.js +71 -32
- package/dist/hitl/gateLedger.d.ts +8 -0
- package/dist/hitl/gateLedger.js +38 -0
- package/dist/hitl/hitlBridge.d.ts +14 -3
- package/dist/hitl/hitlBridge.js +75 -62
- package/dist/hitl/hitlHostSurface.d.ts +3 -0
- package/dist/hitl/hitlHostSurface.js +17 -15
- package/dist/hitl/livePendingAsk.d.ts +16 -6
- package/dist/hitl/livePendingAsk.js +36 -4
- package/dist/hitl/localAllowRule.js +2 -1
- package/dist/hitl/noAllowCause.d.ts +9 -0
- package/dist/hitl/noAllowCause.js +26 -0
- package/dist/hitl/parkExpiryJudgements.d.ts +19 -0
- package/dist/hitl/parkExpiryJudgements.js +46 -0
- package/dist/hitl/parkResolver.d.ts +3 -7
- package/dist/hitl/parkResolver.js +55 -28
- package/dist/hitl/parkRowBirthWait.js +2 -1
- package/dist/hitl/persistedRulesWire.d.ts +6 -1
- package/dist/hitl/persistedRulesWire.js +16 -4
- package/dist/hitl/planReviewWire.d.ts +2 -3
- package/dist/hitl/planReviewWire.js +86 -39
- package/dist/hitl/replayedApproval.d.ts +8 -0
- package/dist/hitl/replayedApproval.js +125 -10
- package/dist/hitl/resumeRunningCard.d.ts +2 -0
- package/dist/hitl/resumeRunningCard.js +15 -4
- package/dist/hitl/sessionPolicyDeliverable.d.ts +1 -1
- package/dist/hitl/sessionPolicyDeliverable.js +3 -8
- package/dist/hitl/sessionPolicyWire.js +1 -1
- package/dist/hitl/toolApprovalWire.d.ts +50 -5
- package/dist/hitl/toolApprovalWire.js +368 -56
- package/dist/hooksWireCaps.js +38 -6
- package/dist/host.d.ts +5 -0
- package/dist/host.js +3 -1
- package/dist/hostCallbackGuard.d.ts +1 -0
- package/dist/hostCallbackGuard.js +25 -0
- package/dist/humanTurnRead.d.ts +15 -1
- package/dist/humanTurnRead.js +28 -2
- package/dist/index.d.ts +45 -14
- package/dist/index.js +33 -12
- package/dist/interactiveInterrupt.d.ts +8 -0
- package/dist/interactiveInterrupt.js +54 -0
- package/dist/limitsWire.d.ts +5 -1
- package/dist/limitsWire.js +51 -13
- package/dist/liveModelCatalog.d.ts +109 -0
- package/dist/liveModelCatalog.js +344 -18
- package/dist/mcpEngineLeg.d.ts +25 -0
- package/dist/mcpEngineLeg.js +71 -15
- package/dist/mcpPanel.js +2 -1
- package/dist/mcpProbeCapability.d.ts +0 -1
- package/dist/mcpProbeCapability.js +13 -12
- package/dist/mcpReconnect.d.ts +1 -3
- package/dist/mcpReconnect.js +20 -10
- package/dist/memoryComplianceCapability.d.ts +0 -1
- package/dist/memoryComplianceCapability.js +14 -13
- package/dist/memoryOriginCapability.d.ts +0 -1
- package/dist/memoryOriginCapability.js +14 -13
- package/dist/memoryVerbsWire.d.ts +1 -1
- package/dist/memoryVerbsWire.js +4 -0
- package/dist/model/liveCatalogShape.d.ts +14 -0
- package/dist/model/liveCatalogShape.js +71 -0
- package/dist/model/modelSupplyRules.d.ts +1 -0
- package/dist/model/modelSupplyRules.js +30 -9
- package/dist/model/modelsPolicy.d.ts +21 -0
- package/dist/model/modelsPolicy.js +90 -0
- package/dist/modelIdentityResolvability.d.ts +4 -2
- package/dist/modelIdentityResolvability.js +25 -5
- package/dist/modelSwitchFallback.d.ts +69 -0
- package/dist/modelSwitchFallback.js +206 -0
- package/dist/notifications.js +12 -11
- package/dist/outputStyleSeatCapability.d.ts +15 -0
- package/dist/outputStyleSeatCapability.js +42 -0
- package/dist/ownKey.d.ts +7 -0
- package/dist/ownKey.js +58 -0
- package/dist/panelReduce.d.ts +114 -0
- package/dist/panelReduce.js +1135 -0
- package/dist/panelStateHolder.d.ts +17 -0
- package/dist/panelStateHolder.js +201 -0
- package/dist/peerLaneCapability.d.ts +0 -1
- package/dist/peerLaneCapability.js +15 -14
- package/dist/permissionModesCapability.d.ts +0 -1
- package/dist/permissionModesCapability.js +5 -10
- package/dist/permissionRuleIssue.js +1 -1
- package/dist/permissionRulesWriteCapability.d.ts +0 -1
- package/dist/permissionRulesWriteCapability.js +15 -14
- package/dist/permissionsAllowGrantCapability.d.ts +2 -1
- package/dist/permissionsAllowGrantCapability.js +35 -19
- package/dist/permissionsDeclaration.d.ts +16 -1
- package/dist/permissionsDeclaration.js +142 -15
- package/dist/printToolResultFrame.js +2 -10
- package/dist/promptDelivery.js +0 -8
- package/dist/protocolSegment.d.ts +1 -0
- package/dist/protocolSegment.js +13 -1
- package/dist/request/taskRequest.d.ts +11 -3
- package/dist/request/taskRequest.js +13 -1
- package/dist/resultFrameKeys.d.ts +4 -0
- package/dist/resultFrameKeys.js +13 -0
- package/dist/resumeRefusalCopy.d.ts +18 -1
- package/dist/resumeRefusalCopy.js +132 -31
- package/dist/retryStatus.js +6 -4
- package/dist/rewindArchiveCapability.d.ts +2 -1
- package/dist/rewindArchiveCapability.js +28 -15
- package/dist/rewindEngineAction.d.ts +21 -0
- package/dist/rewindEngineAction.js +36 -0
- package/dist/rewindWireCaps.d.ts +2 -1
- package/dist/rewindWireCaps.js +1 -0
- package/dist/{hitl/rosterMountedNames.d.ts → rosterMountedNames.d.ts} +1 -1
- package/dist/runCancelContext.js +2 -1
- package/dist/runTerminal.d.ts +0 -11
- package/dist/runTerminal.js +4 -27
- package/dist/sdkRegistryTransit.d.ts +2 -1
- package/dist/sdkRegistryTransit.js +1 -0
- package/dist/sealedKeyCapability.d.ts +0 -1
- package/dist/sealedKeyCapability.js +19 -20
- package/dist/seatContract.d.ts +85 -28
- package/dist/seatContract.js +512 -148
- package/dist/sessionIdSegment.d.ts +1 -0
- package/dist/sessionIdSegment.js +11 -0
- package/dist/sessionMemoryErase.d.ts +1 -1
- package/dist/sessionMemoryErase.js +6 -1
- package/dist/sessionMemoryStatus.js +3 -2
- package/dist/sessionPolicyCapability.d.ts +0 -1
- package/dist/sessionPolicyCapability.js +14 -13
- package/dist/sessionReadRedactionCapability.d.ts +15 -0
- package/dist/sessionReadRedactionCapability.js +42 -0
- package/dist/sessionSyncFileHistoryCapability.d.ts +0 -1
- package/dist/sessionSyncFileHistoryCapability.js +13 -12
- package/dist/skillToolListsCapability.d.ts +0 -1
- package/dist/skillToolListsCapability.js +13 -12
- package/dist/skillsWireCaps.d.ts +4 -0
- package/dist/skillsWireCaps.js +66 -1
- package/dist/sqlEngineCapability.d.ts +0 -1
- package/dist/sqlEngineCapability.js +21 -21
- package/dist/steerPriorityCapability.d.ts +0 -1
- package/dist/steerPriorityCapability.js +18 -19
- package/dist/storePostureCapability.d.ts +1 -1
- package/dist/storePostureCapability.js +16 -16
- package/dist/streamDrainingLegs.d.ts +6 -0
- package/dist/streamDrainingLegs.js +23 -0
- package/dist/subagent/agentStateDetail.d.ts +1 -0
- package/dist/subagent/agentStateDetail.js +41 -0
- package/dist/subagent/engineCompactWire.d.ts +15 -0
- package/dist/subagent/engineCompactWire.js +82 -45
- package/dist/subagent/engineDelegatedPrompt.js +10 -6
- package/dist/subagent/engineSubagentOutput.d.ts +0 -1
- package/dist/subagent/engineSubagentOutput.js +5 -20
- package/dist/subagent/engineSubagentTail.d.ts +0 -1
- package/dist/subagent/engineSubagentTail.js +7 -32
- package/dist/subagentContentStore.js +3 -3
- package/dist/supportFloor.js +2 -5
- package/dist/taskRequestWords.d.ts +2 -4
- package/dist/taskRequestWords.js +3 -2
- package/dist/terminalStatuses.d.ts +30 -0
- package/dist/terminalStatuses.js +67 -0
- package/dist/toolResult.d.ts +5 -0
- package/dist/toolResult.js +88 -36
- package/dist/types/engineState.d.ts +2 -1
- package/dist/usageAnalytics.d.ts +146 -0
- package/dist/usageAnalytics.js +311 -0
- package/dist/userAttachmentEnvelope.d.ts +22 -1
- package/dist/userAttachmentEnvelope.js +90 -2
- package/dist/userInvokedSkillsCapability.d.ts +0 -1
- package/dist/userInvokedSkillsCapability.js +13 -12
- package/dist/webSearchBackendCapability.d.ts +0 -1
- package/dist/webSearchBackendCapability.js +20 -19
- package/dist/webSearchWireCaps.js +3 -11
- package/dist/wireErrorTriage.d.ts +11 -0
- package/dist/wireErrorTriage.js +35 -0
- package/dist/wireFailureShape.d.ts +10 -0
- package/dist/wireFailureShape.js +72 -5
- package/dist/wireRefusalCopy.d.ts +6 -1
- package/dist/wireRefusalCopy.js +23 -25
- package/dist/wiringInstructionsAttribution.d.ts +10 -0
- package/dist/wiringInstructionsAttribution.js +67 -0
- package/dist/workflowClient.js +19 -2
- package/dist/workflowsJournalCapability.d.ts +0 -1
- package/dist/workflowsJournalCapability.js +13 -12
- package/dist/writeProtectionCapability.d.ts +0 -1
- package/dist/writeProtectionCapability.js +26 -26
- package/docs/INTEGRATION-CLIENTS.md +1733 -52
- package/package.json +5 -5
- package/dist/askSurvivesStandingAnswer.d.ts +0 -13
- package/dist/askSurvivesStandingAnswer.js +0 -53
- package/dist/engineCapsGenerationGuard.d.ts +0 -4
- package/dist/engineCapsGenerationGuard.js +0 -19
- package/dist/hitl/askSurvivesPosture.d.ts +0 -20
- package/dist/hitl/askSurvivesPosture.js +0 -48
- package/dist/panelRunningHistory.d.ts +0 -22
- package/dist/panelRunningHistory.js +0 -82
- package/dist/registryConflict.d.ts +0 -3
- package/dist/registryConflict.js +0 -44
- /package/dist/{hitl/rosterMountedNames.js → rosterMountedNames.js} +0 -0
package/dist/toolResult.js
CHANGED
|
@@ -3,6 +3,8 @@ import { markEngineWorkflowNotified, registerOutstandingBgTask, registerOutstand
|
|
|
3
3
|
import { parseWorkflowPollEnvelope, projectWorkflowTaskOutput } from './workflow.js';
|
|
4
4
|
import { asModelFallbackReason } from './engineErrorCodes.js';
|
|
5
5
|
import { frozenSet } from './frozenSet.js';
|
|
6
|
+
import { bashExitOf, bashExitReadingFailed } from './bashExitReading.js';
|
|
7
|
+
import { isCoreSemaTaskTerminal } from './terminalStatuses.js';
|
|
6
8
|
import { CORE_ENGINE_CARD_TYPES } from './generated/engineFactTables.js';
|
|
7
9
|
export const STRUCTURED_DETAIL_TYPES = frozenSet(CORE_ENGINE_CARD_TYPES);
|
|
8
10
|
export function structuredDetailType(structured) {
|
|
@@ -12,11 +14,6 @@ export function structuredDetailType(structured) {
|
|
|
12
14
|
return typeof t === 'string' && STRUCTURED_DETAIL_TYPES.has(t) ? t : undefined;
|
|
13
15
|
}
|
|
14
16
|
const MAX_STRUCTURED_FIELD_CHARS = 1_000_000;
|
|
15
|
-
const WF_TERMINAL_STATUSES = new Set([
|
|
16
|
-
'completed',
|
|
17
|
-
'failed',
|
|
18
|
-
'cancelled',
|
|
19
|
-
]);
|
|
20
17
|
export const PROTOCOL_MARKERS = {
|
|
21
18
|
bashHead: /^exit code: (-?\d+)(?: \(([^)\n]*)\))?\n(--- stdout ---\n)?/,
|
|
22
19
|
bashStderrSep: '\n--- stderr ---\n',
|
|
@@ -28,6 +25,7 @@ export const PROTOCOL_MARKERS = {
|
|
|
28
25
|
delegationNoTextResult: '(no text result)',
|
|
29
26
|
delegationTrailer: 'Verify this result before concluding. If it leaves more to do, continue or delegate again.',
|
|
30
27
|
delegationTrailerFork: 'Verify this result before concluding. If it leaves more to do, continue the work yourself or fork again.',
|
|
28
|
+
delegationFieldLine: /^(status|error|error_kind|observer|stats|worktree):(?: ([^\r\u2028\u2029\u0085]*))?/,
|
|
31
29
|
taskOutputLabel: /^TaskOutput\s+(\S+)$/,
|
|
32
30
|
taskOutputStatus: /^status:\s*(.+)$/m,
|
|
33
31
|
taskOutputHeadSlots: /^(\r?\n)(?:(state: ([^\r\n\u2028\u2029\u0085]*)(?:\r?\n|$)))?(?:(error: ([^\r\n\u2028\u2029\u0085]*)(?:\r?\n|$)))?/,
|
|
@@ -35,7 +33,7 @@ export const PROTOCOL_MARKERS = {
|
|
|
35
33
|
taskOutputNoneSentinel: '(none)',
|
|
36
34
|
taskOutputStdoutLine: /^--- (?:new )?stdout[^\n]*---\n?/m,
|
|
37
35
|
taskOutputStderrLine: /^--- (?:new )?stderr[^\n]*---\n?/m,
|
|
38
|
-
taskOutputResultLine: /^--- result(?: \([^)\n]*\))? ---\n?/m,
|
|
36
|
+
taskOutputResultLine: /^--- result(?: \((?:[^)\n\r\u2028\u2029]|[\r\u2028\u2029](?!--- result))*\))? ---\n?/m,
|
|
39
37
|
spoolStdoutFull: '--- stdout (full, re-readable) ---',
|
|
40
38
|
spoolStdoutIncremental: '--- new stdout ---',
|
|
41
39
|
};
|
|
@@ -78,6 +76,59 @@ export function stripUntrustedFence(text) {
|
|
|
78
76
|
return null;
|
|
79
77
|
return { label: m[1] ?? '', body: m[2] ?? '' };
|
|
80
78
|
}
|
|
79
|
+
function delegationFrameSlots(lines, headAt, labelAt, fromAt) {
|
|
80
|
+
const read = (i) => {
|
|
81
|
+
const line = lines[i] ?? '';
|
|
82
|
+
const hit = PROTOCOL_MARKERS.delegationFieldLine.exec(line);
|
|
83
|
+
if (hit === null)
|
|
84
|
+
return null;
|
|
85
|
+
const value = hit[2];
|
|
86
|
+
return { key: hit[1] ?? '', value: value !== undefined && hit[0].length === line.length && value.trim() !== '' ? value : undefined };
|
|
87
|
+
};
|
|
88
|
+
const fields = [];
|
|
89
|
+
for (let i = headAt + 1; i < labelAt; i++)
|
|
90
|
+
fields.push(read(i));
|
|
91
|
+
const errorFollowedByEngineField = (at) => {
|
|
92
|
+
const next = fields[at + 1];
|
|
93
|
+
return next !== null && next !== undefined && next.value !== undefined && (next.key === 'error_kind' || next.key === 'observer' || next.key === 'stats');
|
|
94
|
+
};
|
|
95
|
+
const worktreeBefore = (at) => fields.slice(0, at).some((f) => f?.key === 'worktree');
|
|
96
|
+
const soleAt = (key) => {
|
|
97
|
+
let at = -1;
|
|
98
|
+
for (let i = 0; i < fields.length; i++) {
|
|
99
|
+
if (fields[i]?.key !== key)
|
|
100
|
+
continue;
|
|
101
|
+
if (at >= 0)
|
|
102
|
+
return -1;
|
|
103
|
+
at = i;
|
|
104
|
+
}
|
|
105
|
+
return at;
|
|
106
|
+
};
|
|
107
|
+
const claimed = new Set([headAt, labelAt]);
|
|
108
|
+
if (fromAt > labelAt + 1)
|
|
109
|
+
claimed.add(labelAt + 1);
|
|
110
|
+
const slots = {};
|
|
111
|
+
const first = fields[0] ?? null;
|
|
112
|
+
if (first !== null && first.key === 'status' && first.value !== undefined && soleAt('status') === 0) {
|
|
113
|
+
slots.status = first.value.trim();
|
|
114
|
+
claimed.add(headAt + 1);
|
|
115
|
+
for (const key of ['error', 'stats']) {
|
|
116
|
+
const at = soleAt(key);
|
|
117
|
+
const value = at >= 0 ? fields[at]?.value : undefined;
|
|
118
|
+
if (value === undefined || (key === 'error' && (!errorFollowedByEngineField(at) || worktreeBefore(at))))
|
|
119
|
+
continue;
|
|
120
|
+
slots[key] = value;
|
|
121
|
+
claimed.add(headAt + 1 + at);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
let rest = '';
|
|
125
|
+
for (let i = 0; i < fromAt; i++)
|
|
126
|
+
if (!claimed.has(i))
|
|
127
|
+
rest += `${lines[i] ?? ''}\n`;
|
|
128
|
+
if (rest.trim() !== '')
|
|
129
|
+
slots.headRest = rest;
|
|
130
|
+
return slots;
|
|
131
|
+
}
|
|
81
132
|
function locateDelegationResultSection(text) {
|
|
82
133
|
const lines = text.split('\n');
|
|
83
134
|
const soleLineAt = (hit) => {
|
|
@@ -107,14 +158,14 @@ function locateDelegationResultSection(text) {
|
|
|
107
158
|
};
|
|
108
159
|
if (trailerAt === labelAt + 2 && lines[labelAt + 1] === PROTOCOL_MARKERS.delegationNoTextResult) {
|
|
109
160
|
const c = cut(labelAt + 1);
|
|
110
|
-
return { section: 'no_text_result', before: c.before, after: c.after };
|
|
161
|
+
return { section: 'no_text_result', before: c.before, after: c.after, slots: delegationFrameSlots(lines, headAt, labelAt, labelAt + 1) };
|
|
111
162
|
}
|
|
112
163
|
const partial = lines[labelAt + 1] === PROTOCOL_MARKERS.delegationPartialFindingsLabel;
|
|
113
164
|
const from = partial ? labelAt + 2 : labelAt + 1;
|
|
114
165
|
if (from >= trailerAt)
|
|
115
166
|
return null;
|
|
116
167
|
const c = cut(from);
|
|
117
|
-
return { section: partial ? 'partial_findings' : 'result', before: c.before, fenceText: c.middle, after: c.after };
|
|
168
|
+
return { section: partial ? 'partial_findings' : 'result', before: c.before, fenceText: c.middle, after: c.after, slots: delegationFrameSlots(lines, headAt, labelAt, from) };
|
|
118
169
|
}
|
|
119
170
|
export function displayBody(text, origin = 'any_tool_result') {
|
|
120
171
|
if (typeof text !== 'string')
|
|
@@ -128,14 +179,14 @@ export function displayBody(text, origin = 'any_tool_result') {
|
|
|
128
179
|
if (located === null)
|
|
129
180
|
return { fenced: false, body: text };
|
|
130
181
|
if (located.section === 'no_text_result') {
|
|
131
|
-
const { before, after, section } = located;
|
|
132
|
-
return { fenced: false, body: '', frame: { before, after, section } };
|
|
182
|
+
const { before, after, section, slots } = located;
|
|
183
|
+
return { fenced: false, body: '', frame: { before, after, section, ...slots } };
|
|
133
184
|
}
|
|
134
185
|
const inner = stripUntrustedFence(located.fenceText);
|
|
135
186
|
if (inner === null)
|
|
136
187
|
return { fenced: false, body: text };
|
|
137
|
-
const { before, after, section } = located;
|
|
138
|
-
return { fenced: true, label: inner.label, body: inner.body, frame: { before, after, section } };
|
|
188
|
+
const { before, after, section, slots } = located;
|
|
189
|
+
return { fenced: true, label: inner.label, body: inner.body, frame: { before, after, section, ...slots } };
|
|
139
190
|
}
|
|
140
191
|
export function parseModelFacingTaskOutput(text) {
|
|
141
192
|
modelFacingParseCount++;
|
|
@@ -241,7 +292,7 @@ export function wireOutputToBody(toolName, output, isError, truncated, flatten,
|
|
|
241
292
|
: typeof bgBlock?.task_id === 'string'
|
|
242
293
|
? bgBlock.task_id
|
|
243
294
|
: undefined;
|
|
244
|
-
if (
|
|
295
|
+
if (readBashDetachView(structured)?.handoffTaskId !== undefined)
|
|
245
296
|
bgTaskId = undefined;
|
|
246
297
|
}
|
|
247
298
|
else {
|
|
@@ -255,20 +306,23 @@ export function wireOutputToBody(toolName, output, isError, truncated, flatten,
|
|
|
255
306
|
};
|
|
256
307
|
}
|
|
257
308
|
}
|
|
258
|
-
|
|
309
|
+
let parsedMemo;
|
|
310
|
+
const parseOnce = () => (parsedMemo === undefined ? (parsedMemo = parseModelFacingBash(text)) : parsedMemo);
|
|
311
|
+
const exit = bashExitOf(structured, parseOnce);
|
|
312
|
+
const structuredSlots = sType === 'bash' && (typeof s?.stdout === 'string' || typeof s?.stderr === 'string');
|
|
313
|
+
const textSlots = structuredSlots ? null : parseOnce();
|
|
314
|
+
const slots = structuredSlots
|
|
259
315
|
? {
|
|
260
316
|
stdout: typeof s?.stdout === 'string' ? s.stdout : '',
|
|
261
317
|
stderr: typeof s?.stderr === 'string' ? s.stderr : '',
|
|
262
|
-
exitCode:
|
|
318
|
+
exitCode: exit.exitCode,
|
|
263
319
|
}
|
|
264
|
-
:
|
|
320
|
+
: textSlots !== null
|
|
321
|
+
? { ...textSlots, exitCode: exit.exitCode }
|
|
322
|
+
: null;
|
|
265
323
|
if (slots) {
|
|
266
|
-
const benignInterp =
|
|
267
|
-
|
|
268
|
-
: 'note' in slots && typeof slots.note === 'string' && slots.note.length > 0
|
|
269
|
-
? slots.note
|
|
270
|
-
: undefined;
|
|
271
|
-
const failed = isError || (slots.exitCode != null && slots.exitCode !== 0 && benignInterp === undefined);
|
|
324
|
+
const benignInterp = exit.benignNote;
|
|
325
|
+
const failed = isError || bashExitReadingFailed(exit);
|
|
272
326
|
if (failed) {
|
|
273
327
|
const reason = slots.stderr.length > 0 ? slots.stderr : slots.stdout;
|
|
274
328
|
let body = slots.exitCode != null ? `Exit code ${slots.exitCode}\n${reason}` : reason;
|
|
@@ -293,7 +347,7 @@ export function wireOutputToBody(toolName, output, isError, truncated, flatten,
|
|
|
293
347
|
};
|
|
294
348
|
}
|
|
295
349
|
const stdout = truncated ? `${text}\n…(truncated)` : text;
|
|
296
|
-
if (isError)
|
|
350
|
+
if (isError || bashExitReadingFailed(exit))
|
|
297
351
|
return { content: stdout, isError: true };
|
|
298
352
|
return { content: stdout, isError, toolUseResult: { stdout, stderr: '', interrupted: false } };
|
|
299
353
|
}
|
|
@@ -316,7 +370,7 @@ export function wireOutputToBody(toolName, output, isError, truncated, flatten,
|
|
|
316
370
|
}
|
|
317
371
|
const wfEnvelope = parseWorkflowPollEnvelope(text);
|
|
318
372
|
if (wfEnvelope) {
|
|
319
|
-
if (leaderLedger &&
|
|
373
|
+
if (leaderLedger && isCoreSemaTaskTerminal(wfEnvelope.status))
|
|
320
374
|
markEngineWorkflowNotified(wfEnvelope.taskId);
|
|
321
375
|
return wrap({
|
|
322
376
|
task_id: wfEnvelope.taskId,
|
|
@@ -362,23 +416,22 @@ export function structuredToToolUseResult(structured, modelText, leaderLedger =
|
|
|
362
416
|
};
|
|
363
417
|
}
|
|
364
418
|
case 'bash': {
|
|
365
|
-
|
|
419
|
+
const handoffTaskId = readBashDetachView(structured)?.handoffTaskId;
|
|
420
|
+
if (handoffTaskId !== undefined) {
|
|
366
421
|
return {
|
|
367
422
|
toolUseResult: {
|
|
368
423
|
stdout: '',
|
|
369
424
|
stderr: '',
|
|
370
425
|
interrupted: false,
|
|
371
|
-
backgroundTaskId:
|
|
426
|
+
backgroundTaskId: handoffTaskId,
|
|
372
427
|
backgroundedByUser: true,
|
|
373
428
|
},
|
|
374
429
|
};
|
|
375
430
|
}
|
|
376
431
|
if (typeof s.stdout !== 'string' && typeof s.stderr !== 'string')
|
|
377
432
|
return null;
|
|
378
|
-
const
|
|
379
|
-
const benignInterp =
|
|
380
|
-
? s.returnCodeInterpretation
|
|
381
|
-
: undefined;
|
|
433
|
+
const exit = bashExitOf(structured, () => null);
|
|
434
|
+
const benignInterp = exit.benignNote;
|
|
382
435
|
return {
|
|
383
436
|
toolUseResult: {
|
|
384
437
|
stdout: typeof s.stdout === 'string' ? s.stdout : '',
|
|
@@ -386,7 +439,7 @@ export function structuredToToolUseResult(structured, modelText, leaderLedger =
|
|
|
386
439
|
interrupted: false,
|
|
387
440
|
...(benignInterp !== undefined ? { returnCodeInterpretation: benignInterp } : {}),
|
|
388
441
|
},
|
|
389
|
-
...(
|
|
442
|
+
...(bashExitReadingFailed(exit) ? { isError: true } : {}),
|
|
390
443
|
};
|
|
391
444
|
}
|
|
392
445
|
case 'edit': {
|
|
@@ -650,7 +703,7 @@ export function structuredToToolUseResult(structured, modelText, leaderLedger =
|
|
|
650
703
|
const runErrorCode = typeof s.errorCode === 'string' && s.errorCode.length > 0 ? s.errorCode : undefined;
|
|
651
704
|
let output = bodyText ?? '';
|
|
652
705
|
if (taskType === 'workflow') {
|
|
653
|
-
if (leaderLedger &&
|
|
706
|
+
if (leaderLedger && isCoreSemaTaskTerminal(status))
|
|
654
707
|
markEngineWorkflowNotified(taskId);
|
|
655
708
|
const jsonSrc = output.length > 0 ? output : (modelText ?? '');
|
|
656
709
|
output = projectWorkflowTaskOutput(jsonSrc);
|
|
@@ -716,9 +769,9 @@ export function detectEngineBgShellDetach(toolName, rawInput, structured, output
|
|
|
716
769
|
if (toolName !== 'Bash')
|
|
717
770
|
return null;
|
|
718
771
|
const view = readBashDetachView(structured);
|
|
719
|
-
if (view === null ||
|
|
772
|
+
if (view === null || view.registerFailed || view.handoffTaskId === undefined)
|
|
720
773
|
return null;
|
|
721
|
-
return engineBgShellRegistrationBody(view.
|
|
774
|
+
return engineBgShellRegistrationBody(view.handoffTaskId, rawInput, typeof outputText === 'string' ? outputText : '', 'bash');
|
|
722
775
|
}
|
|
723
776
|
function readBashDetachView(structured) {
|
|
724
777
|
if (typeof structured !== 'object' || structured === null)
|
|
@@ -731,9 +784,8 @@ function readBashDetachView(structured) {
|
|
|
731
784
|
const registerFailed = s.registerFailed;
|
|
732
785
|
const taskId = s.task_id;
|
|
733
786
|
return {
|
|
734
|
-
|
|
787
|
+
handoffTaskId: detached === true && typeof taskId === 'string' && taskId.length > 0 ? taskId : undefined,
|
|
735
788
|
registerFailed: registerFailed === true,
|
|
736
|
-
taskId: typeof taskId === 'string' && taskId.length > 0 ? taskId : undefined,
|
|
737
789
|
};
|
|
738
790
|
}
|
|
739
791
|
export function todoWriteToolUseResult(rawInput, oldTodos, isError) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EngineHealth } from '@sema-agent/sdk';
|
|
2
|
-
export interface HealthResponse extends Pick<EngineHealth, 'status' | 'model' | 'sessionBackend' | 'sessions' | 'instanceId' | 'dataRoot' | 'configHash' | 'pid' | 'port' | 'restartRequired' | 'version'> {
|
|
2
|
+
export interface HealthResponse extends Pick<EngineHealth, 'status' | 'model' | 'sessionBackend' | 'sessions' | 'instanceId' | 'dataRoot' | 'configHash' | 'pid' | 'port' | 'restartRequired' | 'version' | 'startedAt'> {
|
|
3
3
|
}
|
|
4
4
|
export interface EnginePortFile {
|
|
5
5
|
port: number;
|
|
@@ -19,6 +19,7 @@ export interface EngineInstance {
|
|
|
19
19
|
instanceId?: string;
|
|
20
20
|
dataRoot?: string;
|
|
21
21
|
configHash?: string;
|
|
22
|
+
startedAt?: number;
|
|
22
23
|
logPath?: string;
|
|
23
24
|
ownedByThisShell: boolean;
|
|
24
25
|
child?: unknown;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type { UsageAnalyticsParams, UsageBreakdown, UsageDimension, UsageGranularity, UsageMetric, UsageSeries, UsageSummary } from '@sema-agent/sdk';
|
|
2
|
+
export declare const USAGE_SENTENCES: Readonly<{
|
|
3
|
+
analyticsUnavailable: "Usage analytics aren’t available on this backend.";
|
|
4
|
+
analyticsUnread: "Usage analytics couldn’t be read just now.";
|
|
5
|
+
modelsUnavailable: "Per-model usage breakdown isn't available on this backend.";
|
|
6
|
+
modelsUnread: "Per-model usage breakdown couldn’t be read just now.";
|
|
7
|
+
}>;
|
|
8
|
+
export interface UsageSummaryQuery extends UsageAnalyticsParams {
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
}
|
|
11
|
+
export interface UsageSeriesQuery extends UsageAnalyticsParams {
|
|
12
|
+
metric?: UsageMetric;
|
|
13
|
+
granularity?: UsageGranularity;
|
|
14
|
+
signal?: AbortSignal;
|
|
15
|
+
}
|
|
16
|
+
export interface UsageBreakdownQuery extends UsageAnalyticsParams {
|
|
17
|
+
dimension?: UsageDimension;
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
}
|
|
20
|
+
export interface UsageAnalyticsVerbs {
|
|
21
|
+
summary?: (opts?: UsageSummaryQuery) => Promise<UsageSummary>;
|
|
22
|
+
series?: (opts?: UsageSeriesQuery) => Promise<UsageSeries>;
|
|
23
|
+
breakdown?: (opts?: UsageBreakdownQuery) => Promise<UsageBreakdown>;
|
|
24
|
+
}
|
|
25
|
+
export interface UsageAnalyticsClientLike {
|
|
26
|
+
usage: UsageAnalyticsVerbs;
|
|
27
|
+
}
|
|
28
|
+
export interface UsageReadOptions {
|
|
29
|
+
from?: string | number;
|
|
30
|
+
to?: string | number;
|
|
31
|
+
principal?: string;
|
|
32
|
+
signal?: AbortSignal;
|
|
33
|
+
}
|
|
34
|
+
export interface UsageSeriesReadOptions extends UsageReadOptions {
|
|
35
|
+
metric?: UsageMetric;
|
|
36
|
+
granularity?: UsageGranularity;
|
|
37
|
+
}
|
|
38
|
+
export interface UsageBreakdownReadOptions extends UsageReadOptions {
|
|
39
|
+
dimension?: UsageDimension;
|
|
40
|
+
}
|
|
41
|
+
export type UsageBound = 'exact' | 'lower' | 'approximate';
|
|
42
|
+
export type UsagePrecision = 'exact' | 'estimated';
|
|
43
|
+
export interface UsageTotalsView {
|
|
44
|
+
tasks?: number;
|
|
45
|
+
tokensIn?: number;
|
|
46
|
+
tokensOut?: number;
|
|
47
|
+
cost?: number;
|
|
48
|
+
precision: UsagePrecision;
|
|
49
|
+
}
|
|
50
|
+
export interface UsageWindowView {
|
|
51
|
+
from?: string;
|
|
52
|
+
to?: string;
|
|
53
|
+
truncated: boolean;
|
|
54
|
+
}
|
|
55
|
+
export type UsageSummaryView = UsageWindowView & UsageTotalsView;
|
|
56
|
+
export interface UsageSeriesPointView {
|
|
57
|
+
t: string;
|
|
58
|
+
v: number;
|
|
59
|
+
estimated?: boolean;
|
|
60
|
+
}
|
|
61
|
+
export interface UsageSeriesView extends UsageWindowView {
|
|
62
|
+
points: UsageSeriesPointView[];
|
|
63
|
+
unreadable: number;
|
|
64
|
+
}
|
|
65
|
+
export type UsageBreakdownRowView = UsageTotalsView & {
|
|
66
|
+
key: string;
|
|
67
|
+
};
|
|
68
|
+
export interface UsageBreakdownView extends UsageWindowView {
|
|
69
|
+
rows: UsageBreakdownRowView[];
|
|
70
|
+
unreadable: number;
|
|
71
|
+
}
|
|
72
|
+
export type UsageUnavailableWhy = 'capability' | 'feature' | 'route';
|
|
73
|
+
export type UsageReadVerdict<T> = {
|
|
74
|
+
readonly kind: 'ok';
|
|
75
|
+
readonly value: T;
|
|
76
|
+
} | {
|
|
77
|
+
readonly kind: 'unavailable';
|
|
78
|
+
readonly why: UsageUnavailableWhy;
|
|
79
|
+
} | {
|
|
80
|
+
readonly kind: 'failed';
|
|
81
|
+
readonly error: unknown;
|
|
82
|
+
};
|
|
83
|
+
export declare function classifyUsageFailure(e: unknown): UsageReadVerdict<never>;
|
|
84
|
+
export declare function projectUsageSummary(body: unknown): UsageSummaryView | undefined;
|
|
85
|
+
export declare function projectUsageSeries(body: unknown): UsageSeriesView | undefined;
|
|
86
|
+
export declare function projectUsageBreakdown(body: unknown): UsageBreakdownView | undefined;
|
|
87
|
+
export declare function readUsageSummary(client: UsageAnalyticsClientLike, opts?: UsageReadOptions): Promise<UsageReadVerdict<UsageSummaryView>>;
|
|
88
|
+
export declare function readUsageSeries(client: UsageAnalyticsClientLike, opts?: UsageSeriesReadOptions): Promise<UsageReadVerdict<UsageSeriesView>>;
|
|
89
|
+
export declare function readUsageBreakdown(client: UsageAnalyticsClientLike, opts?: UsageBreakdownReadOptions): Promise<UsageReadVerdict<UsageBreakdownView>>;
|
|
90
|
+
export interface UsageAmount {
|
|
91
|
+
readonly value: number;
|
|
92
|
+
readonly bound: UsageBound;
|
|
93
|
+
}
|
|
94
|
+
export declare function usageBoundPrefix(bound: UsageBound): '' | '≥' | '≈';
|
|
95
|
+
export interface UsageHeatmapCell {
|
|
96
|
+
readonly date: string;
|
|
97
|
+
readonly tasks: number;
|
|
98
|
+
}
|
|
99
|
+
export type UsageUnavailableCause = 'no_backend_face' | 'read_failed';
|
|
100
|
+
export type UsageModelsView = {
|
|
101
|
+
readonly state: 'available';
|
|
102
|
+
readonly rows: readonly UsageBreakdownRowView[];
|
|
103
|
+
readonly unreadable: number;
|
|
104
|
+
} | {
|
|
105
|
+
readonly state: 'unavailable';
|
|
106
|
+
readonly cause: UsageUnavailableCause;
|
|
107
|
+
readonly sentence: string;
|
|
108
|
+
};
|
|
109
|
+
export interface UsageAnalyticsReadings {
|
|
110
|
+
readonly state: 'available' | 'estimated';
|
|
111
|
+
readonly truncated: boolean;
|
|
112
|
+
readonly runs?: number;
|
|
113
|
+
readonly tokens?: UsageAmount;
|
|
114
|
+
readonly cost?: UsageAmount;
|
|
115
|
+
readonly activeDays?: number;
|
|
116
|
+
readonly peakHourUtc?: number;
|
|
117
|
+
readonly favoriteModel?: string;
|
|
118
|
+
readonly heatmap: readonly UsageHeatmapCell[] | null;
|
|
119
|
+
readonly models: UsageModelsView;
|
|
120
|
+
}
|
|
121
|
+
export interface UsageAnalyticsUnavailable {
|
|
122
|
+
readonly state: 'unavailable';
|
|
123
|
+
readonly cause: UsageUnavailableCause;
|
|
124
|
+
readonly sentence: string;
|
|
125
|
+
readonly models: Extract<UsageModelsView, {
|
|
126
|
+
state: 'unavailable';
|
|
127
|
+
}>;
|
|
128
|
+
}
|
|
129
|
+
export type UsageAnalyticsView = UsageAnalyticsReadings | UsageAnalyticsUnavailable;
|
|
130
|
+
export interface UsageAnalyticsInputs {
|
|
131
|
+
summary: UsageReadVerdict<UsageSummaryView>;
|
|
132
|
+
daySeries: UsageReadVerdict<UsageSeriesView>;
|
|
133
|
+
hourSeries: UsageReadVerdict<UsageSeriesView>;
|
|
134
|
+
modelBreakdown: UsageReadVerdict<UsageBreakdownView>;
|
|
135
|
+
}
|
|
136
|
+
export interface UsageAnalyticsWindow {
|
|
137
|
+
readonly from: number;
|
|
138
|
+
readonly to: number;
|
|
139
|
+
}
|
|
140
|
+
export type UsageRange = 'all' | '30d' | '7d';
|
|
141
|
+
export declare const USAGE_HEATMAP_MAX_DAYS = 70;
|
|
142
|
+
export declare function usageWindowOfRange(range: UsageRange, now: number): UsageAnalyticsWindow;
|
|
143
|
+
export declare function projectUsageAnalytics(inputs: UsageAnalyticsInputs, window: UsageAnalyticsWindow): UsageAnalyticsView;
|
|
144
|
+
export declare function readUsageAnalytics(client: UsageAnalyticsClientLike, window: UsageAnalyticsWindow, opts?: {
|
|
145
|
+
signal?: AbortSignal;
|
|
146
|
+
}): Promise<UsageAnalyticsView>;
|