@skrr-ai/cli 0.1.231 → 0.1.232
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 +22 -0
- package/bin/dev.cjs +4 -0
- package/dist/base-command.d.ts +0 -10
- package/dist/base-command.js +10 -39
- package/dist/commands/agent/message/context.d.ts +2 -0
- package/dist/commands/agent/message/context.js +18 -3
- package/dist/commands/agent/message/list.d.ts +22 -0
- package/dist/commands/agent/message/list.js +66 -0
- package/dist/commands/agent/message/send.d.ts +1 -1
- package/dist/commands/agent/message/send.js +1 -3
- package/dist/commands/agent/message/show.d.ts +14 -0
- package/dist/commands/agent/message/show.js +39 -0
- package/dist/commands/agents/chat.d.ts +2 -0
- package/dist/commands/agents/chat.js +20 -4
- package/dist/commands/agents/eval/show.d.ts +1 -0
- package/dist/commands/agents/eval/show.js +19 -0
- package/dist/commands/agents/intuitions/generate.js +1 -1
- package/dist/commands/agents/intuitions/list.js +1 -1
- package/dist/commands/code/acp.js +1 -1
- package/dist/commands/code/handover.d.ts +3 -3
- package/dist/commands/code/handover.js +12 -12
- package/dist/commands/code/index.d.ts +3 -8
- package/dist/commands/code/index.js +15 -21
- package/dist/commands/code/jobs/show.js +1 -0
- package/dist/commands/code/run.js +1 -1
- package/dist/commands/goals/plan-now.d.ts +5 -3
- package/dist/commands/goals/plan-now.js +21 -16
- package/dist/commands/runs/events.d.ts +14 -0
- package/dist/commands/runs/events.js +59 -0
- package/dist/commands/runs/list.d.ts +21 -0
- package/dist/commands/runs/list.js +87 -0
- package/dist/commands/runs/show.d.ts +13 -0
- package/dist/commands/runs/show.js +63 -0
- package/dist/commands/runs/stop.d.ts +14 -0
- package/dist/commands/runs/stop.js +78 -0
- package/dist/commands/runs/transcript.d.ts +17 -0
- package/dist/commands/runs/transcript.js +93 -0
- package/dist/commands/tasks/runs.js +7 -0
- package/dist/commands/tasks/start-receipt.js +8 -8
- package/dist/commands/tasks/start.js +12 -1
- package/dist/generated/agent-guides.json +226 -5
- package/dist/lib/agent-chat-queue.d.ts +2 -1
- package/dist/lib/agent-chat-queue.js +26 -21
- package/dist/lib/agent-runs.d.ts +41 -0
- package/dist/lib/agent-runs.js +177 -0
- package/dist/lib/agentic-stream.d.ts +1 -1
- package/dist/lib/agentic-stream.js +2 -2
- package/dist/lib/api-fetch.d.ts +2 -2
- package/dist/lib/api-fetch.js +5 -4
- package/dist/lib/code-handover.d.ts +2 -3
- package/dist/lib/code-handover.js +4 -6
- package/dist/lib/communication-history.d.ts +27 -0
- package/dist/lib/communication-history.js +45 -0
- package/dist/lib/execution-history.d.ts +31 -0
- package/dist/lib/execution-history.js +7 -0
- package/dist/lib/first-party-harness-broker.d.ts +1 -1
- package/dist/lib/first-party-harness-broker.js +3 -5
- package/dist/lib/inbound-messages.d.ts +1 -0
- package/dist/lib/inbound-messages.js +3 -0
- package/dist/lib/intuition-look.js +20 -4
- package/dist/lib/memory-history-session.d.ts +8 -4
- package/dist/lib/memory-history-session.js +30 -23
- package/dist/lib/task-agent-run.d.ts +4 -0
- package/dist/lib/task-agent-run.js +15 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/daemonWire.d.ts +9 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/daemonWire.js +35 -2
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/toolApprovalSignature.d.ts +62 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/toolApprovalSignature.js +56 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/daemonWire.d.ts +9 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/daemonWire.js +29 -2
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/toolApprovalSignature.d.ts +62 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/toolApprovalSignature.js +51 -0
- package/dist/node_modules/@skrr-ai/data-provider/index.js +10997 -10987
- package/oclif.manifest.json +1065 -1648
- package/package.json +5 -2
|
@@ -22,6 +22,7 @@ exports.renderQueue = renderQueue;
|
|
|
22
22
|
*/
|
|
23
23
|
const node_crypto_1 = require("node:crypto");
|
|
24
24
|
const data_provider_1 = require("@skrr-ai/data-provider");
|
|
25
|
+
const agent_runs_1 = require("./agent-runs");
|
|
25
26
|
const agent_chat_start_1 = require("./agent-chat-start");
|
|
26
27
|
const http_error_1 = require("./http-error");
|
|
27
28
|
const input_queue_1 = require("./input-queue");
|
|
@@ -107,32 +108,36 @@ async function waitForQueuedTurn(turn, { timeoutMs, onPaused, onPosition, deps =
|
|
|
107
108
|
lastPosition = index;
|
|
108
109
|
}
|
|
109
110
|
else {
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const
|
|
111
|
+
const current = snapshot.turn;
|
|
112
|
+
const sameSession = current?.sessionId === turn.sessionId;
|
|
113
|
+
const active = sameSession
|
|
114
|
+
? { sessionId: turn.sessionId, responseMessageId: current?.responseMessageId ?? turn.responseMessageId }
|
|
115
|
+
: current?.userMessageId === turn.clientInputId && current.responseMessageId
|
|
116
|
+
? { sessionId: current.sessionId, responseMessageId: current.responseMessageId }
|
|
117
|
+
: null;
|
|
118
|
+
const currentRunId = (0, agent_runs_1.canonicalRunId)(current?.runId);
|
|
119
|
+
if (active && currentRunId)
|
|
120
|
+
return { outcome: 'sent', turn: { ...active, runId: currentRunId } };
|
|
121
|
+
// The live queue can show an accepted session before it projects that
|
|
122
|
+
// Run ID. The admitted user message carries its exact turn coordinates.
|
|
123
|
+
const reading = messages(turn.conversationId);
|
|
124
|
+
const rows = active ? await reading.catch(() => undefined) : await reading;
|
|
123
125
|
if (Array.isArray(rows)) {
|
|
124
|
-
if (rows.some((m) => m.messageId === turn.responseMessageId)) {
|
|
125
|
-
return { outcome: 'sent' };
|
|
126
|
-
}
|
|
127
|
-
// A replay may be waiting under IDs reserved by an earlier invocation.
|
|
128
|
-
// The admitted input names its own session and reply once it starts.
|
|
129
126
|
const input = rows.find((m) => m.messageId === turn.clientInputId && m.isCreatedByUser === true);
|
|
130
127
|
const metadata = input?.metadata;
|
|
131
|
-
const { sessionId, responseMessageId } = metadata?.agentic ?? {};
|
|
132
|
-
if (typeof sessionId === 'string' && typeof responseMessageId === 'string'
|
|
133
|
-
|
|
128
|
+
const { sessionId, responseMessageId, canonicalRunId: acceptedRunId } = metadata?.agentic ?? {};
|
|
129
|
+
if (typeof sessionId === 'string' && typeof responseMessageId === 'string' &&
|
|
130
|
+
(!active || (sessionId === active.sessionId && responseMessageId === active.responseMessageId))) {
|
|
131
|
+
const runId = (0, agent_runs_1.canonicalRunId)(acceptedRunId);
|
|
132
|
+
if (!active || runId) {
|
|
133
|
+
return { outcome: 'sent', turn: { sessionId, responseMessageId, ...(runId ? { runId } : {}) } };
|
|
134
|
+
}
|
|
134
135
|
}
|
|
136
|
+
if (!active && rows.some((m) => m.messageId === turn.responseMessageId))
|
|
137
|
+
return { outcome: 'sent' };
|
|
135
138
|
}
|
|
139
|
+
if (active)
|
|
140
|
+
return { outcome: 'sent', ...(!sameSession ? { turn: active } : {}) };
|
|
136
141
|
goneFor += 1;
|
|
137
142
|
if (goneFor >= SETTLE_POLLS)
|
|
138
143
|
return { outcome: 'not_sent' };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { AgentRunEventPage, AgentRunHistoryPage, AgentRunStopReceipt, AgentRunSummary, AgentRunTranscriptPage } from '@skrr-ai/data-provider';
|
|
2
|
+
export declare function canonicalRunId(value: unknown): string | undefined;
|
|
3
|
+
export declare const runIdArgument: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
4
|
+
export declare function exactAttemptId(input: string): string;
|
|
5
|
+
export declare const attemptIdFlag: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
6
|
+
export declare function listAgentRuns({ agentId, conversationId, source, from, to, status, cursor, limit, }: {
|
|
7
|
+
agentId?: string;
|
|
8
|
+
conversationId?: string;
|
|
9
|
+
source?: string;
|
|
10
|
+
from?: string;
|
|
11
|
+
to?: string;
|
|
12
|
+
status?: string;
|
|
13
|
+
cursor?: string;
|
|
14
|
+
limit?: number;
|
|
15
|
+
}): Promise<AgentRunHistoryPage>;
|
|
16
|
+
export declare function readAgentRun(runId: string): Promise<AgentRunSummary & {
|
|
17
|
+
snapshot?: AgentRunEventPage['snapshot'];
|
|
18
|
+
}>;
|
|
19
|
+
export declare function readAgentRunEvents(runId: string, options?: {
|
|
20
|
+
cursor?: string;
|
|
21
|
+
limit?: number;
|
|
22
|
+
}): Promise<AgentRunEventPage>;
|
|
23
|
+
export declare function readAgentRunTranscript(runId: string, { attempt, offset, limit }: {
|
|
24
|
+
attempt: string;
|
|
25
|
+
offset?: number;
|
|
26
|
+
limit?: number;
|
|
27
|
+
}): Promise<AgentRunTranscriptPage>;
|
|
28
|
+
type StopRunResult = {
|
|
29
|
+
kind: 'receipt';
|
|
30
|
+
receipt: AgentRunStopReceipt;
|
|
31
|
+
} | {
|
|
32
|
+
kind: 'already-ended';
|
|
33
|
+
runId: string;
|
|
34
|
+
status: string;
|
|
35
|
+
};
|
|
36
|
+
export declare class RunStopUnconfirmedError extends Error {
|
|
37
|
+
readonly expectedAttemptId: string | null;
|
|
38
|
+
constructor(expectedAttemptId: string | null, cause?: unknown);
|
|
39
|
+
}
|
|
40
|
+
export declare function stopAgentRun(runId: string, expectedAttemptId?: string | null): Promise<StopRunResult>;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RunStopUnconfirmedError = exports.attemptIdFlag = exports.runIdArgument = void 0;
|
|
4
|
+
exports.canonicalRunId = canonicalRunId;
|
|
5
|
+
exports.exactAttemptId = exactAttemptId;
|
|
6
|
+
exports.listAgentRuns = listAgentRuns;
|
|
7
|
+
exports.readAgentRun = readAgentRun;
|
|
8
|
+
exports.readAgentRunEvents = readAgentRunEvents;
|
|
9
|
+
exports.readAgentRunTranscript = readAgentRunTranscript;
|
|
10
|
+
exports.stopAgentRun = stopAgentRun;
|
|
11
|
+
const core_1 = require("@oclif/core");
|
|
12
|
+
const api_fetch_1 = require("./api-fetch");
|
|
13
|
+
const http_error_1 = require("./http-error");
|
|
14
|
+
const search_display_1 = require("./search-display");
|
|
15
|
+
const write_outcome_1 = require("./write-outcome");
|
|
16
|
+
const workspace_header_1 = require("./workspace-header");
|
|
17
|
+
const RUN_ID = /^ar_[A-Za-z0-9_-]{43}$/;
|
|
18
|
+
const ATTEMPT_ID = /^aa_[A-Za-z0-9_-]{43}$/;
|
|
19
|
+
const STOPPABLE = new Set(['queued', 'active', 'reconciling', 'stopping']);
|
|
20
|
+
const TERMINAL = new Set(['succeeded', 'failed', 'cancelled', 'expired']);
|
|
21
|
+
const RUNS_PATH = '/api/agent-runs';
|
|
22
|
+
function canonicalRunId(value) {
|
|
23
|
+
return typeof value === 'string' && RUN_ID.test(value) ? value : undefined;
|
|
24
|
+
}
|
|
25
|
+
exports.runIdArgument = core_1.Args.string({
|
|
26
|
+
description: 'Canonical Agent Run ID',
|
|
27
|
+
required: true,
|
|
28
|
+
ignoreStdin: true,
|
|
29
|
+
parse: async (input) => {
|
|
30
|
+
const id = canonicalRunId(input);
|
|
31
|
+
if (!id)
|
|
32
|
+
throw new Error('Expected a canonical Run ID beginning with ar_.');
|
|
33
|
+
return id;
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
function exactAttemptId(input) {
|
|
37
|
+
if (!ATTEMPT_ID.test(input))
|
|
38
|
+
throw new Error('Expected a canonical Attempt ID beginning with aa_.');
|
|
39
|
+
return input;
|
|
40
|
+
}
|
|
41
|
+
exports.attemptIdFlag = core_1.Flags.string({
|
|
42
|
+
description: 'Canonical Agent Run Attempt ID',
|
|
43
|
+
required: true,
|
|
44
|
+
parse: async (input) => exactAttemptId(input),
|
|
45
|
+
});
|
|
46
|
+
function path(runId) {
|
|
47
|
+
if (!canonicalRunId(runId))
|
|
48
|
+
throw new Error('Expected a canonical Run ID beginning with ar_.');
|
|
49
|
+
return `${RUNS_PATH}/${runId}`;
|
|
50
|
+
}
|
|
51
|
+
async function readRunResource(endpoint) {
|
|
52
|
+
const headers = (0, workspace_header_1.withWorkspaceHeader)({});
|
|
53
|
+
const scope = headers['X-Workspace-Id'] ? { headers } : undefined;
|
|
54
|
+
try {
|
|
55
|
+
return { value: await (0, api_fetch_1.apiFetch)(endpoint, scope), scope };
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
// A personal Run can be visible without a workspace. Try the account's
|
|
59
|
+
// default only when the product API could not find the Run in that scope.
|
|
60
|
+
if (scope || process.env.OVERSKY_AUTONOMOUS_SESSION === '1' ||
|
|
61
|
+
!(0, http_error_1.isHttpNotFound)(error) || error.code !== 'RUN_HISTORY_NOT_FOUND') {
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
const profile = await (0, api_fetch_1.apiFetch)('/api/auth/profile').catch(() => undefined);
|
|
65
|
+
const workspaceId = typeof profile?.workspaceId === 'string' ? profile.workspaceId.trim() : '';
|
|
66
|
+
if (!workspaceId)
|
|
67
|
+
throw error;
|
|
68
|
+
const defaultScope = { headers: { 'X-Workspace-Id': workspaceId } };
|
|
69
|
+
return { value: await (0, api_fetch_1.apiFetch)(endpoint, defaultScope), scope: defaultScope };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async function listAgentRuns({ agentId, conversationId, source, from, to, status, cursor, limit, }) {
|
|
73
|
+
const query = new URLSearchParams();
|
|
74
|
+
for (const [key, value] of Object.entries({ agentId, conversationId, source, from, to, status, cursor, limit })) {
|
|
75
|
+
if (value !== undefined)
|
|
76
|
+
query.set(key, String(value));
|
|
77
|
+
}
|
|
78
|
+
const { value } = await readRunResource(`${RUNS_PATH}?${query}`);
|
|
79
|
+
if (!Array.isArray(value?.items) ||
|
|
80
|
+
!value.items.every((row) => canonicalRunId(row?.id) && typeof row.source === 'string' &&
|
|
81
|
+
typeof row.status === 'string' && typeof row.acceptedAt === 'string' &&
|
|
82
|
+
(row.title == null || typeof row.title === 'string')) ||
|
|
83
|
+
(value.nextCursor !== null &&
|
|
84
|
+
(typeof value.nextCursor !== 'string' || !(0, search_display_1.isPrintableSearchCursor)(value.nextCursor)))) {
|
|
85
|
+
throw new Error('The server did not provide a Run History page.');
|
|
86
|
+
}
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
async function readAgentRun(runId) {
|
|
90
|
+
const { value: detail, scope } = await readRunResource(path(runId));
|
|
91
|
+
if (detail?.id !== runId)
|
|
92
|
+
throw new Error('The server returned an unexpected Run.');
|
|
93
|
+
if (!detail.eventReplay)
|
|
94
|
+
return detail;
|
|
95
|
+
const page = await (0, api_fetch_1.apiFetch)(eventsPath(runId), scope);
|
|
96
|
+
const { snapshot } = assertEventsRun(runId, page);
|
|
97
|
+
return { ...detail, ...(snapshot ? { snapshot } : {}) };
|
|
98
|
+
}
|
|
99
|
+
function eventsPath(runId, { cursor, limit } = {}) {
|
|
100
|
+
const query = new URLSearchParams();
|
|
101
|
+
if (cursor !== undefined)
|
|
102
|
+
query.set('cursor', cursor);
|
|
103
|
+
if (limit !== undefined)
|
|
104
|
+
query.set('limit', String(limit));
|
|
105
|
+
const search = query.toString();
|
|
106
|
+
return `${path(runId)}/events${search ? `?${search}` : ''}`;
|
|
107
|
+
}
|
|
108
|
+
function assertEventsRun(runId, page) {
|
|
109
|
+
if (page?.runId !== runId)
|
|
110
|
+
throw new Error('The server returned events for an unexpected Run.');
|
|
111
|
+
return page;
|
|
112
|
+
}
|
|
113
|
+
async function readAgentRunEvents(runId, options) {
|
|
114
|
+
const { value } = await readRunResource(eventsPath(runId, options));
|
|
115
|
+
return assertEventsRun(runId, value);
|
|
116
|
+
}
|
|
117
|
+
async function readAgentRunTranscript(runId, { attempt, offset, limit }) {
|
|
118
|
+
const query = new URLSearchParams({ attempt: exactAttemptId(attempt) });
|
|
119
|
+
if (offset !== undefined)
|
|
120
|
+
query.set('offset', String(offset));
|
|
121
|
+
if (limit !== undefined)
|
|
122
|
+
query.set('limit', String(limit));
|
|
123
|
+
const { value } = await readRunResource(`${path(runId)}/transcript?${query}`);
|
|
124
|
+
if (!['available', 'partial', 'unverified', 'unavailable'].includes(value?.availability)) {
|
|
125
|
+
throw new Error('The server did not provide a Run transcript page.');
|
|
126
|
+
}
|
|
127
|
+
return value;
|
|
128
|
+
}
|
|
129
|
+
class RunStopUnconfirmedError extends Error {
|
|
130
|
+
expectedAttemptId;
|
|
131
|
+
constructor(expectedAttemptId, cause) {
|
|
132
|
+
super('Stop was not confirmed.', { cause });
|
|
133
|
+
this.expectedAttemptId = expectedAttemptId;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.RunStopUnconfirmedError = RunStopUnconfirmedError;
|
|
137
|
+
async function stopAgentRun(runId, expectedAttemptId) {
|
|
138
|
+
if (typeof expectedAttemptId === 'string')
|
|
139
|
+
exactAttemptId(expectedAttemptId);
|
|
140
|
+
const { value, scope } = await readRunResource(eventsPath(runId));
|
|
141
|
+
const { snapshot } = assertEventsRun(runId, value);
|
|
142
|
+
if (!snapshot || typeof snapshot.status !== 'string' ||
|
|
143
|
+
(snapshot.activeAttemptId !== null &&
|
|
144
|
+
(typeof snapshot.activeAttemptId !== 'string' || !ATTEMPT_ID.test(snapshot.activeAttemptId)))) {
|
|
145
|
+
throw new Error('The server did not provide an exact Run snapshot.');
|
|
146
|
+
}
|
|
147
|
+
let attemptId = expectedAttemptId;
|
|
148
|
+
if (attemptId === undefined) {
|
|
149
|
+
if (TERMINAL.has(snapshot.status)) {
|
|
150
|
+
return { kind: 'already-ended', runId, status: snapshot.status };
|
|
151
|
+
}
|
|
152
|
+
attemptId = snapshot.activeAttemptId;
|
|
153
|
+
if (!STOPPABLE.has(snapshot.status) || (snapshot.status === 'queued') !== (attemptId === null)) {
|
|
154
|
+
throw new Error('The server did not confirm a stoppable Run and Attempt.');
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
let receipt;
|
|
158
|
+
try {
|
|
159
|
+
receipt = await (0, api_fetch_1.apiFetch)(`${path(runId)}/stop`, {
|
|
160
|
+
...scope,
|
|
161
|
+
method: 'POST',
|
|
162
|
+
body: { expectedAttemptId: attemptId },
|
|
163
|
+
singleAttempt: true,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
if ((0, write_outcome_1.unknownWriteOf)(error, (0, http_error_1.httpBodyOf)(error)) || error instanceof SyntaxError) {
|
|
168
|
+
throw new RunStopUnconfirmedError(attemptId, error);
|
|
169
|
+
}
|
|
170
|
+
throw error;
|
|
171
|
+
}
|
|
172
|
+
if (receipt?.runId !== runId || receipt.attemptId !== attemptId ||
|
|
173
|
+
(receipt.status !== 'stop_requested' && receipt.status !== 'cancelled')) {
|
|
174
|
+
throw new RunStopUnconfirmedError(attemptId);
|
|
175
|
+
}
|
|
176
|
+
return { kind: 'receipt', receipt };
|
|
177
|
+
}
|
|
@@ -221,7 +221,7 @@ export type AgenticStreamOptions = {
|
|
|
221
221
|
* the stream alone.
|
|
222
222
|
*/
|
|
223
223
|
reconcileTerminal?: () => Promise<ReconciledTerminal | null>;
|
|
224
|
-
/**
|
|
224
|
+
/** The original response from an idempotent Chat retry. Its session may have expired. */
|
|
225
225
|
resumeRecordedResponseId?: string;
|
|
226
226
|
/** Owner-authorized canonical envelopes, including events emitted before room admission. */
|
|
227
227
|
replayEnvelopes?: (from: number) => Promise<EnvelopeReplayPage>;
|
|
@@ -947,7 +947,7 @@ class AgenticStreamClient {
|
|
|
947
947
|
});
|
|
948
948
|
if (this.options.resumeRecordedResponseId) {
|
|
949
949
|
this.responseMessageId = this.options.resumeRecordedResponseId;
|
|
950
|
-
const hasTerminal = await this.probeTerminal('
|
|
950
|
+
const hasTerminal = await this.probeTerminal('idempotent_replay');
|
|
951
951
|
if (hasTerminal || this.handover || this.closed)
|
|
952
952
|
return result;
|
|
953
953
|
}
|
|
@@ -1096,7 +1096,7 @@ class AgenticStreamClient {
|
|
|
1096
1096
|
...(typeof terminal.text === 'string' ? { result: terminal.text } : {}),
|
|
1097
1097
|
...(terminal.publicProjection ? { publicProjection: terminal.publicProjection } : {}),
|
|
1098
1098
|
};
|
|
1099
|
-
if (reason === '
|
|
1099
|
+
if (reason === 'idempotent_replay')
|
|
1100
1100
|
this.finishAfterReplay(terminal.status, event);
|
|
1101
1101
|
else
|
|
1102
1102
|
this.finish(terminal.status, event);
|
package/dist/lib/api-fetch.d.ts
CHANGED
|
@@ -7,8 +7,8 @@ export interface ApiFetchOptions {
|
|
|
7
7
|
singleAttempt?: boolean;
|
|
8
8
|
/** Override credential resolution — useful for tests. */
|
|
9
9
|
credential?: ResolvedCredential;
|
|
10
|
-
/** Exact
|
|
11
|
-
sessionRead?: 'memory-history-v1';
|
|
10
|
+
/** Exact history GET on the currently bound Agent session. */
|
|
11
|
+
sessionRead?: 'memory-history-v1' | 'agent-history-v1';
|
|
12
12
|
/**
|
|
13
13
|
* Extra request headers. Added for `X-Idempotency-Key` (OSK-2806): the
|
|
14
14
|
* shared data-provider transport takes no per-call options, so a replayed
|
package/dist/lib/api-fetch.js
CHANGED
|
@@ -105,7 +105,7 @@ exports.ApiFetchError = ApiFetchError;
|
|
|
105
105
|
*/
|
|
106
106
|
async function apiFetch(pathOrUrl, opts = {}) {
|
|
107
107
|
const historyRead = opts.sessionRead
|
|
108
|
-
? (0, memory_history_session_1.
|
|
108
|
+
? (0, memory_history_session_1.bindHistoryRead)(pathOrUrl, opts.method ?? 'GET', process.env, opts.sessionRead)
|
|
109
109
|
: null;
|
|
110
110
|
const sessionCredential = historyRead
|
|
111
111
|
? { token: historyRead.token, source: 'env-token', kind: (0, credential_resolver_1.kindOf)(historyRead.token) }
|
|
@@ -358,15 +358,16 @@ async function apiFetch(pathOrUrl, opts = {}) {
|
|
|
358
358
|
catch {
|
|
359
359
|
/* ignore body read failures */
|
|
360
360
|
}
|
|
361
|
+
const historyName = opts.sessionRead === 'memory-history-v1' ? 'Memory' : 'Agent';
|
|
361
362
|
const unsupportedHistory = historyRead &&
|
|
362
363
|
res.status === 404 &&
|
|
363
364
|
(!code || ['API_ROUTE_NOT_FOUND', 'ROUTE_NOT_FOUND'].includes(code));
|
|
364
365
|
const error = new ApiFetchError(unsupportedHistory
|
|
365
|
-
?
|
|
366
|
-
: `HTTP ${res.status} ${res.statusText} — ${method} ${pathOrUrl}`, res.status, text, unsupportedHistory ?
|
|
366
|
+
? `This server does not support session-scoped ${historyName} history. Upgrade the server before retrying; owner-credential fallback is disabled.`
|
|
367
|
+
: `HTTP ${res.status} ${res.statusText} — ${method} ${pathOrUrl}`, res.status, text, unsupportedHistory ? `${historyName.toUpperCase()}_HISTORY_API_UNSUPPORTED` : code, method, res.headers.get('x-request-id') || undefined);
|
|
367
368
|
if (historyRead && res.status === 401) {
|
|
368
369
|
error.recoveryHint =
|
|
369
|
-
|
|
370
|
+
`Reconnect the managed Agent session and retry. If the refusal persists, check that this server supports session-scoped ${historyName} history. Owner-credential fallback is disabled.`;
|
|
370
371
|
}
|
|
371
372
|
error.requestPath = (0, write_outcome_1.requestPathOf)(url);
|
|
372
373
|
if (brokerFailure)
|
|
@@ -68,10 +68,9 @@ export interface EngineSessionExport {
|
|
|
68
68
|
redactions?: unknown;
|
|
69
69
|
}
|
|
70
70
|
/**
|
|
71
|
-
*
|
|
72
|
-
* an engine that predates `session export` cannot produce `{version, messages[]}`.
|
|
71
|
+
* Only accept a contract envelope for the requested engine session.
|
|
73
72
|
*/
|
|
74
|
-
export declare function parseSessionExportEnvelope(stdout: string): EngineSessionExport | null;
|
|
73
|
+
export declare function parseSessionExportEnvelope(stdout: string, sessionId: string): EngineSessionExport | null;
|
|
75
74
|
export type SessionExportFailureKind = 'unsupported' | 'unknown-session';
|
|
76
75
|
/**
|
|
77
76
|
* Classify a failed `session export` spawn (an `execFileSync` throw).
|
|
@@ -88,10 +88,9 @@ function composeHandoverPrompt(input) {
|
|
|
88
88
|
.join('\n');
|
|
89
89
|
}
|
|
90
90
|
/**
|
|
91
|
-
*
|
|
92
|
-
* an engine that predates `session export` cannot produce `{version, messages[]}`.
|
|
91
|
+
* Only accept a contract envelope for the requested engine session.
|
|
93
92
|
*/
|
|
94
|
-
function parseSessionExportEnvelope(stdout) {
|
|
93
|
+
function parseSessionExportEnvelope(stdout, sessionId) {
|
|
95
94
|
let parsed;
|
|
96
95
|
try {
|
|
97
96
|
parsed = JSON.parse(stdout);
|
|
@@ -102,9 +101,8 @@ function parseSessionExportEnvelope(stdout) {
|
|
|
102
101
|
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
103
102
|
return null;
|
|
104
103
|
const env = parsed;
|
|
105
|
-
if (env.version === undefined || env.version === null
|
|
106
|
-
|
|
107
|
-
if (!Array.isArray(env.messages))
|
|
104
|
+
if (env.version === undefined || env.version === null || env.sessionId !== sessionId ||
|
|
105
|
+
!Array.isArray(env.messages) || typeof env.truncated !== 'boolean')
|
|
108
106
|
return null;
|
|
109
107
|
return env;
|
|
110
108
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type AgentSessionMessageContext } from './message-intent';
|
|
2
|
+
export declare function resolveHistorySession(requireHumanAuth: () => void): AgentSessionMessageContext | null;
|
|
3
|
+
export declare function readBoundAgentHistory<T>(sessionId: string, path: string, query: Record<string, string | number | undefined>): Promise<T>;
|
|
4
|
+
export declare const historyTimeFlags: {
|
|
5
|
+
from: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
6
|
+
to: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
since: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
timezone: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
};
|
|
10
|
+
export type CommunicationHistoryItem = {
|
|
11
|
+
messageId: string;
|
|
12
|
+
side: 'agent' | 'user';
|
|
13
|
+
source: string;
|
|
14
|
+
ownerAuthored?: boolean;
|
|
15
|
+
at: string;
|
|
16
|
+
kind?: string;
|
|
17
|
+
excerpt?: string;
|
|
18
|
+
retracted?: boolean;
|
|
19
|
+
};
|
|
20
|
+
export type CommunicationHistoryResult = {
|
|
21
|
+
items?: CommunicationHistoryItem[];
|
|
22
|
+
message?: CommunicationHistoryItem;
|
|
23
|
+
nextCursor?: string | null;
|
|
24
|
+
coverage: 'complete' | 'partial';
|
|
25
|
+
};
|
|
26
|
+
export declare function readCommunicationHistory(operation: 'list' | 'show' | 'outreach', agentId: string, session: AgentSessionMessageContext | null, query: Record<string, string | number | undefined>): Promise<CommunicationHistoryResult>;
|
|
27
|
+
export declare function formatCommunicationHistoryItem(item: CommunicationHistoryItem): string;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.historyTimeFlags = void 0;
|
|
4
|
+
exports.resolveHistorySession = resolveHistorySession;
|
|
5
|
+
exports.readBoundAgentHistory = readBoundAgentHistory;
|
|
6
|
+
exports.readCommunicationHistory = readCommunicationHistory;
|
|
7
|
+
exports.formatCommunicationHistoryItem = formatCommunicationHistoryItem;
|
|
8
|
+
const node_util_1 = require("node:util");
|
|
9
|
+
const core_1 = require("@oclif/core");
|
|
10
|
+
const api_fetch_1 = require("./api-fetch");
|
|
11
|
+
const memory_history_session_1 = require("./memory-history-session");
|
|
12
|
+
function resolveHistorySession(requireHumanAuth) {
|
|
13
|
+
if ((0, memory_history_session_1.hasBoundHistoryRuntime)())
|
|
14
|
+
return (0, memory_history_session_1.boundHistorySession)(process.env, 'agent-history-v1');
|
|
15
|
+
requireHumanAuth();
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
function readBoundAgentHistory(sessionId, path, query) {
|
|
19
|
+
return (0, api_fetch_1.apiFetch)(`/api/agentic/sessions/${encodeURIComponent(sessionId)}/${path}${queryString(query)}`, { sessionRead: 'agent-history-v1' });
|
|
20
|
+
}
|
|
21
|
+
function queryString(query) {
|
|
22
|
+
const params = new URLSearchParams();
|
|
23
|
+
for (const [key, value] of Object.entries(query)) {
|
|
24
|
+
if (value !== undefined)
|
|
25
|
+
params.set(key, String(value));
|
|
26
|
+
}
|
|
27
|
+
return params.size ? `?${params}` : '';
|
|
28
|
+
}
|
|
29
|
+
exports.historyTimeFlags = {
|
|
30
|
+
from: core_1.Flags.string({ description: 'Inclusive ISO 8601 timestamp with an offset', exclusive: ['since'] }),
|
|
31
|
+
to: core_1.Flags.string({ description: 'Exclusive ISO 8601 timestamp with an offset', exclusive: ['since'] }),
|
|
32
|
+
since: core_1.Flags.string({ description: 'Today in the owner’s timezone, or an elapsed duration such as 7d', exclusive: ['from', 'to'] }),
|
|
33
|
+
timezone: core_1.Flags.string({ description: 'IANA timezone for --since today', dependsOn: ['since'] }),
|
|
34
|
+
};
|
|
35
|
+
function readCommunicationHistory(operation, agentId, session, query) {
|
|
36
|
+
if (session)
|
|
37
|
+
return readBoundAgentHistory(session.sessionId, `communication-history/${operation}`, query);
|
|
38
|
+
return (0, api_fetch_1.apiFetch)(`/api/agent-communications/history/${encodeURIComponent(agentId)}/${operation}${queryString(query)}`);
|
|
39
|
+
}
|
|
40
|
+
function formatCommunicationHistoryItem(item) {
|
|
41
|
+
const sender = item.side === 'user' ? item.ownerAuthored ? 'owner' : 'inbound' : item.kind ?? item.source;
|
|
42
|
+
const excerpt = item.retracted ? 'Withdrawn' : (0, node_util_1.stripVTControlCharacters)(item.excerpt ?? '')
|
|
43
|
+
.replace(/[\x00-\x1f\x7f-\x9f\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/g, ' ');
|
|
44
|
+
return [item.messageId, item.at, sender, excerpt].filter(Boolean).join(' · ');
|
|
45
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type ExecutionRun = {
|
|
2
|
+
id: string;
|
|
3
|
+
source: string;
|
|
4
|
+
status: string;
|
|
5
|
+
acceptedAt: string;
|
|
6
|
+
transcriptAvailability: string;
|
|
7
|
+
title?: string;
|
|
8
|
+
};
|
|
9
|
+
export type ExecutionRunDetail = ExecutionRun & {
|
|
10
|
+
coverage: 'complete' | 'partial';
|
|
11
|
+
attempts: Array<{
|
|
12
|
+
id: string;
|
|
13
|
+
number: number;
|
|
14
|
+
executor: string;
|
|
15
|
+
grantedAt?: string;
|
|
16
|
+
}>;
|
|
17
|
+
};
|
|
18
|
+
export type ExecutionPage<T> = {
|
|
19
|
+
items: T[];
|
|
20
|
+
nextCursor: string | null;
|
|
21
|
+
coverage: 'complete' | 'partial';
|
|
22
|
+
};
|
|
23
|
+
export type ExecutionExcerpt = {
|
|
24
|
+
sequence: number;
|
|
25
|
+
at?: string;
|
|
26
|
+
kind: string;
|
|
27
|
+
name?: string;
|
|
28
|
+
text?: string;
|
|
29
|
+
outcome?: string;
|
|
30
|
+
};
|
|
31
|
+
export declare function readExecutionHistory<T>(sessionId: string, operation: 'list' | 'show' | 'transcript', query: Record<string, string | number | undefined>): Promise<T>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readExecutionHistory = readExecutionHistory;
|
|
4
|
+
const communication_history_1 = require("./communication-history");
|
|
5
|
+
function readExecutionHistory(sessionId, operation, query) {
|
|
6
|
+
return (0, communication_history_1.readBoundAgentHistory)(sessionId, `execution-history/${operation}`, query);
|
|
7
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* OSK-3892 —
|
|
3
|
+
* OSK-3892 — give a user-started CLI an inference lease for its local engine process.
|
|
4
4
|
*
|
|
5
5
|
* Four steps, in this order, none of which may be reordered:
|
|
6
6
|
*
|
|
@@ -268,9 +268,7 @@ async function acquireManagedSession(input = {}, deps = {}) {
|
|
|
268
268
|
throw new ManagedAcquisitionError('not-signed-in', 'no skrr session on this machine — run `skrr login`');
|
|
269
269
|
}
|
|
270
270
|
const sessionId = newId();
|
|
271
|
-
// The
|
|
272
|
-
// concurrent turns in one session therefore need two process starts to be
|
|
273
|
-
// distinguishable, which is exactly what one CLI process is.
|
|
271
|
+
// The relay keys the lease to this process. These IDs have accounting scope.
|
|
274
272
|
const processStartId = newId();
|
|
275
273
|
// ONE deadline for the whole handshake, armed here and disarmed once the last
|
|
276
274
|
// round trip has answered. Everything the acquisition does over the network is
|
|
@@ -1083,7 +1081,7 @@ function managedLeaseClockLine(clocks, now = Date.now()) {
|
|
|
1083
1081
|
else {
|
|
1084
1082
|
parts.push('this server reports no ceiling');
|
|
1085
1083
|
}
|
|
1086
|
-
return `Managed
|
|
1084
|
+
return `Managed inference lease (${parts.join(' \u00b7 ')}).`;
|
|
1087
1085
|
}
|
|
1088
1086
|
function localClock(atMs) {
|
|
1089
1087
|
const at = new Date(atMs);
|
|
@@ -30,6 +30,7 @@ exports.readMessageDelivery = readMessageDelivery;
|
|
|
30
30
|
*/
|
|
31
31
|
const node_crypto_1 = require("node:crypto");
|
|
32
32
|
const data_provider_1 = require("@skrr-ai/data-provider");
|
|
33
|
+
const agent_runs_1 = require("./agent-runs");
|
|
33
34
|
const agent_chat_start_1 = require("./agent-chat-start");
|
|
34
35
|
const cloud_reply_1 = require("./cloud-reply");
|
|
35
36
|
const http_error_1 = require("./http-error");
|
|
@@ -315,10 +316,12 @@ function nextAfterSend(answer) {
|
|
|
315
316
|
case 'new_turn':
|
|
316
317
|
case 'merged':
|
|
317
318
|
if (turn?.sessionId && turn.responseMessageId) {
|
|
319
|
+
const runId = (0, agent_runs_1.canonicalRunId)(turn.runId);
|
|
318
320
|
return {
|
|
319
321
|
kind: 'turn',
|
|
320
322
|
sessionId: turn.sessionId,
|
|
321
323
|
responseMessageId: turn.responseMessageId,
|
|
324
|
+
...(runId ? { runId } : {}),
|
|
322
325
|
};
|
|
323
326
|
}
|
|
324
327
|
// A merge whose reply row is not known yet is answered by that turn; a new turn that did
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.SET_ASIDE_SENTENCES = exports.LOOK_SKIP_SENTENCES = void 0;
|
|
9
9
|
exports.describeLookAround = describeLookAround;
|
|
10
|
+
const agent_runs_1 = require("./agent-runs");
|
|
10
11
|
exports.LOOK_SKIP_SENTENCES = {
|
|
11
12
|
owner_inactive: 'you have not chatted with it lately; it looks again once you do',
|
|
12
13
|
billing_refused: 'your balance did not cover a look',
|
|
@@ -30,14 +31,25 @@ exports.SET_ASIDE_SENTENCES = {
|
|
|
30
31
|
function describeLookAround(lookAround, agentId) {
|
|
31
32
|
if (!lookAround)
|
|
32
33
|
return [];
|
|
34
|
+
const active = lookAround.state === 'looking';
|
|
35
|
+
const runId = (0, agent_runs_1.canonicalRunId)(active ? lookAround.activeRunId : lookAround.lastLook?.agentRunId);
|
|
36
|
+
if (active) {
|
|
37
|
+
if (!runId)
|
|
38
|
+
return ['Look requested. Check again for its Run or outcome.'];
|
|
39
|
+
return [
|
|
40
|
+
'Look in progress.',
|
|
41
|
+
`View Run: skrr runs show ${runId}`,
|
|
42
|
+
`Request Stop: skrr runs stop ${runId}`,
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
const history = runId ? [`View Run: skrr runs show ${runId}`] : [];
|
|
33
46
|
if (lookAround.state === 'paused') {
|
|
34
47
|
return [
|
|
35
48
|
`Looking around is paused: the last ${lookAround.consecutiveFailures} looks did not finish.`,
|
|
36
49
|
`Resume it with: skrr agents intuitions resume ${agentId}`,
|
|
50
|
+
...history,
|
|
37
51
|
];
|
|
38
52
|
}
|
|
39
|
-
if (lookAround.state === 'looking')
|
|
40
|
-
return ['Looking around now.'];
|
|
41
53
|
const lines = [];
|
|
42
54
|
const last = lookAround.lastLook;
|
|
43
55
|
if (last) {
|
|
@@ -46,8 +58,12 @@ function describeLookAround(lookAround, agentId) {
|
|
|
46
58
|
else if (last.outcome === 'nothing_to_suggest') {
|
|
47
59
|
lines.push(`Last look (${last.at}) found nothing worth suggesting.`);
|
|
48
60
|
}
|
|
49
|
-
else if (last.outcome === 'failed')
|
|
61
|
+
else if (last.outcome === 'failed') {
|
|
50
62
|
lines.push(`Last look (${last.at}) did not finish.`);
|
|
63
|
+
}
|
|
64
|
+
else if (last.outcome === 'interrupted') {
|
|
65
|
+
lines.push(`Stop was requested for the look (${last.at}).`);
|
|
66
|
+
}
|
|
51
67
|
else if (last.skipReason) {
|
|
52
68
|
lines.push(`Last look (${last.at}) skipped: ${exports.LOOK_SKIP_SENTENCES[last.skipReason] ?? last.skipReason}.`);
|
|
53
69
|
}
|
|
@@ -60,5 +76,5 @@ function describeLookAround(lookAround, agentId) {
|
|
|
60
76
|
lines.push('Next look waits for quiet hours to end.');
|
|
61
77
|
else if (lookAround.nextLookAt)
|
|
62
78
|
lines.push(`Next look: ${lookAround.nextLookAt}.`);
|
|
63
|
-
return lines;
|
|
79
|
+
return [...lines, ...history];
|
|
64
80
|
}
|