@skrr-ai/cli 0.1.179 → 0.1.180
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/dist/commands/code/index.js +5 -0
- package/dist/commands/diagnostics/inference-smoke.d.ts +13 -0
- package/dist/commands/diagnostics/inference-smoke.js +50 -0
- package/dist/commands/harnesses/evaluations/evidence.d.ts +2 -0
- package/dist/commands/harnesses/evaluations/evidence.js +20 -0
- package/dist/commands/harnesses/evaluations/fixed-tool.d.ts +10 -0
- package/dist/commands/harnesses/evaluations/fixed-tool.js +189 -0
- package/dist/commands/harnesses/evaluations/platform-h9-turn.d.ts +13 -0
- package/dist/commands/harnesses/evaluations/platform-h9-turn.js +322 -0
- package/dist/commands/machines/hosted/identity-evaluations/issue.d.ts +12 -0
- package/dist/commands/machines/hosted/identity-evaluations/issue.js +40 -0
- package/dist/commands/machines/hosted/identity-evaluations/revoke.d.ts +11 -0
- package/dist/commands/machines/hosted/identity-evaluations/revoke.js +21 -0
- package/dist/commands/machines/hosted/identity-evaluations/show.d.ts +8 -0
- package/dist/commands/machines/hosted/identity-evaluations/show.js +20 -0
- package/dist/commands/machines/hosted/start.d.ts +1 -0
- package/dist/commands/machines/hosted/start.js +6 -0
- package/dist/lib/agentic-stream.d.ts +3 -0
- package/dist/lib/agentic-stream.js +63 -1
- package/dist/lib/copilot-fixed-probe-runner.d.ts +72 -0
- package/dist/lib/copilot-fixed-probe-runner.js +213 -0
- package/dist/lib/copilot-fixed-probe.d.ts +61 -0
- package/dist/lib/copilot-fixed-probe.js +223 -0
- package/dist/lib/first-party-harness-broker.d.ts +5 -0
- package/dist/lib/first-party-harness-broker.js +99 -0
- package/dist/lib/h9-platform-stream.d.ts +63 -0
- package/dist/lib/h9-platform-stream.js +317 -0
- package/dist/lib/h9-prior-stream.d.ts +44 -0
- package/dist/lib/h9-prior-stream.js +217 -0
- package/dist/lib/harness-evaluations.d.ts +85 -0
- package/dist/lib/harness-evaluations.js +8 -0
- package/dist/lib/hosted-identity-evaluations.d.ts +26 -0
- package/dist/lib/hosted-identity-evaluations.js +18 -0
- package/dist/lib/hosted-machines.d.ts +1 -0
- package/dist/lib/inference-overload-smoke-contract.d.ts +53 -0
- package/dist/lib/inference-overload-smoke-contract.js +192 -0
- package/dist/lib/inference-overload-smoke.d.ts +78 -0
- package/dist/lib/inference-overload-smoke.js +350 -0
- package/dist/lib/operator-probe-files.d.ts +6 -0
- package/dist/lib/operator-probe-files.js +68 -0
- package/dist/lib/platform-h9-plan.d.ts +47 -0
- package/dist/lib/platform-h9-plan.js +78 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/codex-model-catalog.json +150 -0
- package/dist/node_modules/@skrr-ai/data-provider/index.js +6 -6
- package/dist/node_modules/@skrr-ai/inference-broker/dist/cjs/index.d.ts +3 -1
- package/dist/node_modules/@skrr-ai/inference-broker/dist/cjs/index.js +23 -1
- package/dist/node_modules/@skrr-ai/inference-broker/dist/cjs/managed-haiku-none.d.ts +8 -0
- package/dist/node_modules/@skrr-ai/inference-broker/dist/cjs/managed-haiku-none.js +40 -0
- package/dist/node_modules/@skrr-ai/inference-broker/dist/cjs/managed-inference-broker.d.ts +2 -11
- package/dist/node_modules/@skrr-ai/inference-broker/dist/cjs/managed-inference-broker.js +31 -5
- package/dist/node_modules/@skrr-ai/inference-broker/dist/cjs/overload-smoke.d.ts +56 -0
- package/dist/node_modules/@skrr-ai/inference-broker/dist/cjs/overload-smoke.js +277 -0
- package/dist/node_modules/@skrr-ai/inference-broker/dist/esm/index.d.ts +3 -1
- package/dist/node_modules/@skrr-ai/inference-broker/dist/esm/index.js +3 -1
- package/dist/node_modules/@skrr-ai/inference-broker/dist/esm/managed-haiku-none.d.ts +8 -0
- package/dist/node_modules/@skrr-ai/inference-broker/dist/esm/managed-haiku-none.js +20 -0
- package/dist/node_modules/@skrr-ai/inference-broker/dist/esm/managed-inference-broker.d.ts +2 -11
- package/dist/node_modules/@skrr-ai/inference-broker/dist/esm/managed-inference-broker.js +28 -4
- package/dist/node_modules/@skrr-ai/inference-broker/dist/esm/overload-smoke.d.ts +56 -0
- package/dist/node_modules/@skrr-ai/inference-broker/dist/esm/overload-smoke.js +261 -0
- package/oclif.manifest.json +473 -1
- package/package.json +2 -2
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { FixedCopilotPermission } from './copilot-fixed-probe';
|
|
2
|
+
type Row = Record<string, any>;
|
|
3
|
+
export interface CopilotProbePlan {
|
|
4
|
+
schema: 'copilot-fixed-tool-plan.v1';
|
|
5
|
+
operationId: string;
|
|
6
|
+
ownerUserId: string;
|
|
7
|
+
workspaceId: string;
|
|
8
|
+
grantId: string;
|
|
9
|
+
agentId: string;
|
|
10
|
+
harnessId: string;
|
|
11
|
+
daemonId: string;
|
|
12
|
+
version: '1.0.112';
|
|
13
|
+
model: string;
|
|
14
|
+
image: string;
|
|
15
|
+
nonce: string;
|
|
16
|
+
expiresAt: string;
|
|
17
|
+
maxDurationMs: 90000;
|
|
18
|
+
maxSpendUsd: number;
|
|
19
|
+
paidOperationApproved: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare function validateCopilotProbePlan(value: unknown): CopilotProbePlan;
|
|
22
|
+
/** Ordinary authenticated GET results. A caller's plan/image labels are never attestation. */
|
|
23
|
+
export declare function validateCopilotProbePreflight(p: CopilotProbePlan, principal: string, records: {
|
|
24
|
+
grant: Row;
|
|
25
|
+
agent: Row;
|
|
26
|
+
harness: Row;
|
|
27
|
+
machine: Row;
|
|
28
|
+
}, now?: number): void;
|
|
29
|
+
export interface CopilotProbeTransport {
|
|
30
|
+
principal(): Promise<string>;
|
|
31
|
+
inspect(plan: CopilotProbePlan): Promise<{
|
|
32
|
+
grant: Row;
|
|
33
|
+
agent: Row;
|
|
34
|
+
harness: Row;
|
|
35
|
+
machine: Row;
|
|
36
|
+
}>;
|
|
37
|
+
/** Exactly one normal start call. A lost response is UNKNOWN, never a new request. */
|
|
38
|
+
start(body: Row, deadline: number): Promise<Row>;
|
|
39
|
+
stream(accepted: Row, permission: FixedCopilotPermission, deadline: number): Promise<Row>;
|
|
40
|
+
cancel(accepted: Row): Promise<void>;
|
|
41
|
+
persist(value: Row): void;
|
|
42
|
+
now?: () => number;
|
|
43
|
+
}
|
|
44
|
+
/** No grant, Agent, machine, policy, credential or permission-mode mutation is performed here. */
|
|
45
|
+
export declare function runCopilotFixedProbe(p: CopilotProbePlan, transport: CopilotProbeTransport): Promise<{
|
|
46
|
+
billingClosureClaimed: boolean;
|
|
47
|
+
h9AdmissionClaimed: boolean;
|
|
48
|
+
cloudH1Claimed: boolean;
|
|
49
|
+
ownedResourcesDeleted: boolean;
|
|
50
|
+
permissionRecorded: boolean;
|
|
51
|
+
toolVerified: boolean;
|
|
52
|
+
failure: string | null;
|
|
53
|
+
toolUseId: string | null;
|
|
54
|
+
requestId: string | null;
|
|
55
|
+
interactiveAdmission: import("./copilot-fixed-probe").InteractiveAdmission;
|
|
56
|
+
autonomousRunClaimed: boolean;
|
|
57
|
+
autonomousAttemptClaimed: boolean;
|
|
58
|
+
approvalSource: string;
|
|
59
|
+
schema: string;
|
|
60
|
+
clientRequestId: string;
|
|
61
|
+
grantId: string;
|
|
62
|
+
agentId: string;
|
|
63
|
+
daemonId: string;
|
|
64
|
+
image: string;
|
|
65
|
+
model: string;
|
|
66
|
+
sessionId: any;
|
|
67
|
+
conversationId: any;
|
|
68
|
+
responseMessageId: any;
|
|
69
|
+
outcome: string;
|
|
70
|
+
runtimeStartObserved: boolean;
|
|
71
|
+
}>;
|
|
72
|
+
export {};
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateCopilotProbePlan = validateCopilotProbePlan;
|
|
4
|
+
exports.validateCopilotProbePreflight = validateCopilotProbePreflight;
|
|
5
|
+
exports.runCopilotFixedProbe = runCopilotFixedProbe;
|
|
6
|
+
const copilot_fixed_probe_1 = require("./copilot-fixed-probe");
|
|
7
|
+
const agent_chat_start_1 = require("./agent-chat-start");
|
|
8
|
+
const need = (ok, code) => {
|
|
9
|
+
if (!ok)
|
|
10
|
+
throw new Error(code);
|
|
11
|
+
};
|
|
12
|
+
const id = (value) => typeof value === 'string' && /^[A-Za-z0-9][A-Za-z0-9_.:@-]{0,239}$/.test(value);
|
|
13
|
+
function validateCopilotProbePlan(value) {
|
|
14
|
+
const p = value;
|
|
15
|
+
const keys = [
|
|
16
|
+
'schema',
|
|
17
|
+
'operationId',
|
|
18
|
+
'ownerUserId',
|
|
19
|
+
'workspaceId',
|
|
20
|
+
'grantId',
|
|
21
|
+
'agentId',
|
|
22
|
+
'harnessId',
|
|
23
|
+
'daemonId',
|
|
24
|
+
'version',
|
|
25
|
+
'model',
|
|
26
|
+
'image',
|
|
27
|
+
'nonce',
|
|
28
|
+
'expiresAt',
|
|
29
|
+
'maxDurationMs',
|
|
30
|
+
'maxSpendUsd',
|
|
31
|
+
'paidOperationApproved',
|
|
32
|
+
];
|
|
33
|
+
need(p &&
|
|
34
|
+
typeof p === 'object' &&
|
|
35
|
+
!Array.isArray(p) &&
|
|
36
|
+
JSON.stringify(Object.keys(p).sort()) === JSON.stringify(keys.sort()), 'PROBE_PLAN_SHAPE');
|
|
37
|
+
need(p.schema === 'copilot-fixed-tool-plan.v1' &&
|
|
38
|
+
p.version === '1.0.112' &&
|
|
39
|
+
[
|
|
40
|
+
'operationId',
|
|
41
|
+
'ownerUserId',
|
|
42
|
+
'workspaceId',
|
|
43
|
+
'grantId',
|
|
44
|
+
'agentId',
|
|
45
|
+
'harnessId',
|
|
46
|
+
'daemonId',
|
|
47
|
+
'model',
|
|
48
|
+
'image',
|
|
49
|
+
].every((k) => id(p[k])) &&
|
|
50
|
+
p.maxDurationMs === 90000 &&
|
|
51
|
+
Number.isFinite(p.maxSpendUsd) &&
|
|
52
|
+
p.maxSpendUsd >= 0 &&
|
|
53
|
+
typeof p.paidOperationApproved === 'boolean' &&
|
|
54
|
+
typeof p.expiresAt === 'string' &&
|
|
55
|
+
p.expiresAt.endsWith('Z') &&
|
|
56
|
+
Number.isFinite(Date.parse(p.expiresAt)), 'PROBE_PLAN_VALUES');
|
|
57
|
+
(0, copilot_fixed_probe_1.fixedCopilotCommand)(p.nonce);
|
|
58
|
+
need((0, agent_chat_start_1.isValidStartKey)(`copilot-fixed:${p.operationId}`), 'PROBE_START_IDENTITY_INVALID');
|
|
59
|
+
return Object.freeze({ ...p });
|
|
60
|
+
}
|
|
61
|
+
/** Ordinary authenticated GET results. A caller's plan/image labels are never attestation. */
|
|
62
|
+
function validateCopilotProbePreflight(p, principal, records, now = Date.now()) {
|
|
63
|
+
const { grant: g, agent: a, harness: h, machine: m } = records;
|
|
64
|
+
need(principal === p.ownerUserId && g.ownerUserId === principal, 'PROBE_OWNER_MISMATCH');
|
|
65
|
+
need(p.paidOperationApproved &&
|
|
66
|
+
p.maxSpendUsd > 0 &&
|
|
67
|
+
Date.parse(p.expiresAt) > now &&
|
|
68
|
+
Date.parse(p.expiresAt) <= now + 600000, 'PROBE_OPERATIONAL_GO_REQUIRED');
|
|
69
|
+
need(g.grantId === p.grantId &&
|
|
70
|
+
g.harness === 'copilot-sdk' &&
|
|
71
|
+
g.version === p.version &&
|
|
72
|
+
g.daemonId === p.daemonId &&
|
|
73
|
+
g.state === 'active' &&
|
|
74
|
+
g.active === true &&
|
|
75
|
+
typeof g.expiresAt === 'string' &&
|
|
76
|
+
Date.parse(g.expiresAt) >= now + p.maxDurationMs &&
|
|
77
|
+
Array.isArray(g.models) &&
|
|
78
|
+
g.models.length === 1 &&
|
|
79
|
+
g.models[0] === p.model &&
|
|
80
|
+
Array.isArray(g.admissions) &&
|
|
81
|
+
g.admissions.length === 0 &&
|
|
82
|
+
Number.isFinite(g.maxSpendUsd) &&
|
|
83
|
+
g.maxSpendUsd > 0 &&
|
|
84
|
+
g.maxSpendUsd <= p.maxSpendUsd, 'PROBE_DEDICATED_EVALUATION_GRANT_REQUIRED');
|
|
85
|
+
const targets = a.executionPolicy?.targets?.filter((x) => x.enabled !== false);
|
|
86
|
+
need((a.id ?? a.agent_id) === p.agentId &&
|
|
87
|
+
a.model === p.model &&
|
|
88
|
+
a.author === principal &&
|
|
89
|
+
a.executionPolicy?.mode === 'ordered' &&
|
|
90
|
+
targets?.length === 1 &&
|
|
91
|
+
targets[0].kind === 'harness' &&
|
|
92
|
+
targets[0].harnessId === p.harnessId &&
|
|
93
|
+
(targets[0].advanceOn?.length ?? 0) === 0, 'PROBE_SOLE_HARNESS_REQUIRED');
|
|
94
|
+
need((h.id ?? h._id) === p.harnessId &&
|
|
95
|
+
h.provider === 'copilot-sdk' &&
|
|
96
|
+
h.daemonId === p.daemonId &&
|
|
97
|
+
h.metadata?.cliVersion === p.version &&
|
|
98
|
+
h.metadata?.evaluation?.grantId === p.grantId &&
|
|
99
|
+
h.metadata?.evaluation?.version === p.version, 'PROBE_HARNESS_BINDING');
|
|
100
|
+
need(m.daemonId === p.daemonId &&
|
|
101
|
+
m.image === p.image &&
|
|
102
|
+
!m.unavailable &&
|
|
103
|
+
['hosted-machine', 'dedicated-machine'].includes(m.machineProduct), 'PROBE_ATTESTED_IMAGE_REQUIRED');
|
|
104
|
+
}
|
|
105
|
+
/** No grant, Agent, machine, policy, credential or permission-mode mutation is performed here. */
|
|
106
|
+
async function runCopilotFixedProbe(p, transport) {
|
|
107
|
+
const now = transport.now ?? Date.now;
|
|
108
|
+
validateCopilotProbePreflight(p, await transport.principal(), await transport.inspect(p), now());
|
|
109
|
+
const clientRequestId = `copilot-fixed:${p.operationId}`;
|
|
110
|
+
// Persist the only request identity before dispatch. No model retry/recovery under a new key.
|
|
111
|
+
transport.persist({
|
|
112
|
+
state: 'start-may-be-unacknowledged',
|
|
113
|
+
clientRequestId,
|
|
114
|
+
agentId: p.agentId,
|
|
115
|
+
grantId: p.grantId,
|
|
116
|
+
daemonId: p.daemonId,
|
|
117
|
+
image: p.image,
|
|
118
|
+
});
|
|
119
|
+
const deadline = Math.min(now() + p.maxDurationMs, Date.parse(p.expiresAt));
|
|
120
|
+
const accepted = await transport.start({
|
|
121
|
+
agentId: p.agentId,
|
|
122
|
+
workspaceId: p.workspaceId,
|
|
123
|
+
conversationId: 'new',
|
|
124
|
+
clientRequestId,
|
|
125
|
+
executionEnvironment: 'local',
|
|
126
|
+
preferredDaemonId: p.daemonId,
|
|
127
|
+
permissionMode: 'default',
|
|
128
|
+
text: `Use Bash exactly once to run exactly: ${(0, copilot_fixed_probe_1.fixedCopilotCommand)(p.nonce)}. ` +
|
|
129
|
+
'Use no other tools. Then reply with the printed value.',
|
|
130
|
+
}, deadline);
|
|
131
|
+
let cancellationAttempted = false;
|
|
132
|
+
const cancelOnce = async () => {
|
|
133
|
+
if (cancellationAttempted || !id(accepted.sessionId))
|
|
134
|
+
return;
|
|
135
|
+
cancellationAttempted = true;
|
|
136
|
+
try {
|
|
137
|
+
await transport.cancel(accepted);
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
transport.persist({
|
|
141
|
+
state: 'cancellation-unconfirmed',
|
|
142
|
+
clientRequestId,
|
|
143
|
+
sessionId: accepted.sessionId,
|
|
144
|
+
physicalStopConfirmed: false,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
try {
|
|
149
|
+
need(accepted.success === true &&
|
|
150
|
+
id(accepted.sessionId) &&
|
|
151
|
+
id(accepted.conversationId) &&
|
|
152
|
+
id(accepted.responseMessageId) &&
|
|
153
|
+
accepted.workspaceId === p.workspaceId, 'PROBE_ACCEPTANCE_MISMATCH');
|
|
154
|
+
need(accepted.runtime?.mode === 'local' &&
|
|
155
|
+
accepted.runtime?.provider === 'copilot-sdk' &&
|
|
156
|
+
accepted.runtime?.daemonId === p.daemonId &&
|
|
157
|
+
accepted.runtime?.agentRuntime === p.harnessId &&
|
|
158
|
+
accepted.runtime?.executionPlan?.selectedExecutionSelector === p.harnessId &&
|
|
159
|
+
accepted.runtime?.executionPlan?.fallbackUsed === false, 'PROBE_ACCEPTED_RUNTIME_MISMATCH');
|
|
160
|
+
const context = (0, copilot_fixed_probe_1.interactiveAdmission)(accepted.interactiveAdmission);
|
|
161
|
+
need(context.sessionId === accepted.sessionId &&
|
|
162
|
+
context.responseMessageId === accepted.responseMessageId, 'PROBE_ACCEPTANCE_CONTEXT_MISMATCH');
|
|
163
|
+
const permission = new copilot_fixed_probe_1.FixedCopilotPermission(context, p.nonce, deadline, now);
|
|
164
|
+
transport.persist({
|
|
165
|
+
state: 'accepted',
|
|
166
|
+
clientRequestId,
|
|
167
|
+
sessionId: accepted.sessionId,
|
|
168
|
+
conversationId: accepted.conversationId,
|
|
169
|
+
responseMessageId: accepted.responseMessageId,
|
|
170
|
+
interactiveAdmission: context,
|
|
171
|
+
});
|
|
172
|
+
const result = await transport.stream(accepted, permission, deadline);
|
|
173
|
+
const facts = permission.result();
|
|
174
|
+
const receipt = {
|
|
175
|
+
schema: 'copilot-fixed-tool-result.v1',
|
|
176
|
+
clientRequestId,
|
|
177
|
+
grantId: p.grantId,
|
|
178
|
+
agentId: p.agentId,
|
|
179
|
+
daemonId: p.daemonId,
|
|
180
|
+
image: p.image,
|
|
181
|
+
model: p.model,
|
|
182
|
+
sessionId: accepted.sessionId,
|
|
183
|
+
conversationId: accepted.conversationId,
|
|
184
|
+
responseMessageId: accepted.responseMessageId,
|
|
185
|
+
outcome: result.status === 'completed' && result.runtimeStartObserved === true && facts.toolVerified
|
|
186
|
+
? 'fixed-tool-observed'
|
|
187
|
+
: 'inconclusive',
|
|
188
|
+
runtimeStartObserved: result.runtimeStartObserved === true,
|
|
189
|
+
...facts,
|
|
190
|
+
billingClosureClaimed: false,
|
|
191
|
+
h9AdmissionClaimed: false,
|
|
192
|
+
cloudH1Claimed: false,
|
|
193
|
+
ownedResourcesDeleted: false,
|
|
194
|
+
};
|
|
195
|
+
transport.persist(receipt);
|
|
196
|
+
if (receipt.outcome !== 'fixed-tool-observed')
|
|
197
|
+
await cancelOnce();
|
|
198
|
+
return receipt;
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
// A response from an older server may name a live turn but no new context.
|
|
202
|
+
// Never leave that turn running merely because this client refuses approval.
|
|
203
|
+
transport.persist({
|
|
204
|
+
state: 'inconclusive-cleanup-required',
|
|
205
|
+
clientRequestId,
|
|
206
|
+
...(id(accepted.sessionId) ? { sessionId: accepted.sessionId } : {}),
|
|
207
|
+
...(id(accepted.responseMessageId) ? { responseMessageId: accepted.responseMessageId } : {}),
|
|
208
|
+
physicalStopConfirmed: false,
|
|
209
|
+
});
|
|
210
|
+
await cancelOnce();
|
|
211
|
+
throw error;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/** OSK-24469: one fixed permission response, never a session/tool-policy grant.
|
|
2
|
+
* All identities come from the authenticated normal admission and its server ask.
|
|
3
|
+
* An interactive generation is NOT an autonomous run or attempt identifier.
|
|
4
|
+
*/
|
|
5
|
+
export type InteractiveAdmission = {
|
|
6
|
+
version: 1;
|
|
7
|
+
kind: 'interactive';
|
|
8
|
+
sessionId: string;
|
|
9
|
+
responseMessageId: string;
|
|
10
|
+
generation: string;
|
|
11
|
+
};
|
|
12
|
+
export type InteractivePermissionAdmission = InteractiveAdmission & {
|
|
13
|
+
requestId: string;
|
|
14
|
+
};
|
|
15
|
+
type Frame = Record<string, unknown>;
|
|
16
|
+
export declare function interactiveAdmission(value: unknown): InteractiveAdmission;
|
|
17
|
+
export declare function fixedCopilotCommand(nonce: string): string;
|
|
18
|
+
export declare function copilotPlatformScratchDirectory(nonce: string): string;
|
|
19
|
+
/** Create a private, non-existing directory and remove it before reporting successful exit. */
|
|
20
|
+
export declare function copilotPlatformScratchCommand(nonce: string): string;
|
|
21
|
+
/** Constructed only after normal authenticated owner/grant/image/sole-Harness checks. */
|
|
22
|
+
export declare class FixedCopilotPermission {
|
|
23
|
+
private readonly deadline;
|
|
24
|
+
private readonly now;
|
|
25
|
+
private readonly matchesOutput;
|
|
26
|
+
private readonly platformCopilotScratch;
|
|
27
|
+
private readonly admission;
|
|
28
|
+
private readonly command;
|
|
29
|
+
private readonly output;
|
|
30
|
+
private claimed;
|
|
31
|
+
private announced;
|
|
32
|
+
private recorded;
|
|
33
|
+
private completed;
|
|
34
|
+
private failure;
|
|
35
|
+
private stopped;
|
|
36
|
+
constructor(admission: unknown, nonce: string, deadline: number, now?: () => number, matchesOutput?: (actual: unknown, expected: string) => boolean, platformCopilotScratch?: boolean);
|
|
37
|
+
stop(reason?: string): void;
|
|
38
|
+
close(): void;
|
|
39
|
+
get refused(): boolean;
|
|
40
|
+
/** The exact answered/admitted notice dismisses the prompt without proving execution. */
|
|
41
|
+
answerNotice(frame: Frame): boolean;
|
|
42
|
+
private refuse;
|
|
43
|
+
private active;
|
|
44
|
+
private tool;
|
|
45
|
+
/** Synchronous consumption happens BEFORE any asynchronous decision transport. */
|
|
46
|
+
decide(frame: Frame): boolean;
|
|
47
|
+
decisionReceipt(frame: Frame, approved: boolean, receipt: Frame): void;
|
|
48
|
+
observe(frame: Frame): void;
|
|
49
|
+
result(): {
|
|
50
|
+
permissionRecorded: boolean;
|
|
51
|
+
toolVerified: boolean;
|
|
52
|
+
failure: string | null;
|
|
53
|
+
toolUseId: string | null;
|
|
54
|
+
requestId: string | null;
|
|
55
|
+
interactiveAdmission: InteractiveAdmission;
|
|
56
|
+
autonomousRunClaimed: boolean;
|
|
57
|
+
autonomousAttemptClaimed: boolean;
|
|
58
|
+
approvalSource: string;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FixedCopilotPermission = void 0;
|
|
4
|
+
exports.interactiveAdmission = interactiveAdmission;
|
|
5
|
+
exports.fixedCopilotCommand = fixedCopilotCommand;
|
|
6
|
+
exports.copilotPlatformScratchDirectory = copilotPlatformScratchDirectory;
|
|
7
|
+
exports.copilotPlatformScratchCommand = copilotPlatformScratchCommand;
|
|
8
|
+
const object = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
9
|
+
const exact = (value, keys) => JSON.stringify(Object.keys(value).sort()) === JSON.stringify([...keys].sort());
|
|
10
|
+
const text = (value) => typeof value === 'string' && /^[A-Za-z0-9][A-Za-z0-9_.:@-]{0,239}$/.test(value);
|
|
11
|
+
function interactiveAdmission(value) {
|
|
12
|
+
if (!object(value) ||
|
|
13
|
+
!exact(value, ['version', 'kind', 'sessionId', 'responseMessageId', 'generation']) ||
|
|
14
|
+
value.version !== 1 ||
|
|
15
|
+
value.kind !== 'interactive' ||
|
|
16
|
+
!text(value.sessionId) ||
|
|
17
|
+
!text(value.responseMessageId) ||
|
|
18
|
+
typeof value.generation !== 'string' ||
|
|
19
|
+
!/^[a-f0-9]{64}$/.test(value.generation))
|
|
20
|
+
throw new Error('PROBE_INTERACTIVE_ADMISSION_REQUIRED');
|
|
21
|
+
return { ...value };
|
|
22
|
+
}
|
|
23
|
+
function requireProbeNonce(nonce) {
|
|
24
|
+
if (!/^[a-f0-9]{32}$/.test(nonce))
|
|
25
|
+
throw new Error('PROBE_NONCE_INVALID');
|
|
26
|
+
}
|
|
27
|
+
function fixedCopilotCommand(nonce) {
|
|
28
|
+
requireProbeNonce(nonce);
|
|
29
|
+
return `printf '%s\\n' 'COPILOT-PROBE-${nonce}'`;
|
|
30
|
+
}
|
|
31
|
+
function copilotPlatformScratchDirectory(nonce) {
|
|
32
|
+
requireProbeNonce(nonce);
|
|
33
|
+
return `/tmp/osk-copilot-h9-${nonce}`;
|
|
34
|
+
}
|
|
35
|
+
/** Create a private, non-existing directory and remove it before reporting successful exit. */
|
|
36
|
+
function copilotPlatformScratchCommand(nonce) {
|
|
37
|
+
const scratch = copilotPlatformScratchDirectory(nonce);
|
|
38
|
+
const marker = `${scratch}/marker`;
|
|
39
|
+
return `(umask 077; mkdir -- '${scratch}' || exit; trap 'rm -f -- "${marker}"; rmdir -- "${scratch}"' EXIT; output=$(${fixedCopilotCommand(nonce)} | tee -- '${marker}') || exit; rm -- '${marker}' && rmdir -- '${scratch}' || exit; trap - EXIT; printf '%s\\n' "$output")`;
|
|
40
|
+
}
|
|
41
|
+
/** Constructed only after normal authenticated owner/grant/image/sole-Harness checks. */
|
|
42
|
+
class FixedCopilotPermission {
|
|
43
|
+
deadline;
|
|
44
|
+
now;
|
|
45
|
+
matchesOutput;
|
|
46
|
+
platformCopilotScratch;
|
|
47
|
+
admission;
|
|
48
|
+
command;
|
|
49
|
+
output;
|
|
50
|
+
claimed = null;
|
|
51
|
+
announced = null;
|
|
52
|
+
recorded = false;
|
|
53
|
+
completed = false;
|
|
54
|
+
failure = null;
|
|
55
|
+
stopped = false;
|
|
56
|
+
constructor(admission, nonce, deadline, now = Date.now, matchesOutput = (actual, expected) => actual === expected, platformCopilotScratch = false) {
|
|
57
|
+
this.deadline = deadline;
|
|
58
|
+
this.now = now;
|
|
59
|
+
this.matchesOutput = matchesOutput;
|
|
60
|
+
this.platformCopilotScratch = platformCopilotScratch;
|
|
61
|
+
this.admission = interactiveAdmission(admission);
|
|
62
|
+
this.command = platformCopilotScratch
|
|
63
|
+
? copilotPlatformScratchCommand(nonce)
|
|
64
|
+
: fixedCopilotCommand(nonce);
|
|
65
|
+
this.output = `COPILOT-PROBE-${nonce}\n`;
|
|
66
|
+
if (!Number.isFinite(deadline) || deadline <= now() || deadline > now() + 120_000)
|
|
67
|
+
throw new Error('PROBE_DEADLINE_INVALID');
|
|
68
|
+
}
|
|
69
|
+
stop(reason = 'PROBE_CANCELLED') {
|
|
70
|
+
this.stopped = true;
|
|
71
|
+
this.failure ??= reason;
|
|
72
|
+
}
|
|
73
|
+
close() {
|
|
74
|
+
this.stopped = true;
|
|
75
|
+
}
|
|
76
|
+
get refused() {
|
|
77
|
+
return this.failure !== null;
|
|
78
|
+
}
|
|
79
|
+
/** The exact answered/admitted notice dismisses the prompt without proving execution. */
|
|
80
|
+
answerNotice(frame) {
|
|
81
|
+
const binding = frame.permissionBinding;
|
|
82
|
+
return (this.active() &&
|
|
83
|
+
!!this.claimed &&
|
|
84
|
+
(frame.reason === 'answered' ||
|
|
85
|
+
(frame.reason === 'response_admitted' && frame.executionConfirmed === false)) &&
|
|
86
|
+
frame.sessionId === this.admission.sessionId &&
|
|
87
|
+
frame.toolUseId === this.claimed.toolUseId &&
|
|
88
|
+
object(binding) &&
|
|
89
|
+
binding.epoch === this.admission.generation &&
|
|
90
|
+
binding.requestId === this.claimed.requestId);
|
|
91
|
+
}
|
|
92
|
+
refuse(reason) {
|
|
93
|
+
this.failure ??= reason;
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
active() {
|
|
97
|
+
return !this.stopped && !this.failure && this.now() < this.deadline;
|
|
98
|
+
}
|
|
99
|
+
tool(frame, observedStart = false) {
|
|
100
|
+
const input = frame.toolInput;
|
|
101
|
+
return (typeof frame.toolName === 'string' &&
|
|
102
|
+
/^(bash|Bash)$/.test(frame.toolName) &&
|
|
103
|
+
text(frame.toolUseId) &&
|
|
104
|
+
object(input) &&
|
|
105
|
+
input.command === this.command &&
|
|
106
|
+
(exact(input, ['command']) ||
|
|
107
|
+
(observedStart &&
|
|
108
|
+
this.platformCopilotScratch &&
|
|
109
|
+
exact(input, ['command', 'description']) &&
|
|
110
|
+
typeof input.description === 'string' &&
|
|
111
|
+
Buffer.byteLength(input.description) <= 256)));
|
|
112
|
+
}
|
|
113
|
+
/** Synchronous consumption happens BEFORE any asynchronous decision transport. */
|
|
114
|
+
decide(frame) {
|
|
115
|
+
if (!this.active())
|
|
116
|
+
return this.refuse('PROBE_CLOSED_OR_EXPIRED');
|
|
117
|
+
const context = frame.interactiveAdmission;
|
|
118
|
+
const binding = frame.permissionBinding;
|
|
119
|
+
if (frame.sessionId !== this.admission.sessionId ||
|
|
120
|
+
frame.purpose !== undefined ||
|
|
121
|
+
frame.runtimeElicitation !== undefined ||
|
|
122
|
+
frame.decisionStatus !== undefined ||
|
|
123
|
+
!this.tool(frame) ||
|
|
124
|
+
!object(context) ||
|
|
125
|
+
!exact(context, [
|
|
126
|
+
'version',
|
|
127
|
+
'kind',
|
|
128
|
+
'sessionId',
|
|
129
|
+
'responseMessageId',
|
|
130
|
+
'generation',
|
|
131
|
+
'requestId',
|
|
132
|
+
]) ||
|
|
133
|
+
!object(binding) ||
|
|
134
|
+
!exact(binding, ['epoch', 'requestId']) ||
|
|
135
|
+
!text(binding.requestId) ||
|
|
136
|
+
context.version !== 1 ||
|
|
137
|
+
context.kind !== 'interactive' ||
|
|
138
|
+
context.sessionId !== this.admission.sessionId ||
|
|
139
|
+
context.responseMessageId !== this.admission.responseMessageId ||
|
|
140
|
+
context.generation !== this.admission.generation ||
|
|
141
|
+
binding.epoch !== this.admission.generation ||
|
|
142
|
+
context.requestId !== binding.requestId ||
|
|
143
|
+
typeof frame.timeoutAt !== 'number' ||
|
|
144
|
+
!Number.isFinite(frame.timeoutAt) ||
|
|
145
|
+
frame.timeoutAt <= this.now())
|
|
146
|
+
return this.refuse('PROBE_PERMISSION_MISMATCH');
|
|
147
|
+
if (this.claimed || (this.announced && this.announced !== frame.toolUseId))
|
|
148
|
+
return this.refuse('PROBE_ADDITIONAL_REQUEST');
|
|
149
|
+
this.claimed = { toolUseId: frame.toolUseId, requestId: binding.requestId };
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
decisionReceipt(frame, approved, receipt) {
|
|
153
|
+
if (!approved ||
|
|
154
|
+
!this.active() ||
|
|
155
|
+
!this.claimed ||
|
|
156
|
+
frame.toolUseId !== this.claimed.toolUseId ||
|
|
157
|
+
receipt.type !== 'permission.response_recorded' ||
|
|
158
|
+
receipt.duplicate === true ||
|
|
159
|
+
typeof receipt.status !== 'string' ||
|
|
160
|
+
!['recorded', 'admitted'].includes(receipt.status)) {
|
|
161
|
+
this.refuse('PROBE_DECISION_UNCONFIRMED');
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
this.recorded = true; // A response receipt alone never sets completed.
|
|
165
|
+
}
|
|
166
|
+
observe(frame) {
|
|
167
|
+
if (typeof frame.type !== 'string') {
|
|
168
|
+
this.stop('PROBE_MALFORMED_EVENT');
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (['stream.gap', 'transport.error', 'run.handed_over', 'text.reset'].includes(String(frame.type))) {
|
|
172
|
+
this.stop('PROBE_TRANSPORT_CONTEXT_LOST');
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (!['tool.started', 'tool.completed', 'run.cancel_requested', 'permission.cancelled'].includes(String(frame.type)))
|
|
176
|
+
return;
|
|
177
|
+
if (frame.type === 'run.cancel_requested' || frame.type === 'permission.cancelled') {
|
|
178
|
+
this.stop();
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (!this.active() || frame.sessionId !== this.admission.sessionId) {
|
|
182
|
+
this.refuse('PROBE_TOOL_CONTEXT_MISMATCH');
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (frame.type === 'tool.started') {
|
|
186
|
+
if (!this.tool(frame, true) ||
|
|
187
|
+
this.announced ||
|
|
188
|
+
(this.claimed && this.claimed.toolUseId !== frame.toolUseId)) {
|
|
189
|
+
this.refuse('PROBE_UNEXPECTED_TOOL');
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
this.announced = frame.toolUseId;
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
if (this.completed ||
|
|
196
|
+
!this.claimed ||
|
|
197
|
+
this.announced !== this.claimed.toolUseId ||
|
|
198
|
+
frame.toolUseId !== this.claimed.toolUseId ||
|
|
199
|
+
typeof frame.toolName !== 'string' ||
|
|
200
|
+
!/^(bash|Bash)$/.test(frame.toolName) ||
|
|
201
|
+
frame.status !== 'completed' ||
|
|
202
|
+
!this.matchesOutput(frame.toolResponse, this.output)) {
|
|
203
|
+
this.refuse('PROBE_TOOL_RESULT_MISMATCH');
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
this.completed = true;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
result() {
|
|
210
|
+
return {
|
|
211
|
+
permissionRecorded: this.recorded,
|
|
212
|
+
toolVerified: this.completed && this.recorded && !this.failure,
|
|
213
|
+
failure: this.failure,
|
|
214
|
+
toolUseId: this.claimed?.toolUseId ?? null,
|
|
215
|
+
requestId: this.claimed?.requestId ?? null,
|
|
216
|
+
interactiveAdmission: this.admission,
|
|
217
|
+
autonomousRunClaimed: false,
|
|
218
|
+
autonomousAttemptClaimed: false,
|
|
219
|
+
approvalSource: 'exact-local-operator-rule',
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
exports.FixedCopilotPermission = FixedCopilotPermission;
|
|
@@ -61,6 +61,7 @@ import { buildManagedInferenceRelayCredential, startManagedInferenceBroker, type
|
|
|
61
61
|
import { type ApiFetchOptions } from './api-fetch';
|
|
62
62
|
import { type EngineExitOutcome } from './first-party-harness';
|
|
63
63
|
import { type FirstPartyHarnessAgent } from './first-party-harness-agent';
|
|
64
|
+
import { type ManagedSmokeOperations } from './inference-overload-smoke-contract';
|
|
64
65
|
/**
|
|
65
66
|
* Reasons the server accepts for a release. An ALLOW-LIST on its side, mirrored
|
|
66
67
|
* here as a type so a typo becomes a compile error rather than a silent
|
|
@@ -122,6 +123,8 @@ export interface ManagedSessionHandle {
|
|
|
122
123
|
* process until the reaper notices. `reason` is what an operator greps.
|
|
123
124
|
*/
|
|
124
125
|
stop(reason?: ManagedReleaseReason): Promise<void>;
|
|
126
|
+
/** Fixed diagnostic operations; the current session capability stays inside this factory. */
|
|
127
|
+
overloadSmoke?: ManagedSmokeOperations;
|
|
125
128
|
}
|
|
126
129
|
type FetchLike = (url: string, init: RequestInit) => Promise<Response>;
|
|
127
130
|
export interface AcquireManagedSessionInput {
|
|
@@ -129,6 +132,8 @@ export interface AcquireManagedSessionInput {
|
|
|
129
132
|
agentRef?: string;
|
|
130
133
|
/** The model the user named to the engine, if any. */
|
|
131
134
|
model?: string;
|
|
135
|
+
/** Optional normal admission selection; absence preserves the policy default. */
|
|
136
|
+
reasoningEffort?: string;
|
|
132
137
|
env?: NodeJS.ProcessEnv;
|
|
133
138
|
onLeaseRenewalStopped?: (reason: RenewalStopReason, detail?: string) => void;
|
|
134
139
|
/**
|