@capybara-hq/kernel 0.1.0-rc.30 → 0.1.0-rc.31
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/bootstrap.json +3 -3
- package/dist/catalog/marketplace-fetch.d.ts +5 -2
- package/dist/catalog/marketplace-fetch.js +4 -1
- package/dist/catalog/requests.service.d.ts +6 -5
- package/dist/catalog/requests.service.js +7 -6
- package/dist/config/load.d.ts +6 -0
- package/dist/config/load.js +26 -0
- package/dist/config/schema.js +5 -5
- package/dist/conversations/events.d.ts +10 -0
- package/dist/conversations/events.js +23 -1
- package/dist/devices/devices.controller.js +3 -2
- package/dist/devices/devices.service.d.ts +17 -5
- package/dist/devices/devices.service.js +24 -13
- package/dist/devices/dto.d.ts +7 -6
- package/dist/devices/dto.js +6 -5
- package/dist/errors.d.ts +6 -1
- package/dist/errors.js +6 -1
- package/dist/evals/reconstruct.js +18 -8
- package/dist/extensions/bootstrap.d.ts +1 -1
- package/dist/extensions/bootstrap.js +7 -1
- package/dist/extensions/installs.js +4 -1
- package/dist/lifecycle/kernel-lifecycle.js +1 -3
- package/dist/net/public-address.d.ts +14 -4
- package/dist/net/public-address.js +22 -12
- package/dist/net/safe-fetch.d.ts +2 -1
- package/dist/net/safe-fetch.js +16 -4
- package/dist/packages/npm.d.ts +28 -9
- package/dist/packages/npm.js +30 -19
- package/dist/packages/provenance.d.ts +3 -1
- package/dist/packages/provenance.js +7 -3
- package/dist/platform/ops/devices.ops.js +1 -1
- package/dist/platform/ops/platform.ops.d.ts +3 -1
- package/dist/platform/ops/platform.ops.js +11 -13
- package/dist/runtime/context/build.d.ts +10 -1
- package/dist/runtime/context/build.js +44 -10
- package/dist/runtime/context/compaction.d.ts +27 -8
- package/dist/runtime/context/compaction.js +133 -58
- package/dist/runtime/context/fit.d.ts +54 -22
- package/dist/runtime/context/fit.js +116 -40
- package/dist/runtime/model-call.d.ts +0 -8
- package/dist/runtime/model-call.js +185 -83
- package/dist/sandbox/review/classifier.d.ts +2 -0
- package/dist/sandbox/review/classifier.js +12 -1
- package/dist/sandbox/review/index.d.ts +3 -3
- package/dist/sandbox/review/index.js +3 -3
- package/dist/sandbox/review/review.service.d.ts +12 -4
- package/dist/sandbox/review/review.service.js +88 -19
- package/dist/sandbox/review/rules.d.ts +6 -0
- package/dist/sandbox/review/rules.js +1013 -95
- package/dist/sandbox/review/types.d.ts +21 -4
- package/dist/sandbox/review/types.js +41 -5
- package/dist/sandbox/sandbox.service.d.ts +8 -7
- package/dist/sandbox/sandbox.service.js +16 -16
- package/dist/setup/kernel-checks.js +3 -2
- package/dist/setup/oauth-token-probe.d.ts +1 -8
- package/dist/setup/oauth-token-probe.js +0 -16
- package/dist/tools/builtins/sandbox/common.d.ts +1 -1
- package/dist/tools/builtins/sandbox/common.js +1 -1
- package/dist/tools/builtins/tool-search.js +4 -3
- package/dist/tools/oauth/discovery.d.ts +38 -16
- package/dist/tools/oauth/discovery.js +59 -33
- package/dist/tools/pipeline.js +17 -13
- package/package.json +1 -1
|
@@ -16,8 +16,8 @@ import { KERNEL_LOGGER } from "../../infra/tokens.js";
|
|
|
16
16
|
import { ModelPurposesService } from "../../models/purposes.js";
|
|
17
17
|
import { StepLog } from "../../runtime/step-log.js";
|
|
18
18
|
import { boundMessages, newReviewTag, REVIEW_ASK_REASON, REVIEW_PURPOSE, runClassifier, } from "./classifier.js";
|
|
19
|
-
import { reviewRules, reviewWrite } from "./rules.js";
|
|
20
|
-
import { isSessionGrantableRule } from "./types.js";
|
|
19
|
+
import { reviewRules, reviewWrite, writtenPaths } from "./rules.js";
|
|
20
|
+
import { applySessionGrants, isSessionGrantableRule, } from "./types.js";
|
|
21
21
|
/** The reasons the service itself answers with (the rule table's own reasons come from its hits). */
|
|
22
22
|
export const REVIEW_REASONS = {
|
|
23
23
|
/** The tool is not one the review covers. */
|
|
@@ -31,6 +31,8 @@ export const REVIEW_REASONS = {
|
|
|
31
31
|
};
|
|
32
32
|
/** The tools the review covers: the shell, and the file tools whose writes may leave the workspace. */
|
|
33
33
|
const REVIEWED_TOOLS = new Set(["Bash", "Write", "Edit"]);
|
|
34
|
+
/** How many of a conversation tree's latest assistant messages the review reads for its writes. */
|
|
35
|
+
const WRITTEN_EVENTS_READ = 200;
|
|
34
36
|
/** How many of the root conversation's latest person messages are read before bounding the text. */
|
|
35
37
|
const PERSON_MESSAGES_READ = 20;
|
|
36
38
|
const allow = (reason, rule) => ({
|
|
@@ -117,8 +119,14 @@ let CommandReviewService = class CommandReviewService {
|
|
|
117
119
|
mode: input.mode,
|
|
118
120
|
attended: input.attended,
|
|
119
121
|
};
|
|
120
|
-
|
|
121
|
-
const
|
|
122
|
+
// running a file this conversation wrote is not a development command (hardening spec R1)
|
|
123
|
+
const result = isWrite
|
|
124
|
+
? reviewWrite(target, facts)
|
|
125
|
+
: reviewRules(target, {
|
|
126
|
+
...facts,
|
|
127
|
+
written: await this.writtenInTree(await rootOf(), facts),
|
|
128
|
+
});
|
|
129
|
+
let hit = decidingHit(result.hits, result.outcome);
|
|
122
130
|
if (result.outcome === "deny") {
|
|
123
131
|
return {
|
|
124
132
|
decision: "deny",
|
|
@@ -131,14 +139,23 @@ let CommandReviewService = class CommandReviewService {
|
|
|
131
139
|
return allow(hit?.reason ?? "The command review allows this command.", hit?.id ?? null);
|
|
132
140
|
}
|
|
133
141
|
if (result.outcome === "ask") {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
142
|
+
// a session grant covers its own class only, and only while the person is there to have
|
|
143
|
+
// given it (hardening spec R4, R6): every ask hit granted and nothing unsure left
|
|
144
|
+
const granted = input.attended ? await this.grantedRules(await rootOf()) : new Set();
|
|
145
|
+
const after = applySessionGrants(result, (rule) => granted.has(rule));
|
|
146
|
+
if (after.outcome === "allow") {
|
|
147
|
+
return allow(REVIEW_REASONS.sessionGrant, after.hit?.id ?? null);
|
|
148
|
+
}
|
|
149
|
+
if (after.outcome === "ask") {
|
|
150
|
+
return {
|
|
137
151
|
decision: "ask",
|
|
138
152
|
by: "rule",
|
|
139
|
-
reason: hit?.reason ?? "This command needs the person's approval.",
|
|
140
|
-
rule: hit?.id ?? null,
|
|
153
|
+
reason: after.hit?.reason ?? "This command needs the person's approval.",
|
|
154
|
+
rule: after.hit?.id ?? null,
|
|
141
155
|
};
|
|
156
|
+
}
|
|
157
|
+
// the granted asks are settled; what is left is unsure, which the classifier decides
|
|
158
|
+
hit = after.hit;
|
|
142
159
|
}
|
|
143
160
|
// unsure: the classifier decides when the purpose is mapped; without one the deciding hit is a
|
|
144
161
|
// catch-all (`unsure.*`), which no person can reason about as a class: it is an ask with no
|
|
@@ -230,21 +247,58 @@ let CommandReviewService = class CommandReviewService {
|
|
|
230
247
|
return id;
|
|
231
248
|
}
|
|
232
249
|
/**
|
|
233
|
-
*
|
|
250
|
+
* The rule classes the root conversation holds session grants for (`command:<ruleId>` rows).
|
|
234
251
|
* Command grants carry no tool-spec fingerprint: the approval records the rule, not the command.
|
|
235
|
-
* Only a concrete
|
|
236
|
-
*
|
|
252
|
+
* Only a concrete grantable class counts: a stored catch-all or never-session class (old data)
|
|
253
|
+
* covers nothing.
|
|
237
254
|
*/
|
|
238
|
-
async
|
|
239
|
-
|
|
240
|
-
return false;
|
|
241
|
-
const grant = await this.db
|
|
255
|
+
async grantedRules(rootConversationId) {
|
|
256
|
+
const rows = await this.db
|
|
242
257
|
.selectFrom("conversation_tool_grants")
|
|
243
258
|
.select("tool_key")
|
|
244
259
|
.where("conversation_id", "=", rootConversationId)
|
|
245
|
-
.where("tool_key", "
|
|
246
|
-
.
|
|
247
|
-
|
|
260
|
+
.where("tool_key", "like", "command:%")
|
|
261
|
+
.execute();
|
|
262
|
+
const rules = rows.map((r) => r.tool_key.slice("command:".length));
|
|
263
|
+
return new Set(rules.filter((rule) => isSessionGrantableRule(rule)));
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* The absolute paths the conversation tree's own tool calls wrote — the root's and every
|
|
267
|
+
* sub-agent's: `Write` / `Edit` targets and the write targets (downloads and copies included) of
|
|
268
|
+
* their `Bash` lines, from the latest {@link WRITTEN_EVENTS_READ} assistant messages of the tree.
|
|
269
|
+
* All agents of a tree share the device, so a file one of them wrote is code the run produced,
|
|
270
|
+
* whoever runs it (hardening spec R1).
|
|
271
|
+
*/
|
|
272
|
+
async writtenInTree(rootConversationId, facts) {
|
|
273
|
+
const rows = await this.db
|
|
274
|
+
.withRecursive("tree(id)", (db) => db
|
|
275
|
+
.selectFrom("conversations")
|
|
276
|
+
.select("id")
|
|
277
|
+
.where("id", "=", rootConversationId)
|
|
278
|
+
.unionAll((q) => q
|
|
279
|
+
.selectFrom("conversations as c")
|
|
280
|
+
.innerJoin("tree", "tree.id", "c.parent_conversation_id")
|
|
281
|
+
.select("c.id")))
|
|
282
|
+
.selectFrom("conversation_events")
|
|
283
|
+
.select("payload")
|
|
284
|
+
.where("conversation_id", "in", (q) => q.selectFrom("tree").select("id"))
|
|
285
|
+
.where("type", "=", "assistant_message")
|
|
286
|
+
.orderBy("created_at", "desc")
|
|
287
|
+
.limit(WRITTEN_EVENTS_READ)
|
|
288
|
+
.execute();
|
|
289
|
+
const written = new Set();
|
|
290
|
+
for (const row of rows) {
|
|
291
|
+
for (const call of toolCallsOf(row.payload)) {
|
|
292
|
+
if ((call.name === "Write" || call.name === "Edit") && typeof call.path === "string") {
|
|
293
|
+
written.add(call.path.startsWith("/") ? call.path : `${facts.workspace}/${call.path}`);
|
|
294
|
+
}
|
|
295
|
+
else if (call.name === "Bash" && typeof call.command === "string") {
|
|
296
|
+
for (const path of writtenPaths(call.command, facts))
|
|
297
|
+
written.add(path);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return [...written];
|
|
248
302
|
}
|
|
249
303
|
/**
|
|
250
304
|
* The bounded text of the root conversation's last person messages: the `user_message` text blocks
|
|
@@ -274,6 +328,21 @@ CommandReviewService = __decorate([
|
|
|
274
328
|
__param(6, Inject(ExtensionHost))
|
|
275
329
|
], CommandReviewService);
|
|
276
330
|
export { CommandReviewService };
|
|
331
|
+
/** The tool calls of an `assistant_message` payload, with the fields the review reads. */
|
|
332
|
+
function toolCallsOf(payload) {
|
|
333
|
+
const content = payload?.content;
|
|
334
|
+
if (!Array.isArray(content))
|
|
335
|
+
return [];
|
|
336
|
+
return content.flatMap((b) => {
|
|
337
|
+
if (b === null || typeof b !== "object")
|
|
338
|
+
return [];
|
|
339
|
+
const block = b;
|
|
340
|
+
if (block.type !== "tool_call" || typeof block.name !== "string")
|
|
341
|
+
return [];
|
|
342
|
+
const input = (block.input ?? {});
|
|
343
|
+
return [{ name: block.name, path: input.file_path, command: input.command }];
|
|
344
|
+
});
|
|
345
|
+
}
|
|
277
346
|
/** The text blocks of a `user_message` payload (its images, documents and attachments are skipped). */
|
|
278
347
|
function textOfUserMessage(payload) {
|
|
279
348
|
const content = payload?.content;
|
|
@@ -65,6 +65,12 @@ import type { ParsedCommand, ReviewFacts, ReviewResult } from "./types.js";
|
|
|
65
65
|
export type { ParsedCommand, Redirect, ReviewFacts, ReviewResult, RuleHit, RuleOutcome, SimpleCommand, } from "./types.js";
|
|
66
66
|
/** The public parser: the parsed command, or null when the tokenizer is not confident. */
|
|
67
67
|
export declare function parseCommand(command: string): ParsedCommand | null;
|
|
68
|
+
/**
|
|
69
|
+
* The absolute paths a command line writes, for the review's record of what a conversation wrote
|
|
70
|
+
* (hardening spec R1: running one of them later is not a development command). An unparseable line
|
|
71
|
+
* writes nothing the review can name.
|
|
72
|
+
*/
|
|
73
|
+
export declare function writtenPaths(command: string, facts: ReviewFacts): string[];
|
|
68
74
|
/**
|
|
69
75
|
* The rule table over a command line: the strictest outcome and every hit, in rule order. A parse
|
|
70
76
|
* the tokenizer cannot make confidently yields only `unsure.unparsed`; a command no rule covers
|