@skrr-ai/cli 0.1.164 → 0.1.166
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 +13 -0
- package/dist/base-command.d.ts +14 -1
- package/dist/base-command.js +166 -46
- package/dist/commands/agent/message/send.d.ts +1 -0
- package/dist/commands/agent/message/send.js +3 -0
- package/dist/commands/agents/mini-computer/app/set.js +1 -1
- package/dist/commands/agents/mini-computer/tasks-view.js +1 -1
- package/dist/commands/apps/check.js +3 -8
- package/dist/commands/apps/data/batch.d.ts +1 -0
- package/dist/commands/apps/data/batch.js +19 -2
- package/dist/commands/apps/data/delete.d.ts +1 -0
- package/dist/commands/apps/data/delete.js +14 -2
- package/dist/commands/apps/data/patch.d.ts +1 -0
- package/dist/commands/apps/data/patch.js +11 -2
- package/dist/commands/apps/data/put.d.ts +1 -0
- package/dist/commands/apps/data/put.js +17 -3
- package/dist/commands/apps/install.js +7 -2
- package/dist/commands/apps/installations/compatibility.d.ts +13 -0
- package/dist/commands/apps/installations/compatibility.js +60 -0
- package/dist/commands/apps/installations/migrate/abort.d.ts +13 -0
- package/dist/commands/apps/installations/migrate/abort.js +45 -0
- package/dist/commands/apps/installations/migrate/cutover.d.ts +15 -0
- package/dist/commands/apps/installations/migrate/cutover.js +102 -0
- package/dist/commands/apps/installations/migrate/plan.d.ts +13 -0
- package/dist/commands/apps/installations/migrate/plan.js +51 -0
- package/dist/commands/apps/installations/migrate/rollback.d.ts +16 -0
- package/dist/commands/apps/installations/migrate/rollback.js +103 -0
- package/dist/commands/apps/installations/migrate/stage.d.ts +15 -0
- package/dist/commands/apps/installations/migrate/stage.js +96 -0
- package/dist/commands/apps/installations/migrate/status.d.ts +12 -0
- package/dist/commands/apps/installations/migrate/status.js +52 -0
- package/dist/commands/apps/installations/migrate/validate.d.ts +14 -0
- package/dist/commands/apps/installations/migrate/validate.js +58 -0
- package/dist/commands/apps/installations/show.js +14 -9
- package/dist/commands/apps/installations/snapshot.js +5 -2
- package/dist/commands/apps/operations/check.d.ts +16 -0
- package/dist/commands/apps/operations/check.js +127 -0
- package/dist/commands/apps/publish/propose.js +33 -4
- package/dist/commands/apps/reconsent.js +7 -1
- package/dist/commands/apps/reference.d.ts +4 -2
- package/dist/commands/apps/reference.js +7 -4
- package/dist/commands/apps/resume.js +1 -1
- package/dist/commands/apps/rollback.d.ts +9 -0
- package/dist/commands/apps/rollback.js +81 -2
- package/dist/commands/apps/settings/set.js +22 -10
- package/dist/commands/apps/upgrade.d.ts +8 -0
- package/dist/commands/apps/upgrade.js +67 -2
- package/dist/commands/apps/version/cat.d.ts +22 -0
- package/dist/commands/apps/version/cat.js +220 -0
- package/dist/commands/apps/version/show.js +3 -1
- package/dist/commands/commerce/incidents/release.d.ts +24 -0
- package/dist/commands/commerce/incidents/release.js +46 -0
- package/dist/commands/duties/cases.js +12 -1
- package/dist/commands/duties/hypotheses.js +10 -3
- package/dist/commands/duties/observations.d.ts +4 -0
- package/dist/commands/duties/observations.js +14 -3
- package/dist/commands/outbox/list.d.ts +11 -4
- package/dist/commands/outbox/list.js +56 -9
- package/dist/commands/outbox/retry.d.ts +8 -2
- package/dist/commands/outbox/retry.js +76 -16
- package/dist/commands/outbox/show.d.ts +20 -0
- package/dist/commands/outbox/show.js +83 -0
- package/dist/commands/proposals/list.js +13 -9
- package/dist/commands/requests/show.d.ts +12 -0
- package/dist/commands/requests/show.js +42 -23
- package/dist/commands/spaces/deletion/cancel.d.ts +21 -0
- package/dist/commands/spaces/deletion/cancel.js +70 -0
- package/dist/commands/spaces/workflows/run.js +12 -0
- package/dist/commands/widgets/check.d.ts +9 -0
- package/dist/commands/widgets/check.js +16 -3
- package/dist/generated/agent-guides.json +17 -17
- package/dist/lib/api-fetch.d.ts +5 -0
- package/dist/lib/api-fetch.js +81 -22
- package/dist/lib/appCompatibility.d.ts +31 -0
- package/dist/lib/appCompatibility.js +66 -0
- package/dist/lib/appData.d.ts +46 -4
- package/dist/lib/appData.js +161 -32
- package/dist/lib/appDataMigration.d.ts +204 -0
- package/dist/lib/appDataMigration.js +753 -0
- package/dist/lib/appDataMigrationCommand.d.ts +39 -0
- package/dist/lib/appDataMigrationCommand.js +90 -0
- package/dist/lib/appInstallations.d.ts +40 -5
- package/dist/lib/appInstallations.js +251 -35
- package/dist/lib/appVersionFile.d.ts +82 -0
- package/dist/lib/appVersionFile.js +195 -0
- package/dist/lib/apps-command.d.ts +14 -3
- package/dist/lib/apps-command.js +80 -65
- package/dist/lib/appsCheck.js +16 -2
- package/dist/lib/commerce.d.ts +6 -0
- package/dist/lib/commerce.js +9 -0
- package/dist/lib/duties.d.ts +15 -1
- package/dist/lib/duties.js +21 -3
- package/dist/lib/json-output.d.ts +2 -0
- package/dist/lib/json-output.js +8 -4
- package/dist/lib/node-adapter.js +69 -38
- package/dist/lib/outbox.d.ts +110 -1
- package/dist/lib/outbox.js +261 -35
- package/dist/lib/rate-limit-retry.d.ts +4 -5
- package/dist/lib/rate-limit-retry.js +6 -10
- package/dist/lib/refresh.d.ts +2 -0
- package/dist/lib/refresh.js +6 -0
- package/dist/lib/space-deletion-cancel.d.ts +47 -0
- package/dist/lib/space-deletion-cancel.js +141 -0
- package/dist/lib/widgetCheck.js +1 -1
- package/dist/lib/widgetStaticScan.d.ts +11 -5
- package/dist/lib/widgetStaticScan.js +73 -165
- package/dist/lib/write-outcome.d.ts +76 -0
- package/dist/lib/write-outcome.js +190 -0
- package/dist/node_modules/@skrr-ai/data-provider/index.js +11955 -11231
- package/oclif.manifest.json +3019 -499
- package/package.json +12 -3
package/dist/lib/duties.d.ts
CHANGED
|
@@ -1224,8 +1224,22 @@ export declare function renderDutyMetrics(response: ReadModelRecord, log: (line:
|
|
|
1224
1224
|
* cost census predates the current rule is visible in the table.
|
|
1225
1225
|
*/
|
|
1226
1226
|
export declare function costRuleCell(projection: Record<string, unknown> | null | undefined, closed?: boolean): string;
|
|
1227
|
+
/**
|
|
1228
|
+
* Whether a response is a bound-only history (OSK-23203, A30 phase 3) and whether it left anything out. The server
|
|
1229
|
+
* marks it `sourcePolicy.reason = 'bound_to_this_duty_document'` and says `coverage.someHidden` without a count.
|
|
1230
|
+
* `null` means the response is not a bound-only history at all.
|
|
1231
|
+
*/
|
|
1232
|
+
export declare function boundHistoryCoverage(value: unknown): {
|
|
1233
|
+
someHidden: boolean;
|
|
1234
|
+
} | null;
|
|
1235
|
+
/** What the server says about a bound-only Case list: only Cases tied to this Duty document are shown. */
|
|
1236
|
+
export declare const BOUND_CASES_NOTE = "Only cases tied to this Duty document are shown. Other cases carry this Duty\u2019s id but cannot be tied to it (an earlier Duty with the same id, or recorded before the link existed), so they are left out.";
|
|
1237
|
+
/** What the server says about a bound-only hypothesis list: only claims first recorded for this Duty document are shown. */
|
|
1238
|
+
export declare const BOUND_HYPOTHESES_NOTE = "Only hypotheses first recorded for this Duty document are shown. Others carry this Duty\u2019s id but cannot be tied to it (an earlier Duty with the same id, or recorded before the link existed), so they are left out.";
|
|
1227
1239
|
/** Human view for the case list — one row per durable problem case. */
|
|
1228
|
-
export declare function renderDutyCases(response: ReadModelRecord, log: (line: string) => void
|
|
1240
|
+
export declare function renderDutyCases(response: ReadModelRecord, log: (line: string) => void, options?: {
|
|
1241
|
+
emptyMessage?: string;
|
|
1242
|
+
}): void;
|
|
1229
1243
|
/**
|
|
1230
1244
|
* Human view for one case — a bounded digest, never the raw document.
|
|
1231
1245
|
*
|
package/dist/lib/duties.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DUTY_CLI_EVALUATORS = exports.DUTY_CREATE_KEYS = exports.DUTY_REMEDIATION_ACTIONS = exports.DUTY_FEEDBACK_KINDS = exports.dutyApi = exports.dutyPackApi = exports.MAX_DUTY_INTERVAL_MS = exports.MIN_DUTY_INTERVAL_MS = exports.DUTY_EXECUTION_ISOLATION_MODES = exports.DUTY_AUTHORABLE_CADENCE_MODES = exports.DUTY_KIND_VALUES = exports.DUTY_STATUSES = exports.DUTY_CADENCE_MAX_TIMES = exports.DUTY_CADENCE_TIME_PATTERN = exports.DUTY_CADENCE_MODES = exports.DUTY_TEMPLATE_IDS = exports.DUTY_WATCHED_SOURCES = void 0;
|
|
3
|
+
exports.BOUND_HYPOTHESES_NOTE = exports.BOUND_CASES_NOTE = exports.DUTY_CLI_EVALUATORS = exports.DUTY_CREATE_KEYS = exports.DUTY_REMEDIATION_ACTIONS = exports.DUTY_FEEDBACK_KINDS = exports.dutyApi = exports.dutyPackApi = exports.MAX_DUTY_INTERVAL_MS = exports.MIN_DUTY_INTERVAL_MS = exports.DUTY_EXECUTION_ISOLATION_MODES = exports.DUTY_AUTHORABLE_CADENCE_MODES = exports.DUTY_KIND_VALUES = exports.DUTY_STATUSES = exports.DUTY_CADENCE_MAX_TIMES = exports.DUTY_CADENCE_TIME_PATTERN = exports.DUTY_CADENCE_MODES = exports.DUTY_TEMPLATE_IDS = exports.DUTY_WATCHED_SOURCES = void 0;
|
|
4
4
|
exports.activationRefusalLines = activationRefusalLines;
|
|
5
5
|
exports.gateRefusesActivation = gateRefusesActivation;
|
|
6
6
|
exports.permissionLines = permissionLines;
|
|
@@ -59,6 +59,7 @@ exports.isDutyLineageUnavailable = isDutyLineageUnavailable;
|
|
|
59
59
|
exports.renderDutyLineage = renderDutyLineage;
|
|
60
60
|
exports.renderDutyMetrics = renderDutyMetrics;
|
|
61
61
|
exports.costRuleCell = costRuleCell;
|
|
62
|
+
exports.boundHistoryCoverage = boundHistoryCoverage;
|
|
62
63
|
exports.renderDutyCases = renderDutyCases;
|
|
63
64
|
exports.renderDutyCaseDetail = renderDutyCaseDetail;
|
|
64
65
|
exports.renderDutyRemediationProposals = renderDutyRemediationProposals;
|
|
@@ -2571,8 +2572,25 @@ function costRuleCell(projection, closed = Boolean(projection)) {
|
|
|
2571
2572
|
return '-';
|
|
2572
2573
|
return projection.current === false ? `v${version} (older)` : `v${version}`;
|
|
2573
2574
|
}
|
|
2575
|
+
/**
|
|
2576
|
+
* Whether a response is a bound-only history (OSK-23203, A30 phase 3) and whether it left anything out. The server
|
|
2577
|
+
* marks it `sourcePolicy.reason = 'bound_to_this_duty_document'` and says `coverage.someHidden` without a count.
|
|
2578
|
+
* `null` means the response is not a bound-only history at all.
|
|
2579
|
+
*/
|
|
2580
|
+
function boundHistoryCoverage(value) {
|
|
2581
|
+
if (!value || typeof value !== 'object')
|
|
2582
|
+
return null;
|
|
2583
|
+
const v = value;
|
|
2584
|
+
if (v.sourcePolicy?.reason !== 'bound_to_this_duty_document')
|
|
2585
|
+
return null;
|
|
2586
|
+
return { someHidden: v.coverage?.someHidden === true };
|
|
2587
|
+
}
|
|
2588
|
+
/** What the server says about a bound-only Case list: only Cases tied to this Duty document are shown. */
|
|
2589
|
+
exports.BOUND_CASES_NOTE = 'Only cases tied to this Duty document are shown. Other cases carry this Duty’s id but cannot be tied to it (an earlier Duty with the same id, or recorded before the link existed), so they are left out.';
|
|
2590
|
+
/** What the server says about a bound-only hypothesis list: only claims first recorded for this Duty document are shown. */
|
|
2591
|
+
exports.BOUND_HYPOTHESES_NOTE = 'Only hypotheses first recorded for this Duty document are shown. Others carry this Duty’s id but cannot be tied to it (an earlier Duty with the same id, or recorded before the link existed), so they are left out.';
|
|
2574
2592
|
/** Human view for the case list — one row per durable problem case. */
|
|
2575
|
-
function renderDutyCases(response, log) {
|
|
2593
|
+
function renderDutyCases(response, log, options = {}) {
|
|
2576
2594
|
const data = records(response.data);
|
|
2577
2595
|
renderRows(data.map((item) => ({
|
|
2578
2596
|
id: text(item.id),
|
|
@@ -2592,7 +2610,7 @@ function renderDutyCases(response, log) {
|
|
|
2592
2610
|
{ key: 'hypotheses', header: 'HYPO', maxWidth: 6 },
|
|
2593
2611
|
{ key: 'receipts', header: 'RCPTS', maxWidth: 6 },
|
|
2594
2612
|
{ key: 'last', header: 'LAST OBSERVED', maxWidth: 24 },
|
|
2595
|
-
], 'No cases recorded.', log);
|
|
2613
|
+
], options.emptyMessage ?? 'No cases recorded.', log);
|
|
2596
2614
|
}
|
|
2597
2615
|
/**
|
|
2598
2616
|
* Human view for one case — a bounded digest, never the raw document.
|
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
* identifier would turn a cosmetic cleanup into data loss.
|
|
18
18
|
*/
|
|
19
19
|
type Json = unknown;
|
|
20
|
+
/** The characters a terminal would act on rather than show, which JSON output escapes (and `apps version cat` builds on). */
|
|
21
|
+
export declare const JSON_TERMINAL_CONTROLS: RegExp;
|
|
20
22
|
/** Escape terminal controls in serialized JSON without changing its parsed value. */
|
|
21
23
|
export declare function escapeJsonForTerminal(text: string): string;
|
|
22
24
|
/**
|
package/dist/lib/json-output.js
CHANGED
|
@@ -18,17 +18,21 @@
|
|
|
18
18
|
* identifier would turn a cosmetic cleanup into data loss.
|
|
19
19
|
*/
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.JSON_TERMINAL_CONTROLS = void 0;
|
|
21
22
|
exports.escapeJsonForTerminal = escapeJsonForTerminal;
|
|
22
23
|
exports.stripStorageFields = stripStorageFields;
|
|
23
24
|
exports.stripAppDataQueryMetadata = stripAppDataQueryMetadata;
|
|
24
25
|
exports.stripStorageFieldsFromText = stripStorageFieldsFromText;
|
|
25
26
|
exports.withOk = withOk;
|
|
26
27
|
exports.withCliOperation = withCliOperation;
|
|
27
|
-
|
|
28
|
+
/** The characters a terminal would act on rather than show, which JSON output escapes (and `apps version cat` builds on). */
|
|
29
|
+
exports.JSON_TERMINAL_CONTROLS =
|
|
30
|
+
// eslint-disable-next-line no-misleading-character-class -- the point of the pattern is to match combining and invisible characters (a pre-existing finding, annotated because this file is now also staged for `apps version cat`)
|
|
31
|
+
/[\u007f-\u009f\u00ad\u034f\u061c\u115f\u1160\u17b4\u17b5\u180b-\u180e\u200b-\u200f\u2028-\u202e\u2060-\u206f\u2800\u3164\ufe00-\ufe0f\ufeff\uffa0\ufff9-\ufffb\u{1d173}-\u{1d17a}\u{e0000}-\u{e03ff}]/gu;
|
|
28
32
|
/** Escape terminal controls in serialized JSON without changing its parsed value. */
|
|
29
33
|
function escapeJsonForTerminal(text) {
|
|
30
34
|
const head = text.trimStart()[0];
|
|
31
|
-
if ((head !== '{' && head !== '[' && head !== '"') || text.search(JSON_TERMINAL_CONTROLS) === -1)
|
|
35
|
+
if ((head !== '{' && head !== '[' && head !== '"') || text.search(exports.JSON_TERMINAL_CONTROLS) === -1)
|
|
32
36
|
return text;
|
|
33
37
|
// Prose printed by a command in JSON mode is not necessarily a JSON document.
|
|
34
38
|
try {
|
|
@@ -38,7 +42,7 @@ function escapeJsonForTerminal(text) {
|
|
|
38
42
|
return text;
|
|
39
43
|
}
|
|
40
44
|
// Do not escape C0: a serialized JSON string has already escaped it, while indentation uses newlines.
|
|
41
|
-
return text.replace(JSON_TERMINAL_CONTROLS, (char) => Array.from({ length: char.length }, (_, index) => `\\u${char.charCodeAt(index).toString(16).padStart(4, '0')}`).join(''));
|
|
45
|
+
return text.replace(exports.JSON_TERMINAL_CONTROLS, (char) => Array.from({ length: char.length }, (_, index) => `\\u${char.charCodeAt(index).toString(16).padStart(4, '0')}`).join(''));
|
|
42
46
|
}
|
|
43
47
|
function usableId(value) {
|
|
44
48
|
return (typeof value === 'string' && value.length > 0) || typeof value === 'number';
|
|
@@ -177,7 +181,7 @@ function withCliOperation(value, options) {
|
|
|
177
181
|
...(options.replayed !== undefined ? { replayed: options.replayed } : {}),
|
|
178
182
|
writeState: options.mode !== 'execute'
|
|
179
183
|
? 'not_attempted'
|
|
180
|
-
: options.writeState ?? (outcome === 'succeeded' ? 'confirmed' : 'unknown'),
|
|
184
|
+
: (options.writeState ?? (outcome === 'succeeded' ? 'confirmed' : 'unknown')),
|
|
181
185
|
},
|
|
182
186
|
};
|
|
183
187
|
}
|
package/dist/lib/node-adapter.js
CHANGED
|
@@ -20,14 +20,9 @@ const task_runtime_headers_1 = require("./task-runtime-headers");
|
|
|
20
20
|
const non_json_response_1 = require("./non-json-response");
|
|
21
21
|
require("./auth-core-init");
|
|
22
22
|
const rate_limit_retry_1 = require("./rate-limit-retry");
|
|
23
|
+
const write_outcome_1 = require("./write-outcome");
|
|
23
24
|
const RESOLVE_URL_RE = /^https?:\/\//i;
|
|
24
25
|
const RESOLVE_URL_RE_2 = /\/+$/;
|
|
25
|
-
// These routes do not yet have a server-side idempotency receipt. A generated
|
|
26
|
-
// request key alone cannot make an arbitrary gateway response safe to replay.
|
|
27
|
-
// A deployment can mount the API beneath a path prefix; a match at any
|
|
28
|
-
// segment is deliberately conservative even for a different origin.
|
|
29
|
-
const APP_DATA_PATH_RE = /\/api\/apps\/installations\/[^/]+\/data(?:\/|$)/;
|
|
30
|
-
const APP_SETTINGS_PATH_RE = /\/api\/apps\/installations\/[^/]+\/settings\/?$/;
|
|
31
26
|
// ---------------------------------------------------------------------
|
|
32
27
|
// Per-process credential override — set by BaseCommand.init().
|
|
33
28
|
// Pulled out of the closure so test harnesses or long-lived callers
|
|
@@ -169,26 +164,6 @@ function createNodeAdapter(opts = {}) {
|
|
|
169
164
|
}
|
|
170
165
|
return u.toString();
|
|
171
166
|
}
|
|
172
|
-
function isAppDataWrite(method, url) {
|
|
173
|
-
if (method === 'GET')
|
|
174
|
-
return false;
|
|
175
|
-
try {
|
|
176
|
-
return APP_DATA_PATH_RE.test(new URL(url).pathname);
|
|
177
|
-
}
|
|
178
|
-
catch {
|
|
179
|
-
return false;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
function isAppSettingsWrite(method, url) {
|
|
183
|
-
if (method !== 'PUT')
|
|
184
|
-
return false;
|
|
185
|
-
try {
|
|
186
|
-
return APP_SETTINGS_PATH_RE.test(new URL(url).pathname);
|
|
187
|
-
}
|
|
188
|
-
catch {
|
|
189
|
-
return false;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
167
|
/** The last 429's `Retry-After`, read off the response of the most recent attempt. */
|
|
193
168
|
let lastRetryAfterMs;
|
|
194
169
|
async function rawRequest(method, url, body, options, isFormData) {
|
|
@@ -217,12 +192,32 @@ function createNodeAdapter(opts = {}) {
|
|
|
217
192
|
const signal = timeoutSignal && callerSignal
|
|
218
193
|
? AbortSignal.any([timeoutSignal, callerSignal])
|
|
219
194
|
: timeoutSignal || callerSignal;
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
195
|
+
const replaySafe = options?._disableAuthReplay !== true && (0, write_outcome_1.isRequestReplaySafe)(method, finalUrl, headers);
|
|
196
|
+
let fetched;
|
|
197
|
+
try {
|
|
198
|
+
fetched = await (0, rate_limit_retry_1.fetchWithRateLimitRetry)(() => fetch(finalUrl, {
|
|
199
|
+
method,
|
|
200
|
+
headers,
|
|
201
|
+
body: finalBody,
|
|
202
|
+
...(signal ? { signal } : {}),
|
|
203
|
+
// A receipt for this route cannot vouch for a redirect destination.
|
|
204
|
+
...(!replaySafe || method !== 'GET'
|
|
205
|
+
? { redirect: 'manual' }
|
|
206
|
+
: (0, task_runtime_headers_1.taskRuntimeRedirectOptions)(headers)),
|
|
207
|
+
}), {
|
|
208
|
+
method,
|
|
209
|
+
url: finalUrl,
|
|
210
|
+
headers,
|
|
211
|
+
signal,
|
|
212
|
+
...(!replaySafe ? { maxRetries: 0 } : {}),
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
catch (transportError) {
|
|
216
|
+
// No answer came back. The error says nothing of what was asked, and whether the write may be sent again depends
|
|
217
|
+
// on which route it was (OSK-24076): stamp the method and path so the error path can ask the registry.
|
|
218
|
+
throw (0, write_outcome_1.stampRequest)(transportError, method, finalUrl);
|
|
219
|
+
}
|
|
220
|
+
const { response, retryAfterMs } = fetched;
|
|
226
221
|
lastRetryAfterMs = retryAfterMs;
|
|
227
222
|
return response;
|
|
228
223
|
}
|
|
@@ -365,6 +360,37 @@ function createNodeAdapter(opts = {}) {
|
|
|
365
360
|
onTokenRefresh?.(accessToken, outcome.outcome.refreshToken);
|
|
366
361
|
return true;
|
|
367
362
|
}
|
|
363
|
+
async function refreshBeforeWrite() {
|
|
364
|
+
const { token, kind } = currentCredential();
|
|
365
|
+
if (!token ||
|
|
366
|
+
_credOverride?.source === 'flag' ||
|
|
367
|
+
(0, auth_core_1.isStaticTokenKind)(kind) ||
|
|
368
|
+
!(0, refresh_1.cliCredentialNeedsRefresh)(token))
|
|
369
|
+
return;
|
|
370
|
+
if ((0, delegated_cli_1.isDelegatedCliSession)()) {
|
|
371
|
+
await refresh();
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
if ((0, credential_resolver_1.resolveTrustedAutonomousCredential)())
|
|
375
|
+
return;
|
|
376
|
+
if ((0, daemonBroker_1.isBrokeredHandoffToken)(token)) {
|
|
377
|
+
const fresh = await (0, daemonBroker_1.redeemBrokeredHandoffToken)(true);
|
|
378
|
+
if (fresh?.accessToken) {
|
|
379
|
+
setAdapterCredentialOverride({
|
|
380
|
+
token: fresh.accessToken,
|
|
381
|
+
source: 'env-token',
|
|
382
|
+
kind: (0, auth_core_1.classifyTokenKind)(fresh.accessToken),
|
|
383
|
+
});
|
|
384
|
+
onTokenRefresh?.(fresh.accessToken);
|
|
385
|
+
}
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
const fresh = await (0, refresh_1.ensureFreshCliCredential)({ credential: _credOverride ?? undefined });
|
|
389
|
+
if (fresh.refreshed && fresh.credential.token) {
|
|
390
|
+
setAdapterCredentialOverride(fresh.credential);
|
|
391
|
+
onTokenRefresh?.(fresh.credential.token, fresh.pair?.refreshToken);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
368
394
|
async function request(method, url, body, options, isFormData = false) {
|
|
369
395
|
// Writes that arrive through `request.ts` already carry a key. A direct
|
|
370
396
|
// adapter call gets one by the same shared rule, chosen HERE, once, so the
|
|
@@ -375,12 +401,15 @@ function createNodeAdapter(opts = {}) {
|
|
|
375
401
|
headers: (0, data_provider_1.withIdempotencyKey)(options?.headers, { method, url, body }),
|
|
376
402
|
};
|
|
377
403
|
}
|
|
378
|
-
|
|
379
|
-
|
|
404
|
+
if (method !== 'GET' && !url.includes('/api/auth/')) {
|
|
405
|
+
await refreshBeforeWrite();
|
|
406
|
+
}
|
|
407
|
+
const replaySafe = options?._disableAuthReplay !== true &&
|
|
408
|
+
(0, write_outcome_1.isRequestReplaySafe)(method, resolveUrl(url), options?.headers);
|
|
380
409
|
let res = await rawRequest(method, url, body, options, isFormData);
|
|
381
410
|
// Never retry auth endpoints themselves — prevents refresh recursion
|
|
382
411
|
// and lets login/logout/refresh surface their real errors.
|
|
383
|
-
if (res.status === 401 &&
|
|
412
|
+
if (res.status === 401 && replaySafe && !url.includes('/api/auth/')) {
|
|
384
413
|
const refreshed = await refresh();
|
|
385
414
|
if (refreshed) {
|
|
386
415
|
res = await rawRequest(method, url, body, options, isFormData);
|
|
@@ -395,11 +424,11 @@ function createNodeAdapter(opts = {}) {
|
|
|
395
424
|
if (brokered) {
|
|
396
425
|
res = await rawRequest(method, url, body, options, isFormData);
|
|
397
426
|
}
|
|
398
|
-
else {
|
|
399
|
-
onAuthFailure?.();
|
|
400
|
-
}
|
|
401
427
|
}
|
|
402
428
|
}
|
|
429
|
+
if (res.status === 401 && !url.includes('/api/auth/')) {
|
|
430
|
+
onAuthFailure?.();
|
|
431
|
+
}
|
|
403
432
|
if (!res.ok) {
|
|
404
433
|
// Attach the raw body to the error object so callers can inspect
|
|
405
434
|
// it programmatically (e.g., --json mode, debug output), but keep
|
|
@@ -416,6 +445,8 @@ function createNodeAdapter(opts = {}) {
|
|
|
416
445
|
err.status = res.status;
|
|
417
446
|
err.body = text;
|
|
418
447
|
err.method = method;
|
|
448
|
+
// Which route answered, so a 5xx on a write can be judged against the routes that keep a server receipt (OSK-24076).
|
|
449
|
+
err.requestPath = (0, write_outcome_1.requestPathOf)(url);
|
|
419
450
|
// The server stamps every response with the id it logs against
|
|
420
451
|
// (`requestLogger`). Carrying it means a refused call can be found in
|
|
421
452
|
// the logs instead of guessed at: with several clients on one account,
|
package/dist/lib/outbox.d.ts
CHANGED
|
@@ -14,6 +14,18 @@ export interface OutboxEntry {
|
|
|
14
14
|
body: unknown;
|
|
15
15
|
/** Workspace active when the write was authored, preserved for replay. */
|
|
16
16
|
workspaceId?: string;
|
|
17
|
+
/**
|
|
18
|
+
* The deployment this write was queued against, as `scheme://host[:port]`
|
|
19
|
+
* (OSK-23807). Absent on entries queued before origin binding, which cannot
|
|
20
|
+
* prove where they were meant to go and so stay paused as unverified.
|
|
21
|
+
*/
|
|
22
|
+
origin?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Who the CLI believed it was acting as, with no secret in it: `user:<id>`
|
|
25
|
+
* when the credential carries an id claim, else `profile:<name>`. Present
|
|
26
|
+
* together with `origin`, or not at all.
|
|
27
|
+
*/
|
|
28
|
+
account?: string;
|
|
17
29
|
/** ISO timestamp of the enqueue. */
|
|
18
30
|
queuedAt: string;
|
|
19
31
|
/** Why it could not be sent — the outage evidence, for triage. */
|
|
@@ -45,7 +57,104 @@ export interface OutboxEntry {
|
|
|
45
57
|
*/
|
|
46
58
|
export declare const MAX_REPLAY_ATTEMPTS = 10;
|
|
47
59
|
export declare function isOutageFailure(err: unknown): boolean;
|
|
48
|
-
|
|
60
|
+
/**
|
|
61
|
+
* ── What may be queued without knowing it did not happen (OSK-24076) ────────
|
|
62
|
+
*
|
|
63
|
+
* A write is queued to be sent again, and sending it again is only safe when the
|
|
64
|
+
* first attempt either did not happen or will be recognised. A 408, a 425, a 5xx
|
|
65
|
+
* and a dead connection prove neither: the server may have applied the write
|
|
66
|
+
* before it failed. Those are queued ONLY for a route the server keeps a replay
|
|
67
|
+
* receipt for (`request`, checked against the registry of routes that mount
|
|
68
|
+
* `requestIdempotency`); on any other route the outcome is unknown, and a repeat
|
|
69
|
+
* could apply it twice, so the write is not queued and the failure is reported.
|
|
70
|
+
*
|
|
71
|
+
* Three kinds of failure do not depend on the route and keep their answer:
|
|
72
|
+
* 401 and 429 as before: could not authenticate right now, throttled.
|
|
73
|
+
* a refused connection or a failed name lookup the request never left, so
|
|
74
|
+
* nothing happened and queueing it is safe.
|
|
75
|
+
*
|
|
76
|
+
* `request` is the write that failed. Left out, the route is unknown and so has
|
|
77
|
+
* no receipt: the default for a write is that nothing will recognise a repeat.
|
|
78
|
+
*/
|
|
79
|
+
export declare function isRetryableWrite(err: unknown, request?: {
|
|
80
|
+
method?: string;
|
|
81
|
+
path?: string;
|
|
82
|
+
}): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* `scheme://host[:port]` of an API base URL, or null when it names no HTTP(S)
|
|
85
|
+
* server. Case, default ports, credentials, path, query and fragment are
|
|
86
|
+
* dropped, so `HTTPS://Skrr.AI:443/api/` and `https://skrr.ai` are one origin.
|
|
87
|
+
*/
|
|
88
|
+
export declare function normalizeOutboxOrigin(baseURL: string | null | undefined): string | null;
|
|
89
|
+
/**
|
|
90
|
+
* The account label for a credential: `user:<id>` from the access token's `id`
|
|
91
|
+
* claim, else `profile:<name>`, which is all an opaque credential (a personal
|
|
92
|
+
* access token, a CI token) lets the CLI know without asking the server.
|
|
93
|
+
*/
|
|
94
|
+
export declare function outboxAccountFor(token: string | null | undefined, profile?: string): string;
|
|
95
|
+
export interface OutboxBinding {
|
|
96
|
+
origin: string;
|
|
97
|
+
account: string;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* What to record on an entry being queued now, or null when the configured
|
|
101
|
+
* server is not an HTTP(S) origin. A null binding still queues the write so the
|
|
102
|
+
* content survives; it just stays paused as unverified, like an older entry.
|
|
103
|
+
*/
|
|
104
|
+
export declare function outboxBindingFor(input: {
|
|
105
|
+
baseURL: string | null | undefined;
|
|
106
|
+
token: string | null | undefined;
|
|
107
|
+
profile?: string;
|
|
108
|
+
}): OutboxBinding | null;
|
|
109
|
+
/** Does this entry record both where and as whom it was queued? */
|
|
110
|
+
export declare function isOutboxBound(entry: Pick<OutboxEntry, 'origin' | 'account'>): entry is {
|
|
111
|
+
origin: string;
|
|
112
|
+
account: string;
|
|
113
|
+
};
|
|
114
|
+
/** The context a replay sent from this process would run in. */
|
|
115
|
+
export interface ReplayContext {
|
|
116
|
+
/** Null when the configured server is not an HTTP(S) origin. */
|
|
117
|
+
origin: string | null;
|
|
118
|
+
account: string;
|
|
119
|
+
}
|
|
120
|
+
export declare function currentReplayContext(input: {
|
|
121
|
+
baseURL: string | null | undefined;
|
|
122
|
+
token: string | null | undefined;
|
|
123
|
+
profile?: string;
|
|
124
|
+
}): ReplayContext;
|
|
125
|
+
export interface ReplayContextFinding {
|
|
126
|
+
field: 'server' | 'account' | 'workspace';
|
|
127
|
+
recorded: string;
|
|
128
|
+
current: string;
|
|
129
|
+
}
|
|
130
|
+
export type ReplayContextVerdict =
|
|
131
|
+
/** Queued before origin binding: nothing proves where it was meant to go. */
|
|
132
|
+
{
|
|
133
|
+
state: 'unverified';
|
|
134
|
+
} | {
|
|
135
|
+
state: 'match';
|
|
136
|
+
} | {
|
|
137
|
+
state: 'mismatch';
|
|
138
|
+
findings: ReplayContextFinding[];
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* May this entry be replayed from `current`?
|
|
142
|
+
*
|
|
143
|
+
* The workspace is not read from `current`: it is whatever `apiFetch` would put
|
|
144
|
+
* on the request, which is the entry's own header when it recorded one and the
|
|
145
|
+
* ambient workspace otherwise (an Agent session replaces even the recorded one).
|
|
146
|
+
* An entry queued with no workspace that is replayed while one is selected would
|
|
147
|
+
* land somewhere it was never authored for.
|
|
148
|
+
*/
|
|
149
|
+
export declare function assessReplayContext(entry: OutboxEntry, current: ReplayContext, env?: Record<string, string | undefined>): ReplayContextVerdict;
|
|
150
|
+
/**
|
|
151
|
+
* A recorded value, safe to print. The file is the user's and can be edited or
|
|
152
|
+
* damaged, so a control or format character is shown as a visible `\uXXXX`
|
|
153
|
+
* rather than drawn.
|
|
154
|
+
*/
|
|
155
|
+
export declare function printableOutboxField(value: string): string;
|
|
156
|
+
/** "recorded server https://a, current server https://b; recorded account ..." */
|
|
157
|
+
export declare function describeReplayFindings(findings: readonly ReplayContextFinding[]): string;
|
|
49
158
|
/** One replay at a time; unlike the short queue lock, this spans network calls. */
|
|
50
159
|
export declare function lockOutboxReplay(profile?: string): Promise<() => Promise<void>>;
|
|
51
160
|
export declare class OutboxFullError extends Error {
|