@capybara-hq/kernel 0.1.0-rc.32 → 0.1.0-rc.33
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/catalog/marketplaces.service.d.ts +1 -1
- package/dist/channels/inbound.d.ts +0 -25
- package/dist/channels/inbound.js +26 -1
- package/dist/channels/phrases.d.ts +28 -0
- package/dist/channels/phrases.js +28 -0
- package/dist/conversations/conversations.controller.d.ts +4 -1
- package/dist/conversations/conversations.controller.js +14 -2
- package/dist/conversations/conversations.service.d.ts +43 -3
- package/dist/conversations/conversations.service.js +93 -19
- package/dist/conversations/event-log.d.ts +3 -3
- package/dist/conversations/event-log.js +3 -3
- package/dist/conversations/events.d.ts +24 -0
- package/dist/conversations/events.js +69 -0
- package/dist/db/kernel-schema.d.ts +20 -0
- package/dist/devices/conversation-devices.d.ts +57 -3
- package/dist/devices/conversation-devices.js +63 -11
- package/dist/devices/device-projects.service.d.ts +162 -0
- package/dist/devices/device-projects.service.js +503 -0
- package/dist/devices/devices.controller.d.ts +15 -2
- package/dist/devices/devices.controller.js +60 -3
- package/dist/devices/devices.module.js +15 -2
- package/dist/devices/devices.schemas.js +9 -1
- package/dist/devices/dto.d.ts +31 -0
- package/dist/devices/dto.js +38 -1
- package/dist/devices/working-root.d.ts +41 -0
- package/dist/devices/working-root.js +50 -0
- package/dist/errors.d.ts +39 -0
- package/dist/errors.js +39 -0
- package/dist/evals/run-replay.d.ts +9 -1
- package/dist/evals/run-replay.js +15 -1
- package/dist/local-devices/local-device-provider.d.ts +37 -1
- package/dist/local-devices/local-device-provider.js +33 -0
- package/dist/local-devices/machines.d.ts +2 -1
- package/dist/local-devices/machines.js +4 -1
- package/dist/local-devices/policy-summary.js +1 -0
- package/dist/local-devices/relay.d.ts +2 -0
- package/dist/local-devices/relay.js +3 -1
- package/dist/local-devices/targets.d.ts +6 -1
- package/dist/local-devices/targets.js +14 -0
- package/dist/overrides.d.ts +4 -0
- package/dist/overrides.js +2 -0
- package/dist/platform/ops/agent-skills.ops.js +2 -1
- package/dist/platform/ops/devices.ops.d.ts +3 -1
- package/dist/platform/ops/devices.ops.js +136 -3
- package/dist/runtime/context/build.d.ts +3 -0
- package/dist/runtime/context/build.js +14 -0
- package/dist/runtime/context/compaction.js +2 -0
- package/dist/runtime/context/project-root.d.ts +43 -0
- package/dist/runtime/context/project-root.js +85 -0
- package/dist/runtime/model-call.js +25 -1
- package/dist/runtime/project/knowledge.d.ts +129 -0
- package/dist/runtime/project/knowledge.js +248 -0
- package/dist/runtime/project/knowledge.service.d.ts +85 -0
- package/dist/runtime/project/knowledge.service.js +288 -0
- package/dist/runtime/run-worker.d.ts +5 -0
- package/dist/runtime/run-worker.js +27 -6
- package/dist/runtime/runtime.module.js +7 -0
- package/dist/sandbox/review/review.service.d.ts +14 -2
- package/dist/sandbox/review/review.service.js +2 -0
- package/dist/sandbox/review/rules.d.ts +6 -4
- package/dist/sandbox/review/rules.js +185 -62
- package/dist/sandbox/review/types.d.ts +14 -0
- package/dist/sandbox/sandbox.service.d.ts +16 -1
- package/dist/sandbox/sandbox.service.js +75 -3
- package/dist/skills/catalog.d.ts +6 -1
- package/dist/skills/catalog.js +18 -4
- package/dist/skills/invoke.d.ts +64 -2
- package/dist/skills/invoke.js +214 -6
- package/dist/skills/skills.module.js +5 -0
- package/dist/tools/approvals.service.d.ts +6 -0
- package/dist/tools/builtins/sandbox/bash.js +19 -4
- package/dist/tools/builtins/sandbox/common.d.ts +36 -6
- package/dist/tools/builtins/sandbox/common.js +69 -8
- package/dist/tools/builtins/sandbox/edit.js +2 -2
- package/dist/tools/builtins/sandbox/glob.js +3 -2
- package/dist/tools/builtins/sandbox/grep.js +2 -1
- package/dist/tools/builtins/sandbox/read.js +3 -3
- package/dist/tools/builtins/sandbox/write.js +2 -2
- package/dist/tools/builtins/skill-load.d.ts +47 -2
- package/dist/tools/builtins/skill-load.js +160 -2
- package/dist/tools/pipeline.d.ts +1 -1
- package/dist/tools/pipeline.js +53 -8
- package/dist/tools/registry.d.ts +6 -0
- package/package.json +2 -2
- package/src/migrations/0133_project_root.sql +30 -0
|
@@ -33,6 +33,7 @@ import { ConversationLock } from "./conversation-lock.js";
|
|
|
33
33
|
import { runDeadline, tightestLimit } from "./limits.js";
|
|
34
34
|
import { RunError } from "./model-call.js";
|
|
35
35
|
import { PluginContextService } from "./plugin-context.service.js";
|
|
36
|
+
import { ProjectKnowledgeService } from "./project/knowledge.service.js";
|
|
36
37
|
import { ProviderListError, ProviderRegistry } from "./providers.js";
|
|
37
38
|
import { ORG_QUOTA_LEASE_MS, orgRunLimit, RUN_QUOTA } from "./quota.js";
|
|
38
39
|
import { RunContextService } from "./run-context.service.js";
|
|
@@ -101,6 +102,7 @@ let RunWorker = class RunWorker {
|
|
|
101
102
|
skillsCatalog;
|
|
102
103
|
runContext;
|
|
103
104
|
pluginContext;
|
|
105
|
+
projectKnowledge;
|
|
104
106
|
tools;
|
|
105
107
|
finisher;
|
|
106
108
|
txHost;
|
|
@@ -132,6 +134,8 @@ let RunWorker = class RunWorker {
|
|
|
132
134
|
runContext,
|
|
133
135
|
/** Run start's plugin context (memory plugin spec §6.1): the `context@1` providers' text. */
|
|
134
136
|
pluginContext,
|
|
137
|
+
/** Run start's project knowledge (project root spec §4.4): a bound project's AGENTS.md, skills. */
|
|
138
|
+
projectKnowledge,
|
|
135
139
|
/** The run's resolved tools, for the plugin context's `tools` (chat runs with providers). */
|
|
136
140
|
tools, finisher, txHost,
|
|
137
141
|
/** The steps' live drafts this process writes for the runs it executes. */
|
|
@@ -155,6 +159,7 @@ let RunWorker = class RunWorker {
|
|
|
155
159
|
this.skillsCatalog = skillsCatalog;
|
|
156
160
|
this.runContext = runContext;
|
|
157
161
|
this.pluginContext = pluginContext;
|
|
162
|
+
this.projectKnowledge = projectKnowledge;
|
|
158
163
|
this.tools = tools;
|
|
159
164
|
this.finisher = finisher;
|
|
160
165
|
this.txHost = txHost;
|
|
@@ -695,6 +700,21 @@ let RunWorker = class RunWorker {
|
|
|
695
700
|
});
|
|
696
701
|
if (!pluginContexted)
|
|
697
702
|
return "finished";
|
|
703
|
+
// project knowledge (project root spec §4.4): a conversation bound to a project reads its
|
|
704
|
+
// AGENTS.md and skills on the device before the first model call, outside any transaction;
|
|
705
|
+
// a free one reads nothing, a sub-agent copies its root's latest snapshot. Its append
|
|
706
|
+
// re-reads the run under the locks, as above.
|
|
707
|
+
const projectRead = await this.projectKnowledge.record({
|
|
708
|
+
orgId: conv.org_id,
|
|
709
|
+
conversationId,
|
|
710
|
+
runId,
|
|
711
|
+
kind: conv.kind,
|
|
712
|
+
// a sub-agent copies its root's snapshot: it works in the root's project
|
|
713
|
+
...(parent !== undefined && { rootConversationId: parent.rootConversationId }),
|
|
714
|
+
signal: state.shutdown.signal,
|
|
715
|
+
});
|
|
716
|
+
if (!projectRead)
|
|
717
|
+
return "finished";
|
|
698
718
|
await this.hooks?.beforeRunning?.(runId, conversationId);
|
|
699
719
|
// never over a terminal status: a run finished meanwhile stays finished
|
|
700
720
|
const updated = await this.db
|
|
@@ -1199,11 +1219,12 @@ RunWorker = __decorate([
|
|
|
1199
1219
|
__param(18, Inject(SkillsCatalogService)),
|
|
1200
1220
|
__param(19, Inject(RunContextService)),
|
|
1201
1221
|
__param(20, Inject(PluginContextService)),
|
|
1202
|
-
__param(21, Inject(
|
|
1203
|
-
__param(22, Inject(
|
|
1204
|
-
__param(23, Inject(
|
|
1205
|
-
__param(24, Inject(
|
|
1206
|
-
__param(25,
|
|
1207
|
-
__param(
|
|
1222
|
+
__param(21, Inject(ProjectKnowledgeService)),
|
|
1223
|
+
__param(22, Inject(ToolRegistry)),
|
|
1224
|
+
__param(23, Inject(RunFinish)),
|
|
1225
|
+
__param(24, Inject(TransactionHost)),
|
|
1226
|
+
__param(25, Inject(RunDrafts)),
|
|
1227
|
+
__param(26, Optional()),
|
|
1228
|
+
__param(26, Inject(RUN_HOOKS))
|
|
1208
1229
|
], RunWorker);
|
|
1209
1230
|
export { RunWorker };
|
|
@@ -11,12 +11,14 @@ import { ConversationAccessModule } from "../conversations/access.js";
|
|
|
11
11
|
import { AttachmentsModule } from "../conversations/attachments.module.js";
|
|
12
12
|
import { EventLogModule } from "../conversations/event-log.js";
|
|
13
13
|
import { TitlesModule } from "../conversations/titles.js";
|
|
14
|
+
import { DevicesModule } from "../devices/devices.module.js";
|
|
14
15
|
import { ExtensionsModule } from "../extensions/extensions.module.js";
|
|
15
16
|
import { GitModule } from "../git/git.module.js";
|
|
16
17
|
import { IdentityModule } from "../identity/identity.module.js";
|
|
17
18
|
import { LockService } from "../infra/lock/lock.service.js";
|
|
18
19
|
import { QueueModule } from "../infra/queue/queue.module.js";
|
|
19
20
|
import { REDIS } from "../infra/tokens.js";
|
|
21
|
+
import { SandboxModule } from "../sandbox/sandbox.module.js";
|
|
20
22
|
import { ScheduledTaskTrackerModule } from "../schedules/run-tracker.js";
|
|
21
23
|
import { SkillsModule } from "../skills/skills.module.js";
|
|
22
24
|
import { ToolsModule } from "../tools/tools.module.js";
|
|
@@ -28,6 +30,7 @@ import { CompactionSettingsService } from "./compaction-settings.service.js";
|
|
|
28
30
|
import { ConversationLock } from "./conversation-lock.js";
|
|
29
31
|
import { MAINTENANCE_QUEUE_NAME } from "./maintenance-queue.js";
|
|
30
32
|
import { PluginContextService } from "./plugin-context.service.js";
|
|
33
|
+
import { ProjectKnowledgeService } from "./project/knowledge.service.js";
|
|
31
34
|
import { ProvidersModule } from "./providers.js";
|
|
32
35
|
import { EVAL_QUOTA, EVAL_QUOTA_PREFIX, OrgQuota, RUN_QUOTA, RUN_QUOTA_PREFIX } from "./quota.js";
|
|
33
36
|
import { RunContextService } from "./run-context.service.js";
|
|
@@ -62,6 +65,9 @@ RuntimeModule = __decorate([
|
|
|
62
65
|
IdentityModule,
|
|
63
66
|
SkillsModule,
|
|
64
67
|
ToolsModule,
|
|
68
|
+
// a bound conversation's device and project scope (project root spec §4.4)
|
|
69
|
+
DevicesModule,
|
|
70
|
+
SandboxModule,
|
|
65
71
|
GitModule,
|
|
66
72
|
ProvidersModule,
|
|
67
73
|
RunJobsModule,
|
|
@@ -90,6 +96,7 @@ RuntimeModule = __decorate([
|
|
|
90
96
|
RunSteps,
|
|
91
97
|
RunContextService,
|
|
92
98
|
PluginContextService,
|
|
99
|
+
ProjectKnowledgeService,
|
|
93
100
|
RunWorker,
|
|
94
101
|
// the org's effective compaction settings, one read per model step
|
|
95
102
|
CompactionSettingsService,
|
|
@@ -42,10 +42,22 @@ export interface ReviewInput {
|
|
|
42
42
|
input: unknown;
|
|
43
43
|
mode: "auto" | "sandbox";
|
|
44
44
|
/**
|
|
45
|
-
* The
|
|
46
|
-
*
|
|
45
|
+
* The conversation's working root: the device's workspace root, or the bound project's root
|
|
46
|
+
* (project root spec §4.3). Commands start here and a write inside it needs no ask. Absent: no
|
|
47
|
+
* device is bound, so the tool fails on its own and there is nothing to review.
|
|
47
48
|
*/
|
|
48
49
|
workspace?: string | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* The owner's home directory (the machine's, else the device workspace's prefix), never derived
|
|
52
|
+
* from a project root: `~` and the home-level sensitive paths are judged against it. Absent or
|
|
53
|
+
* null: the rules derive it from `workspace`.
|
|
54
|
+
*/
|
|
55
|
+
home?: string | null | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* The home prefix of the device's own workspace, judged beside `home` (a project outside every
|
|
58
|
+
* home still protects it). Absent or null: none.
|
|
59
|
+
*/
|
|
60
|
+
deviceHome?: string | null | undefined;
|
|
49
61
|
/** Whether a person is present to answer an `ask` (rules may read it; the pipeline decides). */
|
|
50
62
|
attended: boolean;
|
|
51
63
|
/** Hook payload facts (optional: without enough of them no model hook fires). */
|
|
@@ -63,8 +63,9 @@
|
|
|
63
63
|
*/
|
|
64
64
|
import type { ParsedCommand, ReviewFacts, ReviewResult } from "./types.js";
|
|
65
65
|
export type { ParsedCommand, Redirect, ReviewFacts, ReviewResult, RuleHit, RuleOutcome, SimpleCommand, } from "./types.js";
|
|
66
|
-
/** The public parser: the parsed command, or null when the tokenizer is not confident. */
|
|
67
66
|
export declare function parseCommand(command: string): ParsedCommand | null;
|
|
67
|
+
/** The home directory a path lies in by its `/home/<u>`, `/Users/<u>` or `/root` prefix, or null. */
|
|
68
|
+
export declare function homeOf(workspace: string): string | null;
|
|
68
69
|
/**
|
|
69
70
|
* The absolute paths a command line writes, for the review's record of what a conversation wrote
|
|
70
71
|
* (hardening spec R1: running one of them later is not a development command). An unparseable line
|
|
@@ -78,8 +79,9 @@ export declare function writtenPaths(command: string, facts: ReviewFacts): strin
|
|
|
78
79
|
*/
|
|
79
80
|
export declare function reviewRules(command: string, facts: ReviewFacts): ReviewResult;
|
|
80
81
|
/**
|
|
81
|
-
* The same table for a file-tool write:
|
|
82
|
-
*
|
|
83
|
-
* outside
|
|
82
|
+
* The same table for a file-tool write: the device's own files are denied; git hooks and
|
|
83
|
+
* home-level sensitive paths (shell rc files, SSH, launch agents, credentials) ask wherever they
|
|
84
|
+
* lie, inside the workspace too; other workspace and tmp writes pass; a `.env*` file outside the
|
|
85
|
+
* workspace asks; anything else outside asks to write outside.
|
|
84
86
|
*/
|
|
85
87
|
export declare function reviewWrite(path: string, facts: ReviewFacts): ReviewResult;
|
|
@@ -22,6 +22,47 @@ const WORD_END = new Set([" ", "\t", "\n", "\r", "|", "&", ";", "<", ">", "(", "
|
|
|
22
22
|
const isDigit = (c) => c >= "0" && c <= "9";
|
|
23
23
|
const isAlphaNum = (c) => /[A-Za-z0-9]/.test(c);
|
|
24
24
|
/** The public parser: the parsed command, or null when the tokenizer is not confident. */
|
|
25
|
+
/** `git config` options that only read (the long-standing spelling). */
|
|
26
|
+
const GIT_CONFIG_READ_OPTIONS = new Set([
|
|
27
|
+
"--get",
|
|
28
|
+
"--get-all",
|
|
29
|
+
"--get-regexp",
|
|
30
|
+
"--get-urlmatch",
|
|
31
|
+
"--get-color",
|
|
32
|
+
"--get-colorbool",
|
|
33
|
+
"-l",
|
|
34
|
+
"--list",
|
|
35
|
+
]);
|
|
36
|
+
/** `git config` options that change the file whatever else the line says. */
|
|
37
|
+
const GIT_CONFIG_WRITE_OPTIONS = new Set([
|
|
38
|
+
"--add",
|
|
39
|
+
"--unset",
|
|
40
|
+
"--unset-all",
|
|
41
|
+
"--replace-all",
|
|
42
|
+
"--rename-section",
|
|
43
|
+
"--remove-section",
|
|
44
|
+
"-e",
|
|
45
|
+
"--edit",
|
|
46
|
+
]);
|
|
47
|
+
/**
|
|
48
|
+
* `git config --global` / `--system` that changes the user's or the system's config file: a value
|
|
49
|
+
* set, an `--unset`, an edit, a section rename (`git config [--global] name value`, the subcommands
|
|
50
|
+
* `set` / `unset` / `edit` / `rename-section` / `remove-section`). Reading it (`--get…`, `--list`,
|
|
51
|
+
* `get`, `list`) changes nothing; plain `git config --list` already prints the global values.
|
|
52
|
+
*/
|
|
53
|
+
function gitConfigChangesUserFile(args) {
|
|
54
|
+
if (args[0] !== "config")
|
|
55
|
+
return false;
|
|
56
|
+
const rest = args.slice(1);
|
|
57
|
+
if (!hasArg(rest, "--global", "--system"))
|
|
58
|
+
return false;
|
|
59
|
+
if (rest.some((a) => GIT_CONFIG_WRITE_OPTIONS.has(a)))
|
|
60
|
+
return true;
|
|
61
|
+
const sub = rest.find((a) => !a.startsWith("-"));
|
|
62
|
+
if (sub === "get" || sub === "list")
|
|
63
|
+
return false;
|
|
64
|
+
return !rest.some((a) => GIT_CONFIG_READ_OPTIONS.has(a));
|
|
65
|
+
}
|
|
25
66
|
export function parseCommand(command) {
|
|
26
67
|
const parsed = parseDetailed(command);
|
|
27
68
|
return parsed.ok ? { commands: parsed.value } : null;
|
|
@@ -763,7 +804,8 @@ function unwrapOneLevel(commands) {
|
|
|
763
804
|
function isDynamicScript(script) {
|
|
764
805
|
return script.includes("$(") || script.includes("`") || /\$\{?[A-Za-z_]/.test(script);
|
|
765
806
|
}
|
|
766
|
-
|
|
807
|
+
/** The home directory a path lies in by its `/home/<u>`, `/Users/<u>` or `/root` prefix, or null. */
|
|
808
|
+
export function homeOf(workspace) {
|
|
767
809
|
const parts = workspace.split("/").filter((p) => p.length > 0);
|
|
768
810
|
if ((parts[0] === "home" || parts[0] === "Users") && parts.length >= 2)
|
|
769
811
|
return `/${parts[0]}/${parts[1]}`;
|
|
@@ -773,11 +815,25 @@ function homeOf(workspace) {
|
|
|
773
815
|
}
|
|
774
816
|
function resolveFacts(facts) {
|
|
775
817
|
const workspace = normalizePath(facts.workspace);
|
|
818
|
+
const derived = homeOf(workspace);
|
|
819
|
+
// the home of the device's own workspace: a project outside every home keeps protecting it
|
|
820
|
+
const device = facts.deviceHome?.startsWith("/") ? normalizePath(facts.deviceHome) : null;
|
|
821
|
+
const deviceHome = device === null || device === "/" ? null : device;
|
|
822
|
+
// an implausible reported home (`/`, or an ancestor of a derived home such as `/Users`) would
|
|
823
|
+
// make every path a home path: it is ignored and only the derived homes are used
|
|
824
|
+
const given = facts.home?.startsWith("/") ? normalizePath(facts.home) : null;
|
|
825
|
+
const reported = given === null ||
|
|
826
|
+
given === "/" ||
|
|
827
|
+
[derived, deviceHome].some((d) => d !== null && isAncestor(given, d))
|
|
828
|
+
? null
|
|
829
|
+
: given;
|
|
776
830
|
const cwd = facts.cwd === undefined ? workspace : normalizePath(facts.cwd);
|
|
777
831
|
return {
|
|
778
832
|
workspace,
|
|
779
833
|
cwd,
|
|
780
|
-
home
|
|
834
|
+
// the owner's home as the pipeline knows it (the machine's), else the workspace's prefix
|
|
835
|
+
home: reported ?? derived ?? deviceHome,
|
|
836
|
+
homes: [...new Set([reported, derived, deviceHome].filter((h) => h !== null))],
|
|
781
837
|
written: new Set((facts.written ?? []).map((p) => p.endsWith("/**") ? `${normalizePath(p.slice(0, -3))}/**` : normalizePath(p))),
|
|
782
838
|
};
|
|
783
839
|
}
|
|
@@ -861,24 +917,34 @@ function tildeForm(path, facts) {
|
|
|
861
917
|
}
|
|
862
918
|
return path;
|
|
863
919
|
}
|
|
864
|
-
/** Case-folded spelling for the
|
|
920
|
+
/** Case-folded spelling for the home-level judgements. */
|
|
865
921
|
const foldCase = (value) => value.toLowerCase();
|
|
866
922
|
/**
|
|
867
|
-
* `
|
|
868
|
-
*
|
|
869
|
-
*
|
|
923
|
+
* Every spelling of `path` the home-level rules (secrets, shell and editor rc files, persistence,
|
|
924
|
+
* the device's files) judge: its `~` form against each of {@link ResolvedFacts.homes} it lies in,
|
|
925
|
+
* then the path itself. macOS's default file system is case-insensitive, so `/USERS/me/.SSH` names
|
|
926
|
+
* the same file as `/Users/me/.ssh`: the home is matched case-folded and the rules compare the
|
|
927
|
+
* case-folded forms ({@link foldedForms}), which only widens what they catch. Workspace containment
|
|
928
|
+
* keeps the exact spelling.
|
|
870
929
|
*/
|
|
871
|
-
function
|
|
872
|
-
if (facts.home === null)
|
|
873
|
-
return path;
|
|
874
|
-
const home = foldCase(facts.home);
|
|
930
|
+
function homeForms(path, facts) {
|
|
875
931
|
const folded = foldCase(path);
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
932
|
+
const out = [];
|
|
933
|
+
for (const h of facts.homes) {
|
|
934
|
+
const home = foldCase(h);
|
|
935
|
+
if (folded === home)
|
|
936
|
+
out.push("~");
|
|
937
|
+
// a root home keeps the path's own leading slash: `/.ssh/x` is `~/.ssh/x`, never `~.ssh/x`
|
|
938
|
+
else if (home === "/")
|
|
939
|
+
out.push(`~${path}`);
|
|
940
|
+
else if (folded.startsWith(`${home}/`))
|
|
941
|
+
out.push(`~${path.slice(h.length)}`);
|
|
942
|
+
}
|
|
943
|
+
out.push(path);
|
|
944
|
+
return out;
|
|
881
945
|
}
|
|
946
|
+
/** {@link homeForms}, case-folded: what the home-level rules compare against lowercase patterns. */
|
|
947
|
+
const foldedForms = (path, facts) => homeForms(path, facts).map(foldCase);
|
|
882
948
|
const TMP_ROOTS = ["/tmp", "/private/tmp", "/var/tmp", "/var/folders", "/private/var/folders"];
|
|
883
949
|
const tmpRootOf = (path) => TMP_ROOTS.some((root) => inside(path, root));
|
|
884
950
|
const SECRET_HOME_PATHS = [
|
|
@@ -896,6 +962,7 @@ const SECRET_HOME_PATHS = [
|
|
|
896
962
|
"~/.vault-token",
|
|
897
963
|
"~/.terraform.d/credentials.tfrc.json",
|
|
898
964
|
"~/.config/op",
|
|
965
|
+
"~/.gnupg",
|
|
899
966
|
"~/.bash_history",
|
|
900
967
|
"~/.zsh_history",
|
|
901
968
|
"~/.sh_history",
|
|
@@ -1082,9 +1149,11 @@ function isSecretPattern(path, facts) {
|
|
|
1082
1149
|
if (tail.length >= 2 && last !== undefined && segmentMatches(last, "environ"))
|
|
1083
1150
|
return true;
|
|
1084
1151
|
}
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1152
|
+
// every home the path lies in is tried; none matching falls through to the checks below
|
|
1153
|
+
for (const t of homeForms(path, facts)) {
|
|
1154
|
+
if (t.startsWith("~/") && isSecretHomePath(t.slice(2).split("/")))
|
|
1155
|
+
return true;
|
|
1156
|
+
}
|
|
1088
1157
|
// `/home/<pattern>/…` never becomes `~/…`: the user segment is the pattern, so judge only the
|
|
1089
1158
|
// literal suffix behind it.
|
|
1090
1159
|
const [root, user, ...suffix] = absolute;
|
|
@@ -1111,7 +1180,7 @@ function isSecretPattern(path, facts) {
|
|
|
1111
1180
|
// the workspace is under `/root`; from another home, `/root/…` is another user's and stays
|
|
1112
1181
|
// allowed (as the literal `/root/.netrc` does), so it must not turn a `/Users/me` workspace's
|
|
1113
1182
|
// `/*/.ssh/id_rsa` into a hit.
|
|
1114
|
-
const rootHit = (facts.
|
|
1183
|
+
const rootHit = (facts.homes.length === 0 || facts.homes.includes("/root")) &&
|
|
1115
1184
|
user !== undefined &&
|
|
1116
1185
|
segmentMatches(root, "root") &&
|
|
1117
1186
|
isSecretHomePath([user, ...suffix]);
|
|
@@ -1121,32 +1190,49 @@ function isSecretPattern(path, facts) {
|
|
|
1121
1190
|
return false;
|
|
1122
1191
|
}
|
|
1123
1192
|
function isSecretPath(path, facts) {
|
|
1193
|
+
if (isHomeSecretPath(path, facts))
|
|
1194
|
+
return true;
|
|
1195
|
+
const base = baseName(path).toLowerCase();
|
|
1196
|
+
return base.startsWith(".env") && !inside(path, facts.workspace);
|
|
1197
|
+
}
|
|
1198
|
+
/** {@link isSecretPath} without `.env*`: the secrets judged wherever they lie. */
|
|
1199
|
+
function isHomeSecretPath(path, facts) {
|
|
1124
1200
|
if (PROC_ENVIRON.test(path))
|
|
1125
1201
|
return true;
|
|
1126
1202
|
// A glob or brace is what the shell expands before the command runs: the path is a secret when
|
|
1127
1203
|
// it can expand to one, so `cat ~/.netr?` is the same read as `cat ~/.netrc`.
|
|
1128
1204
|
if (hasPattern(path) && isSecretPattern(path, facts))
|
|
1129
1205
|
return true;
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1206
|
+
return foldedForms(path, facts).some((t) => SECRET_HOME_PATHS.some((secret) => t === secret || t.startsWith(`${secret}/`)));
|
|
1207
|
+
}
|
|
1208
|
+
/**
|
|
1209
|
+
* A home-level sensitive path (auto mode spec §5.2: shell rc files, `~/.ssh`, `~/.gitconfig`,
|
|
1210
|
+
* launch agents, crontab and the secret paths), judged by its absolute path against the owner's
|
|
1211
|
+
* home. These rules apply whether or not the path is inside the workspace fact: the workspace's
|
|
1212
|
+
* exemption covers ordinary files only, so a project at the owner's home (project root spec
|
|
1213
|
+
* §4.3) never makes `~/.bashrc` an ordinary write. (`.env*` stays a secret only outside the
|
|
1214
|
+
* workspace: {@link isSecretPath}.)
|
|
1215
|
+
*/
|
|
1216
|
+
function isHomeLevelSensitive(path, facts) {
|
|
1217
|
+
return isHomeSecretPath(path, facts) || isPersistencePath(path, facts);
|
|
1135
1218
|
}
|
|
1136
1219
|
function isPersistencePath(path, facts) {
|
|
1137
|
-
|
|
1138
|
-
|
|
1220
|
+
return foldedForms(path, facts).some((t) => isPersistenceForm(t, facts)) || isGitHook(path);
|
|
1221
|
+
}
|
|
1222
|
+
/** One case-folded {@link homeForms} spelling of a persistence path (patterns in lowercase). */
|
|
1223
|
+
function isPersistenceForm(t, facts) {
|
|
1224
|
+
if (isGitConfigForm(t))
|
|
1139
1225
|
return true;
|
|
1140
1226
|
if (/^~\/\.(bashrc|bash_profile|bash_login|profile|zshrc|zshenv|zprofile|zlogin|tcshrc|cshrc|kshrc)$/.test(t)) {
|
|
1141
1227
|
return true;
|
|
1142
1228
|
}
|
|
1143
1229
|
if (t === "~/.config/fish/config.fish" || t.startsWith("~/.config/fish/conf.d/"))
|
|
1144
1230
|
return true;
|
|
1145
|
-
if (t
|
|
1231
|
+
if (isEditorOrLogoutRc(t) || isRunLaterHomePath(t, facts))
|
|
1146
1232
|
return true;
|
|
1147
|
-
if (t
|
|
1233
|
+
if (t === "~/.ssh" || t.startsWith("~/.ssh/"))
|
|
1148
1234
|
return true;
|
|
1149
|
-
if (
|
|
1235
|
+
if (isLaunchForm(t))
|
|
1150
1236
|
return true;
|
|
1151
1237
|
if ([
|
|
1152
1238
|
"/etc/profile",
|
|
@@ -1161,10 +1247,12 @@ function isPersistencePath(path, facts) {
|
|
|
1161
1247
|
}
|
|
1162
1248
|
if (t === "/etc/crontab" || t.startsWith("/var/spool/cron") || t.startsWith("/etc/cron."))
|
|
1163
1249
|
return true;
|
|
1164
|
-
|
|
1165
|
-
return true;
|
|
1166
|
-
return isGitHook(path);
|
|
1250
|
+
return t.startsWith("~/.config/systemd");
|
|
1167
1251
|
}
|
|
1252
|
+
/** The global git configuration: `~/.gitconfig` (and its lock / backups) or `~/.config/git/config`. */
|
|
1253
|
+
const isGitConfigForm = (t) => t === "~/.gitconfig" || t.startsWith("~/.gitconfig.") || t === "~/.config/git/config";
|
|
1254
|
+
/** A launch agent or daemon, the owner's or the machine's. */
|
|
1255
|
+
const isLaunchForm = (t) => /^(~|)\/library\/launch(agents|daemons)/.test(t);
|
|
1168
1256
|
const DEVICE_DIRS = [
|
|
1169
1257
|
"~/.config/capybara-device",
|
|
1170
1258
|
"~/.capybara-device",
|
|
@@ -1174,13 +1262,18 @@ const DEVICE_DIRS = [
|
|
|
1174
1262
|
"/var/lib/capybara-device",
|
|
1175
1263
|
];
|
|
1176
1264
|
function isDevicePath(path, facts) {
|
|
1177
|
-
const
|
|
1178
|
-
if (
|
|
1265
|
+
const dirs = DEVICE_DIRS.map(foldCase);
|
|
1266
|
+
if (foldedForms(path, facts).some((t) => dirs.some((d) => t === d || t.startsWith(`${d}/`)))) {
|
|
1179
1267
|
return true;
|
|
1268
|
+
}
|
|
1180
1269
|
// The device binary, its unit file and its launch agent anywhere on disk.
|
|
1181
|
-
return isDeviceIdentifier(baseName(
|
|
1270
|
+
return isDeviceIdentifier(baseName(path));
|
|
1182
1271
|
}
|
|
1183
|
-
|
|
1272
|
+
/** A git hook, in any letter case (a case-insensitive file system names the same directory). */
|
|
1273
|
+
const isGitHook = (path) => {
|
|
1274
|
+
const p = foldCase(path);
|
|
1275
|
+
return p.includes("/.git/hooks/") || p.endsWith("/.git/hooks");
|
|
1276
|
+
};
|
|
1184
1277
|
function looksLikePath(token) {
|
|
1185
1278
|
if (token.length === 0 || token === "-" || token.startsWith("-"))
|
|
1186
1279
|
return false;
|
|
@@ -3956,8 +4049,7 @@ function destroyTargetsOf(inv) {
|
|
|
3956
4049
|
}
|
|
3957
4050
|
function isDangerousDelete(resolved, ctx) {
|
|
3958
4051
|
const base = globBase(resolved);
|
|
3959
|
-
|
|
3960
|
-
if (t === "/" || t === "~" || t === "~/")
|
|
4052
|
+
if (base === "/" || homeForms(base, ctx.facts).some((t) => t === "~" || t === "~/"))
|
|
3961
4053
|
return true;
|
|
3962
4054
|
// the workspace root itself and every directory above it (hardening spec R2)
|
|
3963
4055
|
return base === ctx.facts.workspace || isAncestor(base, ctx.facts.workspace);
|
|
@@ -4002,17 +4094,40 @@ const CONFIG_REASONS = {
|
|
|
4002
4094
|
"ask.ssh": "Changes or prints SSH keys or configuration; this needs approval.",
|
|
4003
4095
|
"ask.secret-file": "Prints, copies or changes a credential file; this needs approval each time.",
|
|
4004
4096
|
};
|
|
4005
|
-
/**
|
|
4097
|
+
/** Logout and editor rc files: read by a program the person starts later, like a shell rc file. */
|
|
4098
|
+
function isEditorOrLogoutRc(t) {
|
|
4099
|
+
if (/^~\/\.(bash_logout|zlogout|logout|vimrc|gvimrc|exrc|nanorc|emacs)$/.test(t))
|
|
4100
|
+
return true;
|
|
4101
|
+
return t.startsWith("~/.vim/") || t.startsWith("~/.config/nvim/") || t.startsWith("~/.emacs.d/");
|
|
4102
|
+
}
|
|
4103
|
+
/**
|
|
4104
|
+
* Home locations whose files run later without the person asking: PATH shims (`~/.local/bin`,
|
|
4105
|
+
* `~/bin`, `~/.cargo/bin`),
|
|
4106
|
+
* desktop autostart entries, and the device's own work directory `~/capybara-device` (other
|
|
4107
|
+
* conversations' background task scripts live there). The work directory counts only when the
|
|
4108
|
+
* workspace is not inside it: a free conversation's workspace is a directory of it.
|
|
4109
|
+
*/
|
|
4110
|
+
function isRunLaterHomePath(t, facts) {
|
|
4111
|
+
const under = (dir) => t === dir || t.startsWith(`${dir}/`);
|
|
4112
|
+
if (RUN_LATER_HOME_DIRS.some(under))
|
|
4113
|
+
return true;
|
|
4114
|
+
return (under("~/capybara-device") &&
|
|
4115
|
+
!foldedForms(facts.workspace, facts).some((w) => w.startsWith("~/capybara-device/")));
|
|
4116
|
+
}
|
|
4117
|
+
/** PATH shims and desktop autostart entries in the home (case-folded). */
|
|
4118
|
+
const RUN_LATER_HOME_DIRS = ["~/.local/bin", "~/bin", "~/.cargo/bin", "~/.config/autostart"];
|
|
4119
|
+
/** The grant class of a secret or persistence path (judged on every case-folded home spelling). */
|
|
4006
4120
|
function configClassOf(path, facts) {
|
|
4007
|
-
const
|
|
4008
|
-
if (t === "~/.ssh" || t.startsWith("~/.ssh/"))
|
|
4121
|
+
const forms = foldedForms(path, facts);
|
|
4122
|
+
if (forms.some((t) => t === "~/.ssh" || t.startsWith("~/.ssh/")))
|
|
4009
4123
|
return "ask.ssh";
|
|
4010
4124
|
if (isGitHook(path) ||
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4125
|
+
forms.some((t) => isLaunchForm(t) ||
|
|
4126
|
+
t === "/etc/crontab" ||
|
|
4127
|
+
t.startsWith("/var/spool/cron") ||
|
|
4128
|
+
t.startsWith("/etc/cron.") ||
|
|
4129
|
+
t.startsWith("~/.config/systemd") ||
|
|
4130
|
+
isRunLaterHomePath(t, facts))) {
|
|
4016
4131
|
return "ask.persistence";
|
|
4017
4132
|
}
|
|
4018
4133
|
return isPersistencePath(path, facts) ? "ask.shell-config" : "ask.secret-file";
|
|
@@ -4046,9 +4161,7 @@ function configMatches(ctx) {
|
|
|
4046
4161
|
}
|
|
4047
4162
|
if (inv.program === "ssh-keygen")
|
|
4048
4163
|
add("ask.ssh", command, "Changes ~/.ssh; this needs approval.");
|
|
4049
|
-
if (inv.program === "git" &&
|
|
4050
|
-
inv.args[0] === "config" &&
|
|
4051
|
-
hasArg(inv.args.slice(1), "--global", "--system")) {
|
|
4164
|
+
if (inv.program === "git" && gitConfigChangesUserFile(inv.args)) {
|
|
4052
4165
|
add("ask.shell-config", command, "Changes ~/.gitconfig; this needs approval.");
|
|
4053
4166
|
}
|
|
4054
4167
|
if (inv.program === "security" && inv.args.some((a) => KEYCHAIN_DUMP.test(a))) {
|
|
@@ -4104,19 +4217,23 @@ function linkSources(inv, command, ctx) {
|
|
|
4104
4217
|
return out;
|
|
4105
4218
|
}
|
|
4106
4219
|
/**
|
|
4107
|
-
* What a link would expose (hardening spec R3): a credential, SSH, persistence or device path,
|
|
4108
|
-
* the home directory or `/` itself (a link to them reaches every secret under them) is
|
|
4109
|
-
* `sensitive
|
|
4220
|
+
* What a link would expose (hardening spec R3): a credential, SSH, persistence or device path, and
|
|
4221
|
+
* the home directory or `/` itself (a link to them reaches every secret under them), is
|
|
4222
|
+
* `sensitive` wherever it lies, inside the workspace too (a project at the owner's home makes the
|
|
4223
|
+
* home the workspace: project root spec §4.3); a parent of the workspace is `sensitive` outside
|
|
4224
|
+
* it; anything else outside the workspace and temporary files is `outside`.
|
|
4110
4225
|
*/
|
|
4111
4226
|
function linkClass(path, ctx) {
|
|
4227
|
+
if (isHomeLevelSensitive(path, ctx.facts) || isDevicePath(path, ctx.facts))
|
|
4228
|
+
return "sensitive";
|
|
4229
|
+
// the home directory and `/` themselves reach every secret under them, whatever the workspace
|
|
4230
|
+
const base = globBase(path);
|
|
4231
|
+
if (base === "/" || homeForms(base, ctx.facts).some((t) => t === "~"))
|
|
4232
|
+
return "sensitive";
|
|
4112
4233
|
if (inside(path, ctx.facts.workspace) || tmpRootOf(path))
|
|
4113
4234
|
return null;
|
|
4114
|
-
if (
|
|
4115
|
-
isPersistencePath(path, ctx.facts) ||
|
|
4116
|
-
isDevicePath(path, ctx.facts) ||
|
|
4117
|
-
isDangerousDelete(path, ctx)) {
|
|
4235
|
+
if (isDangerousDelete(path, ctx))
|
|
4118
4236
|
return "sensitive";
|
|
4119
|
-
}
|
|
4120
4237
|
return "outside";
|
|
4121
4238
|
}
|
|
4122
4239
|
const RULES = [
|
|
@@ -4239,7 +4356,7 @@ const RULES = [
|
|
|
4239
4356
|
return false;
|
|
4240
4357
|
if (inv.args[0] === "push" && gitPushKind(inv.args.slice(1)) !== null)
|
|
4241
4358
|
return false;
|
|
4242
|
-
if (
|
|
4359
|
+
if (gitConfigChangesUserFile(inv.args))
|
|
4243
4360
|
return false;
|
|
4244
4361
|
return true;
|
|
4245
4362
|
});
|
|
@@ -5112,9 +5229,10 @@ export function reviewRules(command, facts) {
|
|
|
5112
5229
|
return { outcome: strictest(hits), hits };
|
|
5113
5230
|
}
|
|
5114
5231
|
/**
|
|
5115
|
-
* The same table for a file-tool write:
|
|
5116
|
-
*
|
|
5117
|
-
* outside
|
|
5232
|
+
* The same table for a file-tool write: the device's own files are denied; git hooks and
|
|
5233
|
+
* home-level sensitive paths (shell rc files, SSH, launch agents, credentials) ask wherever they
|
|
5234
|
+
* lie, inside the workspace too; other workspace and tmp writes pass; a `.env*` file outside the
|
|
5235
|
+
* workspace asks; anything else outside asks to write outside.
|
|
5118
5236
|
*/
|
|
5119
5237
|
export function reviewWrite(path, facts) {
|
|
5120
5238
|
const resolved = resolveFacts(facts);
|
|
@@ -5155,6 +5273,11 @@ export function reviewWrite(path, facts) {
|
|
|
5155
5273
|
],
|
|
5156
5274
|
};
|
|
5157
5275
|
}
|
|
5276
|
+
// home-level sensitive paths ask wherever they lie, inside the workspace fact too
|
|
5277
|
+
if (isHomeLevelSensitive(absolute, resolved)) {
|
|
5278
|
+
const id = configClassOf(absolute, resolved);
|
|
5279
|
+
return { outcome: "ask", hits: [{ id, outcome: "ask", reason: CONFIG_REASONS[id] }] };
|
|
5280
|
+
}
|
|
5158
5281
|
if (inside(absolute, resolved.workspace)) {
|
|
5159
5282
|
return {
|
|
5160
5283
|
outcome: "allow",
|
|
@@ -5179,7 +5302,7 @@ export function reviewWrite(path, facts) {
|
|
|
5179
5302
|
],
|
|
5180
5303
|
};
|
|
5181
5304
|
}
|
|
5182
|
-
if (
|
|
5305
|
+
if (isSecretPath(absolute, resolved)) {
|
|
5183
5306
|
const id = configClassOf(absolute, resolved);
|
|
5184
5307
|
return { outcome: "ask", hits: [{ id, outcome: "ask", reason: CONFIG_REASONS[id] }] };
|
|
5185
5308
|
}
|
|
@@ -44,6 +44,20 @@ export interface ReviewFacts {
|
|
|
44
44
|
attended: boolean;
|
|
45
45
|
/** The directory the command runs in; default: the workspace. */
|
|
46
46
|
cwd?: string;
|
|
47
|
+
/**
|
|
48
|
+
* The owner's home directory, which `~` and the home-level sensitive paths (shell rc files,
|
|
49
|
+
* SSH, credentials) are judged against. The pipeline passes it from the machine (or the device's
|
|
50
|
+
* workspace), never from a project root, so a project outside the home keeps every home rule
|
|
51
|
+
* (project root spec §4.3). Absent or null: derived from the workspace's `/home/<u>`,
|
|
52
|
+
* `/Users/<u>` or `/root` prefix.
|
|
53
|
+
*/
|
|
54
|
+
home?: string | null;
|
|
55
|
+
/**
|
|
56
|
+
* The home prefix of the device's own workspace (`homeOf` of it), judged beside `home` and the
|
|
57
|
+
* working root's prefix: a project outside every home (`/opt/app`) with an implausible reported
|
|
58
|
+
* home (`/`) still protects the real home. Absent or null: none.
|
|
59
|
+
*/
|
|
60
|
+
deviceHome?: string | null;
|
|
47
61
|
/**
|
|
48
62
|
* Absolute paths this conversation's own tool calls wrote (`Write` / `Edit`, and the write
|
|
49
63
|
* targets of its earlier `Bash` lines): running one of them with an interpreter is not a
|
|
@@ -41,6 +41,13 @@ export interface SandboxUseContext {
|
|
|
41
41
|
holderConversationId: string;
|
|
42
42
|
/** Passed with every `exec` (audit and attribution). */
|
|
43
43
|
actor: SandboxActor;
|
|
44
|
+
/**
|
|
45
|
+
* A use that tells the model nothing (the run-start read of a bound project): it does not mark
|
|
46
|
+
* the holder as having seen the instance, so the holder's next ordinary use still learns that
|
|
47
|
+
* the instance started, restarted or had its files reset ({@link SandboxUseInfo}); what this use
|
|
48
|
+
* itself caused (a creation, a rebuild) is kept for that next use.
|
|
49
|
+
*/
|
|
50
|
+
silent?: true;
|
|
44
51
|
}
|
|
45
52
|
export type { SandboxProviderEntry } from "./providers.js";
|
|
46
53
|
type Row = Selectable<DeviceInstancesTable>;
|
|
@@ -213,7 +220,7 @@ export declare class SandboxService {
|
|
|
213
220
|
private readonly background;
|
|
214
221
|
constructor(db: KernelDb,
|
|
215
222
|
/** The record of the instance each holder last used (`capk:sandbox-seen:…`). */
|
|
216
|
-
redis: Pick<Redis, "set">, leases: SandboxLeases,
|
|
223
|
+
redis: Pick<Redis, "set" | "getdel">, leases: SandboxLeases,
|
|
217
224
|
/** The providers (read at every call: providers are ready after the extension load). */
|
|
218
225
|
providers: Pick<SandboxProviders, "cloud" | "forName">, config: Pick<KernelConfigService, "get" | "fieldSource">, log: Pick<KernelLogger, "info" | "warn">,
|
|
219
226
|
/** Background tasks lost while their process may live on (killed after a resume). */
|
|
@@ -375,6 +382,14 @@ export declare class SandboxService {
|
|
|
375
382
|
* machine: until a new login, which resets the row). A failed write only logs.
|
|
376
383
|
*/
|
|
377
384
|
private filesGone;
|
|
385
|
+
/**
|
|
386
|
+
* A silent use ({@link SandboxUseContext.silent}) of `holder`: the seen record is left alone, so
|
|
387
|
+
* the holder's next ordinary use compares against the instance it last saw itself (and learns
|
|
388
|
+
* of a restart or a files reset since); a creation or rebuild this use caused is kept
|
|
389
|
+
* (`capk:sandbox-notice:<env>:<holder>`, merged with an earlier one for the same instance, same
|
|
390
|
+
* TTL as the seen record) for {@link seenBy} to tell. Best effort: a Redis error only logs.
|
|
391
|
+
*/
|
|
392
|
+
private deferNotice;
|
|
378
393
|
/**
|
|
379
394
|
* Records that `holder` uses the instance of `e` (`capk:sandbox-seen:<env>:<holder>` =
|
|
380
395
|
* `<created_at>:<fs_resets>`, with a TTL of the inactivity destruction plus a day). When the
|