@platless/axom-cli 0.5.9 → 0.6.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -6
- package/dist/axom-patch/cli/README.md +129 -12
- package/dist/axom-patch/cli/account-limits/generate.py +15 -12
- package/dist/axom-patch/cli/account-limits/kimi-proxy.mjs +20 -3
- package/dist/axom-patch/cli/claude-account-limits.json +9 -9
- package/dist/axom-patch/cli/claude-replay-lifecycle.json +16 -0
- package/dist/axom-patch/cli/codex-account-limits.json +11 -11
- package/dist/axom-patch/cli/codex-terminal-output.json +16 -0
- package/dist/axom-patch/cli/commandcode-account-limits.json +9 -9
- package/dist/axom-patch/cli/kimi-quota.mjs +12 -0
- package/dist/axom-patch/cli/kimi-subagents.mjs +173 -0
- package/dist/axom-patch/cli/nightly-task.md +55 -13
- package/dist/axom-patch/cli/probes/claude-replay-lifecycle.mjs +31 -0
- package/dist/axom-patch/cli/probes/codex-terminal-output.mjs +33 -0
- package/dist/axom-patch/cli/probes/kimi-subagent-subwork.mjs +82 -0
- package/dist/axom-patch/cli/probes/zcode-env-account.mjs +81 -0
- package/dist/axom-patch/cli/probes/zcode-subagent-subwork.mjs +7 -0
- package/dist/axom-patch/cli/qoder/dist/axom-acp-compat.mjs +1687 -0
- package/dist/axom-patch/cli/qoder/releases/1.1.75.json +277 -0
- package/dist/axom-patch/cli/qoder-background-terminal.md +13 -6
- package/dist/axom-patch/cli/qoder-foreground-output.md +14 -8
- package/dist/axom-patch/cli/qoder-native-acp.json +227 -0
- package/dist/axom-patch/cli/qoder-steering.md +20 -25
- package/dist/axom-patch/cli/qoder-subagent-subwork.md +17 -68
- package/dist/axom-patch/cli/runtime.json +19 -19
- package/dist/axom-patch/cli/zcode/env-account.mjs +13 -0
- package/dist/axom-patch/cli/zcode/generate-env-account.py +52 -0
- package/dist/axom-patch/cli/zcode-account-limits.json +10 -11
- package/dist/axom-patch/cli/zcode-env-account.json +58 -0
- package/dist/axom-patch/cli/zcode-models.json +9 -10
- package/dist/axom-patch/cli/zcode-subagent-subwork.json +10 -11
- package/dist/cli.js +11 -45
- package/dist/commands/auth.js +4 -1
- package/dist/commands/knowledge.js +47 -0
- package/dist/commands/update.js +126 -3
- package/dist/commands/workstation.js +101 -164
- package/dist/commands/workstationRegistrations.js +116 -0
- package/dist/credentialBroker.js +13 -2
- package/dist/credentials.js +16 -0
- package/dist/install/claude/commands.js +15 -15
- package/dist/keepers/terminal/keeper.mjs +1089 -673
- package/dist/keepers/terminal/manifest.json +4 -4
- package/dist/mcp.js +1 -1
- package/dist/native/darwin-x64/axom-quic +0 -0
- package/dist/workstation/acp/acpAgents.js +113 -102
- package/dist/workstation/acp/acpClient.js +26 -0
- package/dist/workstation/acp/builds/install/npm.js +99 -10
- package/dist/workstation/acp/initializeResponse.js +6 -1
- package/dist/workstation/acp/managedPatches.js +189 -25
- package/dist/workstation/acp/managedRuntime.js +314 -0
- package/dist/workstation/acp/outbox.js +12 -5
- package/dist/workstation/acp/patchAssets.js +40 -0
- package/dist/workstation/acp/permission.js +2 -2
- package/dist/workstation/acp/processor/checkpoint.js +26 -34
- package/dist/workstation/acp/processor/control.js +7 -80
- package/dist/workstation/acp/processor/jsonrpc.js +8 -0
- package/dist/workstation/acp/processor/runtime.js +5 -81
- package/dist/workstation/acp/processor/session.js +54 -82
- package/dist/workstation/acp/processor/state.js +7 -13
- package/dist/workstation/acp/processor/step.js +3 -20
- package/dist/workstation/acp/processor/test/fixtureLog.js +9 -16
- package/dist/workstation/acp/processor/transport/local.js +19 -3
- package/dist/workstation/acp/processor/updates.js +156 -105
- package/dist/workstation/acp/processorSession.js +20 -173
- package/dist/workstation/acp/registry/catalog.js +65 -39
- package/dist/workstation/acp/registry/launch.js +16 -1
- package/dist/workstation/acp/switching.js +0 -3
- package/dist/workstation/acp/test/fakeAgent.js +13 -0
- package/dist/workstation/acp/test/keeperWorld.js +32 -3
- package/dist/workstation/acp/test/raw/sources.js +16 -130
- package/dist/workstation/acp/test/realAdapter.js +1 -47
- package/dist/workstation/acp/test/scriptAgent.js +11 -3
- package/dist/workstation/agentFlow.js +1 -1
- package/dist/workstation/agentSessions.js +114 -166
- package/dist/workstation/channels/agent.js +9 -1
- package/dist/workstation/channels/computer.js +27 -4
- package/dist/workstation/channels/management.js +130 -15
- package/dist/workstation/channels/url.js +1 -1
- package/dist/workstation/config.js +33 -9
- package/dist/workstation/connection/encryptedChannel.js +4 -1
- package/dist/workstation/control/bindingStore.js +204 -0
- package/dist/workstation/control/commands.js +125 -0
- package/dist/workstation/control/daemonIdentity.js +143 -0
- package/dist/workstation/control/deviceCommands.js +191 -0
- package/dist/workstation/control/deviceProtocol.js +68 -0
- package/dist/workstation/control/enrollment.js +106 -0
- package/dist/workstation/control/inspect.js +71 -0
- package/dist/workstation/control/locks.js +110 -0
- package/dist/workstation/control/protocol.js +40 -0
- package/dist/workstation/control/restartGuard.js +46 -0
- package/dist/workstation/control/rootFormat.js +16 -0
- package/dist/workstation/control/runtimeClient.js +152 -0
- package/dist/workstation/control/runtimeHost.js +235 -0
- package/dist/workstation/control/serverIdentity.js +35 -0
- package/dist/workstation/control/updateTransition.js +91 -0
- package/dist/workstation/daemon.js +266 -264
- package/dist/workstation/daemonctl.js +226 -25
- package/dist/workstation/desktopControl/audio.js +99 -0
- package/dist/workstation/desktopControl/automationDevice.js +219 -0
- package/dist/workstation/desktopControl/automationJson.js +74 -0
- package/dist/workstation/desktopControl/automationLocalState.js +23 -0
- package/dist/workstation/desktopControl/automationProtocol.js +253 -0
- package/dist/workstation/desktopControl/automationSchema.generated.js +1 -0
- package/dist/workstation/desktopControl/automationSession.js +81 -0
- package/dist/workstation/desktopControl/automationTransport.js +138 -0
- package/dist/workstation/desktopControl/capabilities.js +93 -0
- package/dist/workstation/desktopControl/captureModes.js +9 -0
- package/dist/workstation/desktopControl/captureTargetLabel.js +9 -0
- package/dist/workstation/desktopControl/deviceAdmission.js +229 -0
- package/dist/workstation/desktopControl/deviceOwnership.js +130 -0
- package/dist/workstation/desktopControl/deviceSockets.js +246 -0
- package/dist/workstation/desktopControl/helperProcess.js +602 -0
- package/dist/workstation/desktopControl/hostGrant.js +65 -0
- package/dist/workstation/desktopControl/lobby.js +131 -0
- package/dist/workstation/desktopControl/macProvider.js +156 -0
- package/dist/workstation/desktopControl/media.js +331 -0
- package/dist/workstation/desktopControl/nativeDeviceAdmission.js +207 -0
- package/dist/workstation/desktopControl/nativeProvider.js +1044 -0
- package/dist/workstation/desktopControl/networkEvidence.js +43 -0
- package/dist/workstation/desktopControl/overview.js +58 -0
- package/dist/workstation/desktopControl/ownershipProtocol.js +31 -0
- package/dist/workstation/desktopControl/protocol.js +311 -0
- package/dist/workstation/desktopControl/provider.js +1 -0
- package/dist/workstation/desktopControl/quicMedia.js +240 -0
- package/dist/workstation/desktopControl/rateController.js +226 -0
- package/dist/workstation/desktopControl/supervisor.js +1774 -0
- package/dist/workstation/desktopControl/transport.js +27 -0
- package/dist/workstation/desktopControl/wallpaper.js +98 -0
- package/dist/workstation/exec/policy.js +5 -0
- package/dist/workstation/files/client.js +10 -1
- package/dist/workstation/files/credentials.js +142 -0
- package/dist/workstation/files/host.js +9 -2
- package/dist/workstation/files/text.js +42 -8
- package/dist/workstation/journal.js +5 -2
- package/dist/workstation/keepers/acp/client.js +38 -2
- package/dist/workstation/keepers/kit/buildVersion.js +35 -11
- package/dist/workstation/keepers/kit/bundle.js +21 -17
- package/dist/workstation/keepers/kit/client.js +2 -2
- package/dist/workstation/keepers/kit/launcher.js +123 -7
- package/dist/workstation/keepers/kit/paths.js +2 -1
- package/dist/workstation/keepers/legacy.js +16 -2
- package/dist/workstation/keepers/policy.js +5 -34
- package/dist/workstation/keepers/terminal/client.js +115 -23
- package/dist/workstation/keepers/terminal/exec.js +6 -3
- package/dist/workstation/keepers/terminal/frames.js +73 -0
- package/dist/workstation/keepers/terminal/generations.js +5 -8
- package/dist/workstation/keepers/terminal/gridProtocol.js +16 -0
- package/dist/workstation/keepers/terminal/input.js +146 -0
- package/dist/workstation/keepers/terminal/keeper.js +22 -8
- package/dist/workstation/keepers/terminal/main.js +1 -1
- package/dist/workstation/keepers/terminal/metadata.js +138 -0
- package/dist/workstation/keepers/terminal/protocol.js +4 -28
- package/dist/workstation/keepers/terminal/pty.js +1 -330
- package/dist/workstation/keepers/terminal/screen.js +246 -0
- package/dist/workstation/keepers/terminal/sessions.js +526 -0
- package/dist/workstation/managedInstall.js +57 -0
- package/dist/workstation/oauth/deviceAuthorization.js +31 -17
- package/dist/workstation/protocol/agent.js +2 -15
- package/dist/workstation/protocol/management.js +113 -5
- package/dist/workstation/protocol/runtimeDiagnostics.js +15 -0
- package/dist/workstation/rd/artifact.js +120 -0
- package/dist/workstation/rd/control.js +117 -0
- package/dist/workstation/rd/display.js +29 -0
- package/dist/workstation/rd/host.js +213 -0
- package/dist/workstation/rd/migrationReadiness.js +46 -0
- package/dist/workstation/rd/provider.js +256 -0
- package/dist/workstation/rd/sessions.js +391 -0
- package/dist/workstation/rd/state.js +57 -0
- package/dist/workstation/rd/update.js +168 -0
- package/dist/workstation/rd/upkeep.js +80 -0
- package/dist/workstation/register.js +27 -37
- package/dist/workstation/registrations/enrollment.js +250 -0
- package/dist/workstation/registrations/enrollmentPending.js +361 -0
- package/dist/workstation/registrations/migration.js +356 -0
- package/dist/workstation/registrations/model.js +34 -0
- package/dist/workstation/registrations/removal.js +222 -0
- package/dist/workstation/registrations/store.js +737 -0
- package/dist/workstation/runtime/desktopBinding.js +20 -0
- package/dist/workstation/runtime/deviceDesktop.js +193 -0
- package/dist/workstation/runtime/deviceRuntime.js +568 -0
- package/dist/workstation/runtime/deviceServices.js +117 -0
- package/dist/workstation/runtime/events.js +20 -0
- package/dist/workstation/runtime/ownership.js +100 -0
- package/dist/workstation/runtime/registrationRuntime.js +575 -0
- package/dist/workstation/runtime/remoteDesktopAdapter.js +186 -0
- package/dist/workstation/runtime/removalActivity.js +184 -0
- package/dist/workstation/service/installer.js +197 -14
- package/dist/workstation/service/launchd.js +2 -0
- package/dist/workstation/service/systemd.js +1 -0
- package/dist/workstation/storageMetrics.js +118 -0
- package/dist/workstation/systemMetrics.js +47 -92
- package/dist/workstation/toolchain.js +94 -0
- package/dist/workstation/tools/browser.js +28 -4
- package/dist/workstation/tools/client.js +8 -27
- package/dist/workstation/tools/info.js +6 -13
- package/dist/workstation/tools/terminalRouter.js +17 -172
- package/dist/workstation/tools/validation.js +55 -1
- package/dist/workstation/update/archiveEvidence.js +206 -0
- package/dist/workstation/update/artifact.js +2 -1
- package/dist/workstation/update/coordinator.js +34 -13
- package/dist/workstation/update/deviceCompatibility.js +119 -0
- package/dist/workstation/update/deviceCoordinator.js +369 -0
- package/dist/workstation/update/deviceHealth.js +104 -0
- package/dist/workstation/update/deviceHealthProtocol.js +26 -0
- package/dist/workstation/update/deviceRecoveryLifecycle.js +46 -0
- package/dist/workstation/update/deviceRollback.js +78 -0
- package/dist/workstation/update/globalInstall.js +186 -0
- package/dist/workstation/update/legacyBridge.js +414 -0
- package/dist/workstation/update/legacyOwner.js +39 -0
- package/dist/workstation/update/npmInstaller.js +51 -25
- package/dist/workstation/update/privateDurability.js +61 -0
- package/dist/workstation/update/rdRollback.js +145 -0
- package/dist/workstation/update/recoveryPlan.js +124 -0
- package/dist/workstation/update/runUpdate.js +10 -3
- package/dist/workstation/update/taskRegistry.js +161 -3
- package/dist/workstation/update/watchdog.js +29806 -333
- package/dist/workstation/update/watchdogProcess.js +72 -0
- package/package.json +11 -7
- package/skills/axom/SKILL.md +11 -11
- package/skills/axom-definition/SKILL.md +3 -3
- package/skills/axom-platform/SKILL.md +3 -3
- package/dist/axom-patch/cli/probes/qoder-steering.mjs +0 -89
- package/dist/axom-patch/cli/probes/qoder-subagent-origin.mjs +0 -61
- package/dist/axom-patch/cli/qoder-steering.json +0 -52
- package/dist/axom-patch/cli/qoder-subagent-origin.json +0 -73
- package/dist/commands/guide.js +0 -38
- package/dist/runtime-deps/qoder-sdk/package-lock.json +0 -1189
- package/dist/runtime-deps/qoder-sdk/package.json +0 -8
- package/dist/workstation/acp/delegationMcp.js +0 -24
- package/dist/workstation/acp/processor/sideChannel.js +0 -80
- package/dist/workstation/acp/qoderStartup.js +0 -45
- package/dist/workstation/acp/test/raw/qoderCaptures.js +0 -125
- package/dist/workstation/qoderAdapter/backgroundProcess.js +0 -118
- package/dist/workstation/qoderAdapter/backgroundTerminal.js +0 -193
- package/dist/workstation/qoderAdapter/backgroundTerminalFold.js +0 -372
- package/dist/workstation/qoderAdapter/callbackContext.js +0 -76
- package/dist/workstation/qoderAdapter/completedContinuation.js +0 -139
- package/dist/workstation/qoderAdapter/contract.js +0 -78
- package/dist/workstation/qoderAdapter/foregroundOutput.js +0 -36
- package/dist/workstation/qoderAdapter/history.js +0 -85
- package/dist/workstation/qoderAdapter/identityIndex.js +0 -191
- package/dist/workstation/qoderAdapter/inputQueue.js +0 -42
- package/dist/workstation/qoderAdapter/main.js +0 -95
- package/dist/workstation/qoderAdapter/mapper.js +0 -117
- package/dist/workstation/qoderAdapter/observerPlugin.js +0 -245
- package/dist/workstation/qoderAdapter/observerReceiver.js +0 -187
- package/dist/workstation/qoderAdapter/permissions.js +0 -61
- package/dist/workstation/qoderAdapter/profile.js +0 -93
- package/dist/workstation/qoderAdapter/sdkDriver.js +0 -48
- package/dist/workstation/qoderAdapter/sdkRuntime.js +0 -93
- package/dist/workstation/qoderAdapter/sdkRuntimeInstall.js +0 -145
- package/dist/workstation/qoderAdapter/session.js +0 -319
- package/dist/workstation/qoderAdapter/subagentMeta.js +0 -28
- package/dist/workstation/qoderAdapter/subwork.js +0 -85
- package/dist/workstation/qoderAdapter/taskControl.js +0 -38
- package/dist/workstation/qoderAdapter/taskLedger.js +0 -163
- package/dist/workstation/qoderAdapter/usage.js +0 -37
- /package/dist/workstation/{qoderAdapter/types.js → desktopControl/automationPreparation.js} +0 -0
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
const object = (v) => v && typeof v === 'object' && !Array.isArray(v) ? v : {};
|
|
2
|
-
const id = (v) => typeof v === 'string' && v.length > 0 && v.length <= 256 && !/[\x00-\x1f\x7f]/.test(v);
|
|
3
|
-
export function newSubworkData() {
|
|
4
|
-
return { calls: {}, count: 0 };
|
|
5
|
-
}
|
|
6
|
-
export function supportsSubworkMeta(info) {
|
|
7
|
-
return (info?.name === 'qoder-cli' && info.version === '1.1.61') ||
|
|
8
|
-
(info?.name === 'axom-qoder-sdk' && info.version === '1.0.50');
|
|
9
|
-
}
|
|
10
|
-
function resultText(value) {
|
|
11
|
-
if (typeof value === 'string')
|
|
12
|
-
return value;
|
|
13
|
-
if (Array.isArray(value)) {
|
|
14
|
-
const texts = value.filter(v => object(v).type === 'text').map(v => object(v).text).filter(v => typeof v === 'string');
|
|
15
|
-
return texts.length ? texts.join('\n') : undefined;
|
|
16
|
-
}
|
|
17
|
-
const v = object(value);
|
|
18
|
-
if (v.kind === 'agent-result')
|
|
19
|
-
return resultText(v.content ?? v.result);
|
|
20
|
-
return undefined;
|
|
21
|
-
}
|
|
22
|
-
export class SubworkBoundary {
|
|
23
|
-
root;
|
|
24
|
-
data;
|
|
25
|
-
constructor(root, data = newSubworkData()) {
|
|
26
|
-
this.root = root;
|
|
27
|
-
this.data = data;
|
|
28
|
-
}
|
|
29
|
-
get(toolId) { return Object.hasOwn(this.data.calls, toolId) ? this.data.calls[toolId] : undefined; }
|
|
30
|
-
child(toolId) { return `qoder-agent:${this.root}:${toolId}`; }
|
|
31
|
-
map(event) {
|
|
32
|
-
if (event.acpSessionId && event.acpSessionId !== this.root)
|
|
33
|
-
return [event];
|
|
34
|
-
const p = event.payload, q = object(object(p._meta).qoder), input = object(p.rawInput);
|
|
35
|
-
const marked = q.version === 1 && ['native-acp-patch', 'sdk', 'correction'].includes(String(q.source));
|
|
36
|
-
const toolId = p.toolCallId;
|
|
37
|
-
let call = id(toolId) ? this.get(toolId) : undefined;
|
|
38
|
-
const parent = marked && q.route !== 'unknown' && id(q.parentToolUseId) ? q.parentToolUseId : undefined;
|
|
39
|
-
const events = [];
|
|
40
|
-
if (!call && marked && p.kind === 'think' && q.toolName === 'Agent' && id(toolId) &&
|
|
41
|
-
typeof input.prompt === 'string' && (input.subagent_type == null || typeof input.subagent_type === 'string') &&
|
|
42
|
-
(input.run_in_background === undefined || typeof input.run_in_background === 'boolean') &&
|
|
43
|
-
['tool_call', 'tool_call_update'].includes(event.eventName) && this.data.count < 4096) {
|
|
44
|
-
call = { child: this.child(toolId), ...(parent ? { parent: this.child(parent) } : {}),
|
|
45
|
-
background: input.run_in_background === true, ended: false, streamedText: '' };
|
|
46
|
-
Object.defineProperty(this.data.calls, toolId, { value: call, enumerable: true, writable: true, configurable: true });
|
|
47
|
-
this.data.count += 1;
|
|
48
|
-
events.push({ eventName: 'subagent_spawned', payload: { subagentSessionId: call.child,
|
|
49
|
-
name: typeof input.description === 'string' && input.description.trim() ? input.description : input.subagent_type ?? 'Agent',
|
|
50
|
-
task: input.prompt, capabilities: {} }, ...(call.parent ? { acpSessionId: call.parent } : {}) });
|
|
51
|
-
events.push({ eventName: 'user_message_chunk', payload: { content: { type: 'text', text: input.prompt } }, acpSessionId: call.child });
|
|
52
|
-
}
|
|
53
|
-
if (call && ['tool_call', 'tool_call_update'].includes(event.eventName)) {
|
|
54
|
-
if (call.ended)
|
|
55
|
-
return events;
|
|
56
|
-
const output = object(p.rawOutput);
|
|
57
|
-
const state = output.kind === 'agent-result' ? output.state : undefined;
|
|
58
|
-
const terminal = state === 'completed' ? 'completed' : ['error', 'failed'].includes(String(state)) ? 'failed' :
|
|
59
|
-
state === 'cancelled' ? 'cancelled' : ['failed', 'cancelled'].includes(String(p.status)) ? p.status :
|
|
60
|
-
!call.background && p.status === 'completed' ? 'completed' : undefined;
|
|
61
|
-
if (terminal) {
|
|
62
|
-
const text = resultText(p.rawOutput);
|
|
63
|
-
if (text !== undefined && !call.streamedText.endsWith(text))
|
|
64
|
-
events.push({ eventName: 'agent_message_chunk',
|
|
65
|
-
payload: { content: { type: 'text', text } }, acpSessionId: call.child });
|
|
66
|
-
events.push({ eventName: 'subagent_state_update', payload: { subagentSessionId: call.child, state: terminal },
|
|
67
|
-
...(call.parent ? { acpSessionId: call.parent } : {}) });
|
|
68
|
-
call.ended = true;
|
|
69
|
-
// Read only by the check above, once: an ended call keeps no stream (checkpointed state).
|
|
70
|
-
call.streamedText = '';
|
|
71
|
-
}
|
|
72
|
-
// The Agent invocation becomes a dispatch/result in subwork. Keeping the vendor tool here
|
|
73
|
-
// would also create the old delegation card for the very same task.
|
|
74
|
-
return events;
|
|
75
|
-
}
|
|
76
|
-
if (parent) {
|
|
77
|
-
const owner = this.get(parent), content = object(p.content);
|
|
78
|
-
if (owner && !owner.ended && event.eventName === 'agent_message_chunk' && content.type === 'text' && typeof content.text === 'string') {
|
|
79
|
-
owner.streamedText += content.text;
|
|
80
|
-
}
|
|
81
|
-
return [{ ...event, acpSessionId: this.child(parent) }];
|
|
82
|
-
}
|
|
83
|
-
return [event];
|
|
84
|
-
}
|
|
85
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { capabilitiesFor } from './profile.js';
|
|
2
|
-
const validId = (value) => value.length > 0 && Buffer.byteLength(value, 'utf8') <= 256 &&
|
|
3
|
-
!/[\x00-\x1f\x7f]/.test(value);
|
|
4
|
-
export class TaskControl {
|
|
5
|
-
ledger;
|
|
6
|
-
profile;
|
|
7
|
-
query;
|
|
8
|
-
certifications;
|
|
9
|
-
binding;
|
|
10
|
-
requests = new Map();
|
|
11
|
-
constructor(ledger, profile, query, certifications, binding) {
|
|
12
|
-
this.ledger = ledger;
|
|
13
|
-
this.profile = profile;
|
|
14
|
-
this.query = query;
|
|
15
|
-
this.certifications = certifications;
|
|
16
|
-
this.binding = binding;
|
|
17
|
-
}
|
|
18
|
-
async stop(request) {
|
|
19
|
-
if (![request.sessionId, request.taskId, request.requestId].every(validId))
|
|
20
|
-
throw new Error('Invalid task stop identity');
|
|
21
|
-
const previous = this.requests.get(request.requestId);
|
|
22
|
-
if (previous) {
|
|
23
|
-
if (previous.sessionId !== request.sessionId || previous.taskId !== request.taskId)
|
|
24
|
-
throw new Error('Task stop request identity conflict');
|
|
25
|
-
return previous.receipt;
|
|
26
|
-
}
|
|
27
|
-
const profile = this.profile(), task = this.ledger.get(request.taskId);
|
|
28
|
-
if (!profile || !task || request.sessionId !== profile.rootSessionId ||
|
|
29
|
-
!task.origin.agentId || !task.origin.launchingToolUseId || task.taskType !== 'local_agent' ||
|
|
30
|
-
task.background !== true || !capabilitiesFor(profile, task, this.certifications, this.binding).stopActiveRun)
|
|
31
|
-
throw new Error('Task stop unavailable');
|
|
32
|
-
if (this.requests.size >= 4096)
|
|
33
|
-
throw new Error('Task stop receipt capacity exceeded');
|
|
34
|
-
const receipt = this.query.stopTask(request.taskId).then(() => ({ requestId: request.requestId, state: 'accepted' }), () => ({ requestId: request.requestId, state: 'unknown' }));
|
|
35
|
-
this.requests.set(request.requestId, { sessionId: request.sessionId, taskId: request.taskId, receipt });
|
|
36
|
-
return receipt;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
const identifier = (value) => typeof value === 'string' && value.length > 0 &&
|
|
2
|
-
Buffer.byteLength(value, 'utf8') <= 256 && !/[\x00-\x1f\x7f]/.test(value);
|
|
3
|
-
const terminal = (state) => state === 'completed' || state === 'failed' || state === 'stopped';
|
|
4
|
-
const defaultMaxTasks = 4096;
|
|
5
|
-
const sameTask = (a, b) => a.state === b.state && a.live === b.live && a.stale === b.stale && a.taskType === b.taskType &&
|
|
6
|
-
a.background === b.background && JSON.stringify(a.origin) === JSON.stringify(b.origin);
|
|
7
|
-
export class TaskLedger {
|
|
8
|
-
rootSessionId;
|
|
9
|
-
runtimeGeneration;
|
|
10
|
-
maxTasks;
|
|
11
|
-
tasks = new Map();
|
|
12
|
-
seen = new Set();
|
|
13
|
-
actors = new Map();
|
|
14
|
-
launchTasks = new Map();
|
|
15
|
-
conflicts = new Set();
|
|
16
|
-
notified = new Set();
|
|
17
|
-
failed = false;
|
|
18
|
-
constructor(rootSessionId, runtimeGeneration, maxTasks = defaultMaxTasks) {
|
|
19
|
-
this.rootSessionId = rootSessionId;
|
|
20
|
-
this.runtimeGeneration = runtimeGeneration;
|
|
21
|
-
this.maxTasks = maxTasks;
|
|
22
|
-
if (!identifier(rootSessionId) || !identifier(runtimeGeneration))
|
|
23
|
-
throw new Error('Invalid task ledger binding');
|
|
24
|
-
if (!Number.isInteger(maxTasks) || maxTasks < 1 || maxTasks > defaultMaxTasks)
|
|
25
|
-
throw new Error('Invalid task ledger capacity');
|
|
26
|
-
}
|
|
27
|
-
get(taskId) {
|
|
28
|
-
const task = this.tasks.get(taskId);
|
|
29
|
-
return task && { ...task, origin: { ...task.origin } };
|
|
30
|
-
}
|
|
31
|
-
all() { return [...this.tasks.keys()].map((id) => this.get(id)); }
|
|
32
|
-
get launchObservationCount() { return this.actors.size; }
|
|
33
|
-
get degraded() { return this.failed; }
|
|
34
|
-
markStale() {
|
|
35
|
-
for (const [id, task] of this.tasks)
|
|
36
|
-
this.tasks.set(id, { ...task, live: false, stale: true });
|
|
37
|
-
return this.all();
|
|
38
|
-
}
|
|
39
|
-
degrade() {
|
|
40
|
-
this.failed = true;
|
|
41
|
-
return this.markStale();
|
|
42
|
-
}
|
|
43
|
-
observeLaunch(toolUseId, agentId) {
|
|
44
|
-
if (this.failed || !identifier(toolUseId) || !identifier(agentId))
|
|
45
|
-
return [];
|
|
46
|
-
const prior = this.actors.get(toolUseId);
|
|
47
|
-
if (prior !== undefined && prior !== agentId)
|
|
48
|
-
this.actors.set(toolUseId, null);
|
|
49
|
-
else if (prior === undefined && this.actors.size < this.maxTasks)
|
|
50
|
-
this.actors.set(toolUseId, agentId);
|
|
51
|
-
const changed = [];
|
|
52
|
-
for (const [id, task] of this.tasks) {
|
|
53
|
-
if (task.origin.launchingToolUseId !== toolUseId)
|
|
54
|
-
continue;
|
|
55
|
-
const actor = this.actors.get(toolUseId);
|
|
56
|
-
const next = { ...task, origin: { ...task.origin,
|
|
57
|
-
agentId: this.conflicts.has(id) ? undefined : actor ?? undefined },
|
|
58
|
-
stale: actor === null || this.conflicts.has(id) || task.stale };
|
|
59
|
-
this.tasks.set(id, next);
|
|
60
|
-
changed.push(next);
|
|
61
|
-
}
|
|
62
|
-
return changed;
|
|
63
|
-
}
|
|
64
|
-
ensure(taskId) {
|
|
65
|
-
if (!identifier(taskId))
|
|
66
|
-
return undefined;
|
|
67
|
-
const existing = this.tasks.get(taskId);
|
|
68
|
-
if (existing)
|
|
69
|
-
return existing;
|
|
70
|
-
if (this.tasks.size >= this.maxTasks) {
|
|
71
|
-
this.degrade();
|
|
72
|
-
return undefined;
|
|
73
|
-
}
|
|
74
|
-
const task = { origin: { rootSessionId: this.rootSessionId, runtimeGeneration: this.runtimeGeneration,
|
|
75
|
-
taskId }, state: 'unknown', live: false, stale: false };
|
|
76
|
-
this.tasks.set(taskId, task);
|
|
77
|
-
return task;
|
|
78
|
-
}
|
|
79
|
-
apply(message) {
|
|
80
|
-
if (this.failed || message.type !== 'system' || message.session_id !== this.rootSessionId ||
|
|
81
|
-
!identifier(message.uuid) || this.seen.has(message.uuid))
|
|
82
|
-
return [];
|
|
83
|
-
if (this.seen.size >= this.maxTasks * 4)
|
|
84
|
-
return this.degrade();
|
|
85
|
-
if (message.subtype === 'background_tasks_changed' && message.tasks.length > this.maxTasks)
|
|
86
|
-
return this.degrade();
|
|
87
|
-
if (message.subtype === 'background_tasks_changed') {
|
|
88
|
-
const added = new Set();
|
|
89
|
-
for (const entry of message.tasks) {
|
|
90
|
-
if (identifier(entry.task_id) && !this.tasks.has(entry.task_id))
|
|
91
|
-
added.add(entry.task_id);
|
|
92
|
-
if (this.tasks.size + added.size > this.maxTasks)
|
|
93
|
-
return this.degrade();
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
const previous = new Map(this.tasks);
|
|
97
|
-
this.seen.add(message.uuid);
|
|
98
|
-
if (message.subtype === 'background_tasks_changed') {
|
|
99
|
-
const current = new Map(message.tasks.filter((entry) => identifier(entry.task_id))
|
|
100
|
-
.map((entry) => [entry.task_id, entry]));
|
|
101
|
-
for (const [id, task] of this.tasks) {
|
|
102
|
-
if (!terminal(task.state) && task.background) {
|
|
103
|
-
const next = { ...task, live: current.has(id),
|
|
104
|
-
stale: current.has(id) ? this.conflicts.has(id) : task.stale };
|
|
105
|
-
if (!sameTask(task, next))
|
|
106
|
-
this.tasks.set(id, next);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
for (const [id, entry] of current) {
|
|
110
|
-
const task = this.ensure(id);
|
|
111
|
-
if (task && !terminal(task.state)) {
|
|
112
|
-
const next = { ...task, state: 'running', live: true,
|
|
113
|
-
stale: this.conflicts.has(id), taskType: entry.task_type, background: true };
|
|
114
|
-
if (!sameTask(task, next))
|
|
115
|
-
this.tasks.set(id, next);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
else if (message.subtype === 'task_started' || message.subtype === 'task_progress') {
|
|
120
|
-
const task = this.ensure(message.task_id);
|
|
121
|
-
if (task && !terminal(task.state)) {
|
|
122
|
-
const toolId = identifier(message.tool_use_id) ? message.tool_use_id : task.origin.launchingToolUseId;
|
|
123
|
-
if (toolId && !this.launchTasks.has(toolId) && this.launchTasks.size < this.maxTasks)
|
|
124
|
-
this.launchTasks.set(toolId, message.task_id);
|
|
125
|
-
else if (toolId && this.launchTasks.get(toolId) !== message.task_id) {
|
|
126
|
-
this.conflicts.add(message.task_id);
|
|
127
|
-
const other = this.launchTasks.get(toolId);
|
|
128
|
-
if (other) {
|
|
129
|
-
this.conflicts.add(other);
|
|
130
|
-
const previous = this.tasks.get(other);
|
|
131
|
-
if (previous)
|
|
132
|
-
this.tasks.set(other, { ...previous, stale: true,
|
|
133
|
-
origin: { ...previous.origin, agentId: undefined } });
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
const actor = toolId && this.actors.get(toolId);
|
|
137
|
-
this.tasks.set(message.task_id, { ...task, state: 'running', stale: this.conflicts.has(message.task_id),
|
|
138
|
-
taskType: 'task_type' in message ? message.task_type : task.taskType,
|
|
139
|
-
origin: { ...task.origin, launchingToolUseId: toolId,
|
|
140
|
-
agentId: this.conflicts.has(message.task_id) ? undefined : actor ?? task.origin.agentId } });
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
else if (message.subtype === 'task_updated') {
|
|
144
|
-
const task = this.ensure(message.task_id);
|
|
145
|
-
if (task && !terminal(task.state)) {
|
|
146
|
-
const status = message.patch.status;
|
|
147
|
-
const state = status === 'killed' ? 'stopped' : status ?? task.state;
|
|
148
|
-
this.tasks.set(message.task_id, { ...task, state, live: terminal(state) ? false : task.live,
|
|
149
|
-
stale: this.conflicts.has(message.task_id), background: message.patch.is_backgrounded ?? task.background });
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
else if (message.subtype === 'task_notification') {
|
|
153
|
-
const task = this.ensure(message.task_id);
|
|
154
|
-
if (task && (!this.notified.has(message.task_id) ||
|
|
155
|
-
(task.state === 'stopped' && message.status === 'completed'))) {
|
|
156
|
-
this.notified.add(message.task_id);
|
|
157
|
-
this.tasks.set(message.task_id, { ...task, state: message.status,
|
|
158
|
-
live: false, stale: this.conflicts.has(message.task_id) });
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
return [...this.tasks].filter(([id, task]) => task !== previous.get(id)).map(([id]) => this.get(id));
|
|
162
|
-
}
|
|
163
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export const QODER_CREDITS_LABEL = 'Qoder Credits(厂商报告)';
|
|
2
|
-
const validCredits = (value) => typeof value === 'number' &&
|
|
3
|
-
Number.isFinite(value) && value >= 0;
|
|
4
|
-
/** Qoder's report is cumulative. A missing/invalid report never erases a prior valid value. */
|
|
5
|
-
export function applyCredits(previous, reported) {
|
|
6
|
-
if (validCredits(reported))
|
|
7
|
-
return reported;
|
|
8
|
-
return validCredits(previous) ? previous : undefined;
|
|
9
|
-
}
|
|
10
|
-
function reportedCredits(value) {
|
|
11
|
-
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
12
|
-
return undefined;
|
|
13
|
-
const input = value;
|
|
14
|
-
for (const key of ['total_credits', 'totalCredits', 'credits'])
|
|
15
|
-
if (validCredits(input[key]))
|
|
16
|
-
return input[key];
|
|
17
|
-
return undefined;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Keeps vendor credits separate from ACP token/USD counters. Qoder's SDK does not
|
|
21
|
-
* provide equivalent token or USD values, so zero placeholders are intentionally omitted.
|
|
22
|
-
*/
|
|
23
|
-
export function normalizeQoderUsage(value, previousCredits) {
|
|
24
|
-
const input = value && typeof value === 'object' && !Array.isArray(value)
|
|
25
|
-
? value : {};
|
|
26
|
-
const scope = input.cumulativeScope === 'unknown' ? 'unknown' : 'session';
|
|
27
|
-
const reported = reportedCredits(value);
|
|
28
|
-
if (scope === 'unknown') {
|
|
29
|
-
return { credits: undefined, creditsLabel: QODER_CREDITS_LABEL, creditsScope: scope,
|
|
30
|
-
inputTokens: undefined, outputTokens: undefined, costUsd: undefined,
|
|
31
|
-
...(validCredits(previousCredits) ? { previousCredits } : {}) };
|
|
32
|
-
}
|
|
33
|
-
const credits = applyCredits(previousCredits, reported);
|
|
34
|
-
return { credits, creditsLabel: QODER_CREDITS_LABEL, creditsScope: scope,
|
|
35
|
-
inputTokens: undefined, outputTokens: undefined, costUsd: undefined,
|
|
36
|
-
...(validCredits(previousCredits) ? { previousCredits } : {}) };
|
|
37
|
-
}
|
|
File without changes
|