lastlight-core 0.21.11 → 0.21.12
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/deploy/k8s/README.md +111 -34
- package/deploy/k8s/architecture.md +199 -0
- package/deploy/k8s/configmap.yaml +14 -3
- package/deploy/k8s/harness-deployment.yaml +111 -0
- package/deploy/k8s/kustomization.yaml +10 -8
- package/deploy/k8s/sandbox-namespace.yaml +14 -0
- package/deploy/k8s/sandbox-quota.yaml +37 -0
- package/deploy/k8s/sandbox-rbac.yaml +60 -0
- package/dist/admin/routes.js +66 -10
- package/dist/admin/routes.js.map +1 -1
- package/dist/config/config.d.ts +36 -0
- package/dist/config/config.js +101 -3
- package/dist/config/config.js.map +1 -1
- package/dist/cron/review-discovery.d.ts +54 -0
- package/dist/cron/review-discovery.js +70 -0
- package/dist/cron/review-discovery.js.map +1 -0
- package/dist/engine/executors/orchestrator.js +124 -58
- package/dist/engine/executors/orchestrator.js.map +1 -1
- package/dist/engine/github/profiles.d.ts +12 -1
- package/dist/engine/github/profiles.js +33 -1
- package/dist/engine/github/profiles.js.map +1 -1
- package/dist/index.js +52 -13
- package/dist/index.js.map +1 -1
- package/dist/sandbox/artifact-backend.d.ts +40 -0
- package/dist/sandbox/artifact-backend.js +67 -0
- package/dist/sandbox/artifact-backend.js.map +1 -0
- package/dist/sandbox/artifact-store.d.ts +55 -0
- package/dist/sandbox/artifact-store.js +203 -0
- package/dist/sandbox/artifact-store.js.map +1 -0
- package/dist/sandbox/docker.d.ts +2 -1
- package/dist/sandbox/docker.js +3 -3
- package/dist/sandbox/docker.js.map +1 -1
- package/dist/sandbox/k8s/agent-context-registry.d.ts +25 -0
- package/dist/sandbox/k8s/agent-context-registry.js +45 -0
- package/dist/sandbox/k8s/agent-context-registry.js.map +1 -0
- package/dist/sandbox/k8s/agent-context-route.d.ts +13 -0
- package/dist/sandbox/k8s/agent-context-route.js +21 -0
- package/dist/sandbox/k8s/agent-context-route.js.map +1 -0
- package/dist/sandbox/k8s/artifact-upload-route.d.ts +12 -0
- package/dist/sandbox/k8s/artifact-upload-route.js +40 -0
- package/dist/sandbox/k8s/artifact-upload-route.js.map +1 -0
- package/dist/sandbox/k8s/client.d.ts +22 -0
- package/dist/sandbox/k8s/client.js +35 -0
- package/dist/sandbox/k8s/client.js.map +1 -0
- package/dist/sandbox/k8s/egress-apply.d.ts +14 -0
- package/dist/sandbox/k8s/egress-apply.js +44 -0
- package/dist/sandbox/k8s/egress-apply.js.map +1 -0
- package/dist/sandbox/k8s/egress-ensurer.d.ts +37 -0
- package/dist/sandbox/k8s/egress-ensurer.js +54 -0
- package/dist/sandbox/k8s/egress-ensurer.js.map +1 -0
- package/dist/sandbox/k8s/egress-policy.d.ts +112 -0
- package/dist/sandbox/k8s/egress-policy.js +118 -0
- package/dist/sandbox/k8s/egress-policy.js.map +1 -0
- package/dist/sandbox/k8s/init-agent-context.d.ts +20 -0
- package/dist/sandbox/k8s/init-agent-context.js +35 -0
- package/dist/sandbox/k8s/init-agent-context.js.map +1 -0
- package/dist/sandbox/k8s/init-clone.d.ts +53 -0
- package/dist/sandbox/k8s/init-clone.js +114 -0
- package/dist/sandbox/k8s/init-clone.js.map +1 -0
- package/dist/sandbox/k8s/init-skills.d.ts +13 -0
- package/dist/sandbox/k8s/init-skills.js +28 -0
- package/dist/sandbox/k8s/init-skills.js.map +1 -0
- package/dist/sandbox/k8s/kubernetes-sandbox.d.ts +179 -0
- package/dist/sandbox/k8s/kubernetes-sandbox.js +418 -0
- package/dist/sandbox/k8s/kubernetes-sandbox.js.map +1 -0
- package/dist/sandbox/k8s/log-stream.d.ts +4 -0
- package/dist/sandbox/k8s/log-stream.js +43 -0
- package/dist/sandbox/k8s/log-stream.js.map +1 -0
- package/dist/sandbox/k8s/naming.d.ts +19 -0
- package/dist/sandbox/k8s/naming.js +35 -0
- package/dist/sandbox/k8s/naming.js.map +1 -0
- package/dist/sandbox/k8s/pod-lifecycle.d.ts +40 -0
- package/dist/sandbox/k8s/pod-lifecycle.js +151 -0
- package/dist/sandbox/k8s/pod-lifecycle.js.map +1 -0
- package/dist/sandbox/k8s/pod-status.d.ts +46 -0
- package/dist/sandbox/k8s/pod-status.js +83 -0
- package/dist/sandbox/k8s/pod-status.js.map +1 -0
- package/dist/sandbox/k8s/pod.d.ts +79 -0
- package/dist/sandbox/k8s/pod.js +115 -0
- package/dist/sandbox/k8s/pod.js.map +1 -0
- package/dist/sandbox/k8s/pvc.d.ts +20 -0
- package/dist/sandbox/k8s/pvc.js +26 -0
- package/dist/sandbox/k8s/pvc.js.map +1 -0
- package/dist/sandbox/k8s/quota.d.ts +34 -0
- package/dist/sandbox/k8s/quota.js +52 -0
- package/dist/sandbox/k8s/quota.js.map +1 -0
- package/dist/sandbox/k8s/reclaim.d.ts +50 -0
- package/dist/sandbox/k8s/reclaim.js +141 -0
- package/dist/sandbox/k8s/reclaim.js.map +1 -0
- package/dist/sandbox/k8s/resource-name.d.ts +33 -0
- package/dist/sandbox/k8s/resource-name.js +49 -0
- package/dist/sandbox/k8s/resource-name.js.map +1 -0
- package/dist/sandbox/k8s/run-agent-script.d.ts +60 -0
- package/dist/sandbox/k8s/run-agent-script.js +48 -0
- package/dist/sandbox/k8s/run-agent-script.js.map +1 -0
- package/dist/sandbox/k8s/run-id.d.ts +23 -0
- package/dist/sandbox/k8s/run-id.js +32 -0
- package/dist/sandbox/k8s/run-id.js.map +1 -0
- package/dist/sandbox/k8s/run-secrets.d.ts +75 -0
- package/dist/sandbox/k8s/run-secrets.js +115 -0
- package/dist/sandbox/k8s/run-secrets.js.map +1 -0
- package/dist/sandbox/k8s/secret.d.ts +20 -0
- package/dist/sandbox/k8s/secret.js +38 -0
- package/dist/sandbox/k8s/secret.js.map +1 -0
- package/dist/sandbox/k8s/skill-bundle-route.d.ts +10 -0
- package/dist/sandbox/k8s/skill-bundle-route.js +18 -0
- package/dist/sandbox/k8s/skill-bundle-route.js.map +1 -0
- package/dist/sandbox/k8s/skill-bundle.d.ts +36 -0
- package/dist/sandbox/k8s/skill-bundle.js +85 -0
- package/dist/sandbox/k8s/skill-bundle.js.map +1 -0
- package/dist/sandbox/k8s/sweep.d.ts +47 -0
- package/dist/sandbox/k8s/sweep.js +29 -0
- package/dist/sandbox/k8s/sweep.js.map +1 -0
- package/dist/sandbox/k8s/workspace-provisioner.d.ts +51 -0
- package/dist/sandbox/k8s/workspace-provisioner.js +64 -0
- package/dist/sandbox/k8s/workspace-provisioner.js.map +1 -0
- package/dist/sandbox/sandbox.d.ts +20 -1
- package/dist/sandbox/sandbox.js +22 -1
- package/dist/sandbox/sandbox.js.map +1 -1
- package/dist/state/workflow-run-store.d.ts +11 -0
- package/dist/state/workflow-run-store.js +19 -0
- package/dist/state/workflow-run-store.js.map +1 -1
- package/dist/workflows/admission.d.ts +12 -0
- package/dist/workflows/admission.js +13 -2
- package/dist/workflows/admission.js.map +1 -1
- package/dist/workflows/handlers/post-review.d.ts +21 -0
- package/dist/workflows/handlers/post-review.js +56 -13
- package/dist/workflows/handlers/post-review.js.map +1 -1
- package/dist/workflows/resume.js +6 -0
- package/dist/workflows/resume.js.map +1 -1
- package/dist/workflows/runner.d.ts +3 -1
- package/dist/workflows/runner.js +73 -15
- package/dist/workflows/runner.js.map +1 -1
- package/dist/workflows/simple.d.ts +13 -1
- package/dist/workflows/simple.js +37 -4
- package/dist/workflows/simple.js.map +1 -1
- package/package.json +19 -18
- package/skills/issue-triage/SKILL.md +17 -0
- package/workflows/cron-review.yaml +14 -1
- package/workflows/issue-triage.yaml +6 -0
- package/deploy/k8s/deployment.yaml +0 -63
- package/deploy/k8s/generic-device-plugin.yaml +0 -63
- package/deploy/k8s/namespace.yaml +0 -10
- package/deploy/k8s/pvc.yaml +0 -13
- package/deploy/k8s/service.yaml +0 -12
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/** Pod/selector label choosing which egress policy applies. */
|
|
2
|
+
export const EGRESS_POLICY_LABEL = "egress-policy";
|
|
3
|
+
/** Single derivation point: the backend-agnostic intent-only {@link EgressPolicy}
|
|
4
|
+
* (`sandbox.ts`) → the k8s-specific {@link EgressMode} label value. */
|
|
5
|
+
export function egressModeFor(policy) {
|
|
6
|
+
return policy.unrestricted ? "open" : "strict";
|
|
7
|
+
}
|
|
8
|
+
/** Name of the CiliumNetworkPolicy applied to strict-egress sandbox pods. */
|
|
9
|
+
export const STRICT_POLICY_NAME = "lastlight-sandbox-egress-strict";
|
|
10
|
+
/** Name of the CiliumNetworkPolicy applied to open-egress sandbox pods. */
|
|
11
|
+
export const OPEN_POLICY_NAME = "lastlight-sandbox-egress-open";
|
|
12
|
+
/** Cilium CiliumNetworkPolicy CRD coordinates (client-node CustomObjectsApi). */
|
|
13
|
+
export const CILIUM_GROUP = "cilium.io";
|
|
14
|
+
export const CILIUM_VERSION = "v2";
|
|
15
|
+
export const CILIUM_CNP_PLURAL = "ciliumnetworkpolicies";
|
|
16
|
+
/**
|
|
17
|
+
* Private / link-local / loopback ranges the OPEN policy excepts from its
|
|
18
|
+
* broad `0.0.0.0/0` allow — the SSRF floor. RFC-1918 covers the cluster pod /
|
|
19
|
+
* service CIDRs on the target cluster (all within 10/8), and 169.254.0.0/16
|
|
20
|
+
* covers the cloud-metadata literal. Strict mode needs none of this: with only
|
|
21
|
+
* DNS + toFQDNs rules, a strict pod can reach *only* an allowlisted FQDN's
|
|
22
|
+
* resolved IP, so private space is unreachable by construction.
|
|
23
|
+
*/
|
|
24
|
+
const PRIVATE_CIDRS_V4 = [
|
|
25
|
+
"10.0.0.0/8",
|
|
26
|
+
"172.16.0.0/12",
|
|
27
|
+
"192.168.0.0/16",
|
|
28
|
+
"169.254.0.0/16",
|
|
29
|
+
"127.0.0.0/8",
|
|
30
|
+
];
|
|
31
|
+
const PRIVATE_CIDRS_V6 = ["::1/128", "fc00::/7", "fe80::/10"];
|
|
32
|
+
/** Selects the in-cluster DNS service so Cilium's DNS proxy sees the queries. */
|
|
33
|
+
const KUBE_DNS_SELECTOR = {
|
|
34
|
+
"k8s:io.kubernetes.pod.namespace": "kube-system",
|
|
35
|
+
"k8s-app": "kube-dns",
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* DNS egress rule shared by both policies: allow port 53 to kube-dns AND turn
|
|
39
|
+
* on the DNS proxy (`rules.dns: [{ matchPattern: "*" }]`). WITHOUT this rule
|
|
40
|
+
* `toFQDNs` never learns any IP and every connection is denied — Cilium only
|
|
41
|
+
* permits connecting to an IP it was allowed to resolve. This is the mechanism
|
|
42
|
+
* that closes the private-IP SSRF gap the docker SNI-peek admits it cannot.
|
|
43
|
+
*/
|
|
44
|
+
function dnsEgressRule() {
|
|
45
|
+
return {
|
|
46
|
+
toEndpoints: [{ matchLabels: KUBE_DNS_SELECTOR }],
|
|
47
|
+
toPorts: [
|
|
48
|
+
{ ports: [{ port: "53", protocol: "ANY" }], rules: { dns: [{ matchPattern: "*" }] } },
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** Permit sandbox→harness only, by Cilium identity (namespace + labels), on the
|
|
53
|
+
* harness port — an identity rule, not a CIDR hole. Carries the Section 7 skill
|
|
54
|
+
* fetch under both strict and open. */
|
|
55
|
+
function harnessEgressRule(h) {
|
|
56
|
+
return {
|
|
57
|
+
toEndpoints: [
|
|
58
|
+
{ matchLabels: { "k8s:io.kubernetes.pod.namespace": h.namespace, ...h.labels } },
|
|
59
|
+
],
|
|
60
|
+
toPorts: [{ ports: [{ port: String(h.port), protocol: "TCP" }] }],
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Expand each bare allowlist host to the two Cilium FQDN forms it needs:
|
|
65
|
+
* `matchName` for the apex, `matchPattern: "*.host"` for every subdomain
|
|
66
|
+
* (the pattern alone excludes the apex). Mirrors nginx's `.host` and CoreDNS's
|
|
67
|
+
* `(^|\.)host\.$` — same apex+subdomain convention, one shared source list.
|
|
68
|
+
*/
|
|
69
|
+
export function fqdnRulesFor(hosts) {
|
|
70
|
+
const rules = [];
|
|
71
|
+
for (const host of hosts) {
|
|
72
|
+
rules.push({ matchName: host });
|
|
73
|
+
rules.push({ matchPattern: `*.${host}` });
|
|
74
|
+
}
|
|
75
|
+
return rules;
|
|
76
|
+
}
|
|
77
|
+
function policy(name, namespace, value, egress) {
|
|
78
|
+
return {
|
|
79
|
+
apiVersion: `${CILIUM_GROUP}/${CILIUM_VERSION}`,
|
|
80
|
+
kind: "CiliumNetworkPolicy",
|
|
81
|
+
metadata: { name, namespace },
|
|
82
|
+
spec: { endpointSelector: { matchLabels: { [EGRESS_POLICY_LABEL]: value } }, egress },
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/** Strict = DNS + the allowlist FQDNs on 443/TCP; everything else default-denied. */
|
|
86
|
+
export function renderStrictEgressPolicy(opts) {
|
|
87
|
+
const egress = [
|
|
88
|
+
dnsEgressRule(),
|
|
89
|
+
{ toFQDNs: fqdnRulesFor(opts.hosts), toPorts: [{ ports: [{ port: "443", protocol: "TCP" }] }] },
|
|
90
|
+
];
|
|
91
|
+
if (opts.harness)
|
|
92
|
+
egress.push(harnessEgressRule(opts.harness));
|
|
93
|
+
return policy(STRICT_POLICY_NAME, opts.namespace, "strict", egress);
|
|
94
|
+
}
|
|
95
|
+
/** Open = DNS + broad 80/443 egress minus the private-CIDR SSRF floor. */
|
|
96
|
+
export function renderOpenEgressPolicy(opts) {
|
|
97
|
+
const egress = [
|
|
98
|
+
dnsEgressRule(),
|
|
99
|
+
{
|
|
100
|
+
toCIDRSet: [
|
|
101
|
+
{ cidr: "0.0.0.0/0", except: PRIVATE_CIDRS_V4 },
|
|
102
|
+
{ cidr: "::/0", except: PRIVATE_CIDRS_V6 },
|
|
103
|
+
],
|
|
104
|
+
toPorts: [{ ports: [{ port: "443", protocol: "TCP" }, { port: "80", protocol: "TCP" }] }],
|
|
105
|
+
},
|
|
106
|
+
];
|
|
107
|
+
if (opts.harness)
|
|
108
|
+
egress.push(harnessEgressRule(opts.harness));
|
|
109
|
+
return policy(OPEN_POLICY_NAME, opts.namespace, "open", egress);
|
|
110
|
+
}
|
|
111
|
+
/** Render the strict/open CiliumNetworkPolicy pair for one sandbox namespace. */
|
|
112
|
+
export function renderEgressPolicies(opts) {
|
|
113
|
+
return {
|
|
114
|
+
strict: renderStrictEgressPolicy(opts),
|
|
115
|
+
open: renderOpenEgressPolicy({ namespace: opts.namespace, harness: opts.harness }),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=egress-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"egress-policy.js","sourceRoot":"","sources":["../../../src/sandbox/k8s/egress-policy.ts"],"names":[],"mappings":"AAEA,+DAA+D;AAC/D,MAAM,CAAC,MAAM,mBAAmB,GAAG,eAAe,CAAC;AAOnD;wEACwE;AACxE,MAAM,UAAU,aAAa,CAAC,MAAoB;IAChD,OAAO,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC;AACjD,CAAC;AAED,6EAA6E;AAC7E,MAAM,CAAC,MAAM,kBAAkB,GAAG,iCAAiC,CAAC;AACpE,2EAA2E;AAC3E,MAAM,CAAC,MAAM,gBAAgB,GAAG,+BAA+B,CAAC;AAEhE,iFAAiF;AACjF,MAAM,CAAC,MAAM,YAAY,GAAG,WAAW,CAAC;AACxC,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC;AACnC,MAAM,CAAC,MAAM,iBAAiB,GAAG,uBAAuB,CAAC;AAEzD;;;;;;;GAOG;AACH,MAAM,gBAAgB,GAAG;IACvB,YAAY;IACZ,eAAe;IACf,gBAAgB;IAChB,gBAAgB;IAChB,aAAa;CACd,CAAC;AACF,MAAM,gBAAgB,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;AAE9D,iFAAiF;AACjF,MAAM,iBAAiB,GAAG;IACxB,iCAAiC,EAAE,aAAa;IAChD,SAAS,E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AC,OAAO,CAAC,CAAC,CAAC;IAC/D,OAAO,MAAM,CAAC,gBAAgB,EAAE,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAClE,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,oBAAoB,CAAC,IAIpC;IACC,OAAO;QACL,MAAM,EAAE,wBAAwB,CAAC,IAAI,CAAC;QACtC,IAAI,EAAE,sBAAsB,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;KACnF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { V1Container } from "@kubernetes/client-node";
|
|
2
|
+
/**
|
|
3
|
+
* The agent-context initContainer: fetch the per-run resolved agent-context
|
|
4
|
+
* (persona/hard-rules) from the harness (bearer token from the creds Secret
|
|
5
|
+
* env, endpoint as a positional arg so it is never interpolated into the script)
|
|
6
|
+
* and write it to `<WORKSPACE_DIR>/AGENTS.md` — the workspace ROOT, never a
|
|
7
|
+
* cwd-relative path, so a repo-write phase's `git add -A` can't commit the bot's
|
|
8
|
+
* AGENTS.md into the customer's checkout (cwd is `<WORKSPACE_DIR>/<repo>` after a
|
|
9
|
+
* pre-clone). agentic-pi reads `AGENTS.md` from cwd, and the agent container's
|
|
10
|
+
* `workingDir` is inside this same workspace volume, so the file is visible.
|
|
11
|
+
*
|
|
12
|
+
* `envFrom` (creds Secret) is attached by `buildPodManifest`. `-f` makes curl
|
|
13
|
+
* fail the init on a non-2xx so a bad fetch surfaces (checkInitContainerFailure
|
|
14
|
+
* appends its logs); with `-f`, curl also suppresses the error body so a failed
|
|
15
|
+
* fetch never leaves a partial/garbage `AGENTS.md` behind.
|
|
16
|
+
*/
|
|
17
|
+
export declare function buildAgentContextInitContainer(image: string, opts: {
|
|
18
|
+
endpoint: string;
|
|
19
|
+
runAsUser: number;
|
|
20
|
+
}): V1Container;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { WORKSPACE_DIR } from "./pod.js";
|
|
2
|
+
/**
|
|
3
|
+
* The agent-context initContainer: fetch the per-run resolved agent-context
|
|
4
|
+
* (persona/hard-rules) from the harness (bearer token from the creds Secret
|
|
5
|
+
* env, endpoint as a positional arg so it is never interpolated into the script)
|
|
6
|
+
* and write it to `<WORKSPACE_DIR>/AGENTS.md` — the workspace ROOT, never a
|
|
7
|
+
* cwd-relative path, so a repo-write phase's `git add -A` can't commit the bot's
|
|
8
|
+
* AGENTS.md into the customer's checkout (cwd is `<WORKSPACE_DIR>/<repo>` after a
|
|
9
|
+
* pre-clone). agentic-pi reads `AGENTS.md` from cwd, and the agent container's
|
|
10
|
+
* `workingDir` is inside this same workspace volume, so the file is visible.
|
|
11
|
+
*
|
|
12
|
+
* `envFrom` (creds Secret) is attached by `buildPodManifest`. `-f` makes curl
|
|
13
|
+
* fail the init on a non-2xx so a bad fetch surfaces (checkInitContainerFailure
|
|
14
|
+
* appends its logs); with `-f`, curl also suppresses the error body so a failed
|
|
15
|
+
* fetch never leaves a partial/garbage `AGENTS.md` behind.
|
|
16
|
+
*/
|
|
17
|
+
export function buildAgentContextInitContainer(image, opts) {
|
|
18
|
+
const script = 'curl -fsS -H "Authorization: Bearer $LASTLIGHT_AGENT_CONTEXT_TOKEN" ' +
|
|
19
|
+
`"$1/internal/agent-context" -o ${WORKSPACE_DIR}/AGENTS.md`;
|
|
20
|
+
return {
|
|
21
|
+
name: "agent-context",
|
|
22
|
+
image,
|
|
23
|
+
command: ["sh", "-c", script],
|
|
24
|
+
args: ["sh", opts.endpoint],
|
|
25
|
+
envFrom: [],
|
|
26
|
+
volumeMounts: [{ name: "workspace", mountPath: WORKSPACE_DIR }],
|
|
27
|
+
securityContext: {
|
|
28
|
+
allowPrivilegeEscalation: false,
|
|
29
|
+
runAsNonRoot: true,
|
|
30
|
+
runAsUser: opts.runAsUser,
|
|
31
|
+
capabilities: { drop: ["ALL"] },
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=init-agent-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init-agent-context.js","sourceRoot":"","sources":["../../../src/sandbox/k8s/init-agent-context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,8BAA8B,CAC5C,KAAa,EACb,IAA6C;IAE7C,MAAM,MAAM,GACV,sEAAsE;QACtE,kCAAkC,aAAa,YAAY,CAAC;IAC9D,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,KAAK;QACL,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC;QAC7B,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC;QAC3B,OAAO,EAAE,EAAE;QACX,YAAY,EAAE,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC;QAC/D,eAAe,EAAE;YACf,wBAAwB,EAAE,KAAK;YAC/B,YAAY,EAAE,IAAI;YAClB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,YAAY,EAAE,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,EAAE;SAChC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { V1Container } from "@kubernetes/client-node";
|
|
2
|
+
export interface CloneSpec {
|
|
3
|
+
owner: string;
|
|
4
|
+
repo: string;
|
|
5
|
+
branch: string;
|
|
6
|
+
cwd: string;
|
|
7
|
+
runAsUser: number;
|
|
8
|
+
/**
|
|
9
|
+
* PR base branch. When set (and distinct from `branch`), the script fetches it
|
|
10
|
+
* and deepens both refs to a shared merge-base so `git diff origin/<base>...HEAD`
|
|
11
|
+
* works — for both the fresh clone and the reuse-refresh path. Skipped for a
|
|
12
|
+
* `recreateFromBase` run.
|
|
13
|
+
*/
|
|
14
|
+
baseBranch?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Owning workflow run id, stamped into a `<cwd>/.lastlight-run` marker so a
|
|
17
|
+
* reused PVC can tell "next phase of the same run" (preserve the checkout —
|
|
18
|
+
* the architect's plan.md survives) from "a fresh run reusing this PR's dir"
|
|
19
|
+
* (refresh to the new head). Undefined ⇒ always preserve (the safe direction).
|
|
20
|
+
*/
|
|
21
|
+
runId?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Recreate the checkout from the default branch on a different-run reuse
|
|
24
|
+
* instead of refreshing the (possibly stale) feature branch: discard the
|
|
25
|
+
* leftover checkout and re-clone the default, cutting `branch` locally off it
|
|
26
|
+
* (issue #153, `build`). A same-run reuse still preserves.
|
|
27
|
+
*/
|
|
28
|
+
recreateFromBase?: boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Minimal clone init (locked decision #2): clone the branch shallow-ish; if the
|
|
32
|
+
* branch isn't on the remote yet (build-style first run), clone the default
|
|
33
|
+
* branch and cut the branch locally.
|
|
34
|
+
*
|
|
35
|
+
* Reuse (a per-(repo,PR) PVC already holds a checkout) is marker-gated, mirroring
|
|
36
|
+
* the host `prePopulateWorkspace`: the same run preserves the checkout (a later
|
|
37
|
+
* phase reads what an earlier one wrote), a different run refreshes the head
|
|
38
|
+
* (`git fetch` + `reset --hard` + `clean -fdx -e node_modules`) or, for a
|
|
39
|
+
* recreate-from-base run, re-clones the default branch. For PR-diff workflows the
|
|
40
|
+
* base branch is fetched + deepened to a shared merge-base on both the fresh and
|
|
41
|
+
* refresh paths so `git diff origin/<base>...HEAD` resolves.
|
|
42
|
+
*
|
|
43
|
+
* Auth is the github.com-scoped `http.extraheader` delivered as `GIT_CONFIG_*`
|
|
44
|
+
* env from the creds Secret (agentGitIdentityEnv) — no token in any URL.
|
|
45
|
+
*
|
|
46
|
+
* owner/repo/branch/cwd/base/runId are NOT validated upstream (branch is the PR
|
|
47
|
+
* head ref, attacker-named for external pr-review/pr-fix PRs) — so they're passed
|
|
48
|
+
* as positional args to a fixed script rather than interpolated into shell text.
|
|
49
|
+
* `sh -c CLONE_SCRIPT sh <owner> <repo> <branch> <cwd> <base> <runId> <recreate>`
|
|
50
|
+
* binds argv to `$1`..`$7` at exec time, immune to quote-breaking regardless of
|
|
51
|
+
* characters.
|
|
52
|
+
*/
|
|
53
|
+
export declare function buildCloneInitContainer(image: string, spec: CloneSpec): V1Container;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// A fixed script — untrusted values (owner/repo/branch/cwd/base/runId) arrive as
|
|
2
|
+
// positional args ($1..$7), NEVER interpolated into shell text, so a branch name
|
|
3
|
+
// containing shell metacharacters cannot break out. `--` before the URL/dir
|
|
4
|
+
// positionals blocks flag-smuggling on a value starting with `-`.
|
|
5
|
+
//
|
|
6
|
+
// Existing checkout (reused PVC): compare the `.lastlight-run` marker to decide.
|
|
7
|
+
// Same run (or no run id) → preserve, exactly as before. A different run → refresh
|
|
8
|
+
// the head (fetch + reset --hard + `clean -fdx -e node_modules`, keeping the deps
|
|
9
|
+
// tree warm) or, for a recreate-from-base run, discard and re-clone the default.
|
|
10
|
+
// The head refresh is best-effort: a failed fetch preserves the existing checkout
|
|
11
|
+
// rather than leaving a half-reset tree (mirrors the host `refreshExistingClone`).
|
|
12
|
+
// `ensure_base` fetches + deepens `origin/<base>` for the three-dot PR diff on
|
|
13
|
+
// both the fresh-clone and refresh paths (mirrors the host `ensureBaseAvailable`).
|
|
14
|
+
const CLONE_SCRIPT = [
|
|
15
|
+
"set -eu",
|
|
16
|
+
'owner="$1"; repo="$2"; branch="$3"; ws="$4"; base="$5"; run_id="$6"; recreate="$7"',
|
|
17
|
+
'repo_dir="$ws/$repo"',
|
|
18
|
+
'marker="$ws/.lastlight-run"',
|
|
19
|
+
'url="https://github.com/$owner/$repo.git"',
|
|
20
|
+
"ensure_base() {",
|
|
21
|
+
' [ -n "$base" ] && [ "$base" != "$branch" ] && [ -z "$recreate" ] || return 0',
|
|
22
|
+
' dest="+refs/heads/$base:refs/remotes/origin/$base"',
|
|
23
|
+
" for depth in 50 500; do",
|
|
24
|
+
' git -C "$repo_dir" fetch --depth "$depth" -- "$url" "$dest" || true',
|
|
25
|
+
' git -C "$repo_dir" fetch --depth "$depth" -- "$url" "$branch" || true',
|
|
26
|
+
' git -C "$repo_dir" merge-base "origin/$base" HEAD >/dev/null 2>&1 && return 0',
|
|
27
|
+
" done",
|
|
28
|
+
' git -C "$repo_dir" fetch --unshallow -- "$url" "$dest" || true',
|
|
29
|
+
' git -C "$repo_dir" fetch --unshallow -- "$url" "$branch" || true',
|
|
30
|
+
" return 0",
|
|
31
|
+
"}",
|
|
32
|
+
'stamp() { [ -n "$run_id" ] && printf %s "$run_id" > "$marker" 2>/dev/null || true; }',
|
|
33
|
+
'if [ -d "$repo_dir/.git" ]; then',
|
|
34
|
+
' last_run="$(cat "$marker" 2>/dev/null || true)"',
|
|
35
|
+
' if [ -z "$run_id" ] || [ "$last_run" = "$run_id" ]; then',
|
|
36
|
+
' echo "[clone] existing checkout (same run) — preserving"; exit 0',
|
|
37
|
+
" fi",
|
|
38
|
+
' if [ -z "$recreate" ]; then',
|
|
39
|
+
' if git -C "$repo_dir" fetch --depth 50 -- "$url" "$branch" \\',
|
|
40
|
+
' && git -C "$repo_dir" checkout -B "$branch" FETCH_HEAD \\',
|
|
41
|
+
' && git -C "$repo_dir" reset --hard FETCH_HEAD \\',
|
|
42
|
+
' && git -C "$repo_dir" clean -fdx -e node_modules; then',
|
|
43
|
+
' git -C "$repo_dir" remote set-url origin "$url" || true',
|
|
44
|
+
" ensure_base; stamp",
|
|
45
|
+
' echo "[clone] refreshed reused workspace -> $branch"',
|
|
46
|
+
" else",
|
|
47
|
+
' echo "[clone] refresh fetch failed — preserving existing checkout"',
|
|
48
|
+
" fi",
|
|
49
|
+
" exit 0",
|
|
50
|
+
" fi",
|
|
51
|
+
' echo "[clone] recreate-from-base — discarding stale checkout"',
|
|
52
|
+
' rm -rf "$repo_dir"',
|
|
53
|
+
"fi",
|
|
54
|
+
'if [ -n "$recreate" ]; then',
|
|
55
|
+
' git clone --depth 50 -- "$url" "$repo_dir"',
|
|
56
|
+
' git -C "$repo_dir" checkout -B "$branch"',
|
|
57
|
+
' git -C "$repo_dir" remote set-url origin "$url"',
|
|
58
|
+
'elif git clone --branch "$branch" --depth 50 -- "$url" "$repo_dir"; then',
|
|
59
|
+
' git -C "$repo_dir" remote set-url origin "$url"',
|
|
60
|
+
"else",
|
|
61
|
+
' echo "[clone] branch not on remote — cloning default and cutting $branch"',
|
|
62
|
+
' git clone --depth 50 -- "$url" "$repo_dir"',
|
|
63
|
+
' git -C "$repo_dir" checkout -B "$branch"',
|
|
64
|
+
' git -C "$repo_dir" remote set-url origin "$url"',
|
|
65
|
+
"fi",
|
|
66
|
+
"ensure_base",
|
|
67
|
+
"stamp",
|
|
68
|
+
].join("\n");
|
|
69
|
+
/**
|
|
70
|
+
* Minimal clone init (locked decision #2): clone the branch shallow-ish; if the
|
|
71
|
+
* branch isn't on the remote yet (build-style first run), clone the default
|
|
72
|
+
* branch and cut the branch locally.
|
|
73
|
+
*
|
|
74
|
+
* Reuse (a per-(repo,PR) PVC already holds a checkout) is marker-gated, mirroring
|
|
75
|
+
* the host `prePopulateWorkspace`: the same run preserves the checkout (a later
|
|
76
|
+
* phase reads what an earlier one wrote), a different run refreshes the head
|
|
77
|
+
* (`git fetch` + `reset --hard` + `clean -fdx -e node_modules`) or, for a
|
|
78
|
+
* recreate-from-base run, re-clones the default branch. For PR-diff workflows the
|
|
79
|
+
* base branch is fetched + deepened to a shared merge-base on both the fresh and
|
|
80
|
+
* refresh paths so `git diff origin/<base>...HEAD` resolves.
|
|
81
|
+
*
|
|
82
|
+
* Auth is the github.com-scoped `http.extraheader` delivered as `GIT_CONFIG_*`
|
|
83
|
+
* env from the creds Secret (agentGitIdentityEnv) — no token in any URL.
|
|
84
|
+
*
|
|
85
|
+
* owner/repo/branch/cwd/base/runId are NOT validated upstream (branch is the PR
|
|
86
|
+
* head ref, attacker-named for external pr-review/pr-fix PRs) — so they're passed
|
|
87
|
+
* as positional args to a fixed script rather than interpolated into shell text.
|
|
88
|
+
* `sh -c CLONE_SCRIPT sh <owner> <repo> <branch> <cwd> <base> <runId> <recreate>`
|
|
89
|
+
* binds argv to `$1`..`$7` at exec time, immune to quote-breaking regardless of
|
|
90
|
+
* characters.
|
|
91
|
+
*/
|
|
92
|
+
export function buildCloneInitContainer(image, spec) {
|
|
93
|
+
return {
|
|
94
|
+
name: "clone",
|
|
95
|
+
image,
|
|
96
|
+
command: ["sh", "-c", CLONE_SCRIPT],
|
|
97
|
+
args: [
|
|
98
|
+
"sh",
|
|
99
|
+
spec.owner,
|
|
100
|
+
spec.repo,
|
|
101
|
+
spec.branch,
|
|
102
|
+
spec.cwd,
|
|
103
|
+
spec.baseBranch ?? "",
|
|
104
|
+
spec.runId ?? "",
|
|
105
|
+
spec.recreateFromBase ? "1" : "",
|
|
106
|
+
],
|
|
107
|
+
workingDir: spec.cwd,
|
|
108
|
+
// Populated in the pod builder to share the creds Secret (GIT_CONFIG_* extraheader).
|
|
109
|
+
envFrom: [],
|
|
110
|
+
volumeMounts: [{ name: "workspace", mountPath: spec.cwd }],
|
|
111
|
+
securityContext: { allowPrivilegeEscalation: false, capabilities: { drop: ["ALL"] } },
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=init-clone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init-clone.js","sourceRoot":"","sources":["../../../src/sandbox/k8s/init-clone.ts"],"names":[],"mappings":"AA+BA,iFAAiF;AACjF,iFAAiF;AACjF,4EAA4E;AAC5E,kEAAkE;AAClE,EAAE;AACF,iFAAiF;AACjF,mFAAmF;AACnF,kFAAkF;AAClF,iFAAiF;AACjF,kFAAkF;AAClF,mFAAmF;AACnF,+EAA+E;AAC/E,mFAAmF;AACnF,MAAM,YAAY,GAAG;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C,CAAC,EAAE;SACjC;QACD,UAAU,EAAE,IAAI,CAAC,GAAG;QACpB,qFAAqF;QACrF,OAAO,EAAE,EAAE;QACX,YAAY,EAAE,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC;QAC1D,eAAe,EAAE,EAAE,wBAAwB,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,EAAE,EAAE;KACtF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { V1Container } from "@kubernetes/client-node";
|
|
2
|
+
/**
|
|
3
|
+
* The skills initContainer: fetch the per-phase bundle from the harness
|
|
4
|
+
* (bearer token from the creds Secret env, endpoint as a positional arg so it
|
|
5
|
+
* is never interpolated into the script) and unpack it into the shared
|
|
6
|
+
* `skills` emptyDir the agent container reads via `--skill`. `envFrom` (creds
|
|
7
|
+
* Secret) is attached by `buildPodManifest`. `-f` makes curl fail the init on a
|
|
8
|
+
* non-2xx so a bad fetch surfaces (checkInitContainerFailure appends its logs).
|
|
9
|
+
*/
|
|
10
|
+
export declare function buildSkillsInitContainer(image: string, opts: {
|
|
11
|
+
endpoint: string;
|
|
12
|
+
runAsUser: number;
|
|
13
|
+
}): V1Container;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SKILLS_MOUNT_DIR } from "./skill-bundle.js";
|
|
2
|
+
/**
|
|
3
|
+
* The skills initContainer: fetch the per-phase bundle from the harness
|
|
4
|
+
* (bearer token from the creds Secret env, endpoint as a positional arg so it
|
|
5
|
+
* is never interpolated into the script) and unpack it into the shared
|
|
6
|
+
* `skills` emptyDir the agent container reads via `--skill`. `envFrom` (creds
|
|
7
|
+
* Secret) is attached by `buildPodManifest`. `-f` makes curl fail the init on a
|
|
8
|
+
* non-2xx so a bad fetch surfaces (checkInitContainerFailure appends its logs).
|
|
9
|
+
*/
|
|
10
|
+
export function buildSkillsInitContainer(image, opts) {
|
|
11
|
+
const script = 'curl -fsS -H "Authorization: Bearer $LASTLIGHT_SKILL_TOKEN" ' +
|
|
12
|
+
`"$1/internal/skill-bundle" | tar xzf - -C ${SKILLS_MOUNT_DIR}`;
|
|
13
|
+
return {
|
|
14
|
+
name: "skills",
|
|
15
|
+
image,
|
|
16
|
+
command: ["sh", "-c", script],
|
|
17
|
+
args: ["sh", opts.endpoint],
|
|
18
|
+
envFrom: [],
|
|
19
|
+
volumeMounts: [{ name: "skills", mountPath: SKILLS_MOUNT_DIR }],
|
|
20
|
+
securityContext: {
|
|
21
|
+
allowPrivilegeEscalation: false,
|
|
22
|
+
runAsNonRoot: true,
|
|
23
|
+
runAsUser: opts.runAsUser,
|
|
24
|
+
capabilities: { drop: ["ALL"] },
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=init-skills.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init-skills.js","sourceRoot":"","sources":["../../../src/sandbox/k8s/init-skills.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;;;;;GAOG;AACH,MAAM,UAAU,wBAAwB,CACtC,KAAa,EACb,IAA6C;IAE7C,MAAM,MAAM,GACV,8DAA8D;QAC9D,6CAA6C,gBAAgB,EAAE,CAAC;IAClE,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,KAAK;QACL,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC;QAC7B,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC;QAC3B,OAAO,EAAE,EAAE;QACX,YAAY,EAAE,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,gBAAgB,EAAE,CAAC;QAC/D,eAAe,EAAE;YACf,wBAAwB,EAAE,KAAK;YAC/B,YAAY,EAAE,IAAI;YAClB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,YAAY,EAAE,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,EAAE;SAChC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import type { RunResult } from "agentic-pi";
|
|
2
|
+
import type { Sandbox, SandboxFactoryOpts, PrePopulateSpec, ProvisionResult, RunAgentOpts, RunCommandOpts, RawCommandResult, SandboxEvent } from "../sandbox.js";
|
|
3
|
+
import type { SandboxBackend } from "../../config/config.js";
|
|
4
|
+
import { type ArtifactStore } from "../artifact-store.js";
|
|
5
|
+
import { type K8sApis } from "./client.js";
|
|
6
|
+
import { type AgentContextRegistry } from "./agent-context-registry.js";
|
|
7
|
+
import { EgressEnsurer } from "./egress-ensurer.js";
|
|
8
|
+
import { type SkillBundleRegistry } from "./skill-bundle.js";
|
|
9
|
+
/** Config the adapter needs. `storageClassName` / `workspaceSize` size and
|
|
10
|
+
* class the per-(repo,PR) PVC (Task 5); `runAsUser` is the pod and
|
|
11
|
+
* initContainer security-context UID. `harnessEndpoint` / `harnessNamespace`
|
|
12
|
+
* / `harnessPodLabels` locate the harness Pod the skills-init fetches the
|
|
13
|
+
* bundle from (Task 3/6). The factory (`sandbox.ts`) resolves and passes all
|
|
14
|
+
* of these via `resolveKubernetesConfig()`. */
|
|
15
|
+
export interface K8sAdapterConfig {
|
|
16
|
+
namespace: string;
|
|
17
|
+
image: string;
|
|
18
|
+
storageClassName: string;
|
|
19
|
+
workspaceSize: string;
|
|
20
|
+
runAsUser: number;
|
|
21
|
+
harnessEndpoint: string;
|
|
22
|
+
harnessNamespace: string;
|
|
23
|
+
harnessPodLabels: Record<string, string>;
|
|
24
|
+
/** Injectable fake `K8sApis` for tests; defaults to the real client. */
|
|
25
|
+
apis?: K8sApis;
|
|
26
|
+
/** Injectable registry for tests; defaults to the module singleton skillBundleRegistry. */
|
|
27
|
+
skillRegistry?: SkillBundleRegistry;
|
|
28
|
+
/** Injectable registry for tests; defaults to the module singleton agentContextRegistry. */
|
|
29
|
+
agentContextRegistry?: AgentContextRegistry;
|
|
30
|
+
/** Injectable artifact store (tests only). Defaults to the module-wide
|
|
31
|
+
* `artifactStore` singleton (`../artifact-store.js`) — the same instance
|
|
32
|
+
* the `/internal/sandbox-artifacts` route resolves tokens against, so a
|
|
33
|
+
* token this adapter registers is always resolvable by that route. */
|
|
34
|
+
artifactStore?: ArtifactStore;
|
|
35
|
+
/** Injectable egress-policy applier (tests only). Defaults to the module-wide
|
|
36
|
+
* `egressEnsurer` singleton (`./egress-ensurer.js`) so production keeps
|
|
37
|
+
* ensure-once-per-namespace-per-process behaviour. A test can inject a
|
|
38
|
+
* fresh `EgressEnsurer` for isolation instead of needing a unique
|
|
39
|
+
* namespace per test. */
|
|
40
|
+
egressEnsurer?: EgressEnsurer;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The `kubernetes` {@link Sandbox} adapter — one pod per `runAgent`/
|
|
44
|
+
* `runCommand` call. A thin orchestrator (F1): it wires the collaborators that
|
|
45
|
+
* own the real work — {@link WorkspaceProvisioner} (emptyDir vs per-(repo,PR)
|
|
46
|
+
* PVC), {@link RunSecrets} (creds/prompt Secret create + ownerRef patch +
|
|
47
|
+
* best-effort delete), {@link EgressEnsurer} (the CiliumNetworkPolicy pair),
|
|
48
|
+
* and the free pod-lifecycle functions (`pod-lifecycle.ts`) — behind the
|
|
49
|
+
* unchanged `Sandbox` port.
|
|
50
|
+
*
|
|
51
|
+
* `provision` hands back a {@link Provisioned} the orchestrator holds until
|
|
52
|
+
* `dispose` (the sequence provision→runPod is provision-scoped, and the port
|
|
53
|
+
* gives no channel to thread it per call); `runPod` threads a
|
|
54
|
+
* {@link RunHandles} out explicitly for `runCommand`'s result poll and for
|
|
55
|
+
* `dispose` to reap, rather than stashing loose `activePod`/`activeCredsSecret`
|
|
56
|
+
* mutable fields mid-call. The only other fields that outlive a call are the
|
|
57
|
+
* skill/agent-context/artifact tokens, kept solely so `dispose` can evict them.
|
|
58
|
+
*
|
|
59
|
+
* `runAgent` delivers the prompt via a per-run prompt Secret mounted into the
|
|
60
|
+
* pod and piped to the agent's stdin; the resolved agent-context (persona/hard
|
|
61
|
+
* rules) is delivered over its own HTTP init-fetch channel (nearform#240),
|
|
62
|
+
* mirroring skills: `runAgent` registers the resolved text with the (injectable)
|
|
63
|
+
* agent-context registry, carries the fetch token into the creds Secret, and
|
|
64
|
+
* adds an agent-context initContainer that pulls it from the harness's
|
|
65
|
+
* `/internal/agent-context` route and writes it to `<WORKSPACE_DIR>/AGENTS.md`.
|
|
66
|
+
* A dedicated route (not the skills bundle) because agent-context is
|
|
67
|
+
* per-run-constant and a no-skills phase must still receive `AGENTS.md`.
|
|
68
|
+
* `stageSkills` tars the resolved skill dirs and registers the bundle with the
|
|
69
|
+
* (injectable) skill registry; `runPod` then carries the fetch token into the
|
|
70
|
+
* creds Secret and adds a skills initContainer that pulls it from the harness's
|
|
71
|
+
* `/internal/skill-bundle` route. `runAgent` additionally mints a per-run token
|
|
72
|
+
* from the (injectable) artifact store and carries it into the same creds
|
|
73
|
+
* Secret; the in-pod script tars `.lastlight/` after the agent finishes and
|
|
74
|
+
* uploads it to the harness's `/internal/sandbox-artifacts` route, best-effort
|
|
75
|
+
* so an upload hiccup never masks the agent's real exit code — `dispose` evicts
|
|
76
|
+
* the token afterward.
|
|
77
|
+
*/
|
|
78
|
+
export declare class KubernetesSandbox implements Sandbox {
|
|
79
|
+
private readonly opts;
|
|
80
|
+
readonly backend: SandboxBackend;
|
|
81
|
+
private readonly apis;
|
|
82
|
+
private readonly ns;
|
|
83
|
+
private readonly image;
|
|
84
|
+
private readonly runAsUser;
|
|
85
|
+
private readonly harnessEndpoint;
|
|
86
|
+
private readonly harnessNamespace;
|
|
87
|
+
private readonly harnessPodLabels;
|
|
88
|
+
private readonly skillRegistry;
|
|
89
|
+
private readonly agentContextRegistry;
|
|
90
|
+
private readonly artifactStore;
|
|
91
|
+
private readonly egressEnsurer;
|
|
92
|
+
private readonly provisioner;
|
|
93
|
+
private readonly runSecrets;
|
|
94
|
+
/** Result of the last `provision()` call — the workspace descriptor + pre-clone
|
|
95
|
+
* coordinates `runPod` reads to shape the pod (PVC/emptyDir volume, clone
|
|
96
|
+
* init, run-id stamp). Set once per sandbox lifecycle, before any run. */
|
|
97
|
+
private provisioned?;
|
|
98
|
+
/** Pod + Secrets for the last run, held for `dispose` to reap. */
|
|
99
|
+
private handles?;
|
|
100
|
+
/** Fetch token for the bundle staged by the last `stageSkills()` call, if
|
|
101
|
+
* any — `runPod` carries it into the creds Secret + skills-init; `dispose`
|
|
102
|
+
* evicts it from the registry. */
|
|
103
|
+
private skillToken?;
|
|
104
|
+
/** Fetch token for the resolved agent-context registered by the last
|
|
105
|
+
* `runAgent()` call, if any — `runPod` carries it into the creds Secret +
|
|
106
|
+
* agent-context-init; `dispose` evicts it from the registry. Never minted
|
|
107
|
+
* for `runCommand` (no agent, no AGENTS.md), nor when the context is empty. */
|
|
108
|
+
private agentContextToken?;
|
|
109
|
+
/** Artifact-upload token minted by the last `runAgent()` call, if any —
|
|
110
|
+
* `runPod` carries it into the creds Secret; the in-pod script reads it back
|
|
111
|
+
* via env to authenticate the `.lastlight/` upload; `dispose` evicts it from
|
|
112
|
+
* the store. Never minted for `runCommand` (nothing to upload). */
|
|
113
|
+
private artifactToken?;
|
|
114
|
+
constructor(opts: SandboxFactoryOpts, cfg: K8sAdapterConfig);
|
|
115
|
+
provision(pre?: PrePopulateSpec): Promise<ProvisionResult>;
|
|
116
|
+
/**
|
|
117
|
+
* Package `skillPaths` into a tar, register it in the (injectable) skill
|
|
118
|
+
* registry, and return the in-pod dirs the agent should `--skill` against.
|
|
119
|
+
* The returned token is stashed on `this.skillToken` so `runPod` can wire the
|
|
120
|
+
* creds Secret + skills-init and `dispose` can evict it; the orchestrator also
|
|
121
|
+
* threads the returned dirs back in as `opts.skillDirs` for the `runAgent`
|
|
122
|
+
* command (Task 6 brief). Deduped: `buildSkillTar` doesn't dedupe
|
|
123
|
+
* sanitized-name collisions (two skill dirs whose basenames sanitize equal
|
|
124
|
+
* merge in the tar), so a `Set` here at least keeps the returned `--skill`
|
|
125
|
+
* list free of repeats.
|
|
126
|
+
*/
|
|
127
|
+
stageSkills(_phaseKey: string, skillPaths: string[] | undefined): string[] | undefined;
|
|
128
|
+
/** Hosts the strict policy allows — the shared allowlist plus OTEL collector
|
|
129
|
+
* hosts when sandbox OTEL forwarding is on (mirrors `egressPolicyFor`). */
|
|
130
|
+
private strictHosts;
|
|
131
|
+
/** Apply the egress policy pair once per namespace, via the injected
|
|
132
|
+
* {@link EgressEnsurer} (`this.egressEnsurer`). Best-effort in Plan 3: a
|
|
133
|
+
* 403 means the CiliumNetworkPolicy RBAC verb isn't granted yet (Plan 6),
|
|
134
|
+
* so it warns ONCE and runs on Cilium's default-allow — no regression to
|
|
135
|
+
* the validated flows; the same code enforces the moment RBAC lands. */
|
|
136
|
+
private ensureEgress;
|
|
137
|
+
sandboxPathFor(relPath: string): string;
|
|
138
|
+
/** The provisioned pre-clone descriptor's `runId` wrapped as a {@link RunId}
|
|
139
|
+
* — stamped identically onto the Pod (`runPod`) and the PVC
|
|
140
|
+
* (`WorkspaceProvisioner`) so the reclaim run-selector (Plan 5) matches both
|
|
141
|
+
* (F7). Undefined when `provision()` had no pre-clone descriptor, or the
|
|
142
|
+
* descriptor carried no runId. */
|
|
143
|
+
private currentRunId;
|
|
144
|
+
runAgent(taskId: string, prompt: string, opts: RunAgentOpts, onEvent: (record: SandboxEvent) => void): Promise<RunResult | undefined>;
|
|
145
|
+
/** Guard the free-form `runAgent` options against their closed sets so an
|
|
146
|
+
* unexpected value fails loudly here rather than reaching the CLI. Profile
|
|
147
|
+
* enables agentic-pi's github_* extension per access profile; web-search
|
|
148
|
+
* defaults OFF (agentic-pi auto-enables it whenever any `*_API_KEY` is
|
|
149
|
+
* present, so a phase that never opted in actively suppresses it via the
|
|
150
|
+
* script's `--no-web-search`). */
|
|
151
|
+
private assertValidRunAgentOpts;
|
|
152
|
+
runCommand(taskId: string, command: string, opts: RunCommandOpts): Promise<RawCommandResult>;
|
|
153
|
+
/** Delegates to {@link awaitPodResult} (`pod-lifecycle.ts`) — see there for
|
|
154
|
+
* the poll/fallback rationale. */
|
|
155
|
+
private awaitPodResult;
|
|
156
|
+
private runPod;
|
|
157
|
+
/** The init containers this run needs: the minimal clone (locked decision #2)
|
|
158
|
+
* only when the run has a PVC workspace AND a pre-clone descriptor (an
|
|
159
|
+
* ephemeral emptyDir run has nothing to clone into), the skills-init whenever
|
|
160
|
+
* `stageSkills` staged a bundle, and the agent-context-init whenever
|
|
161
|
+
* `runAgent` registered a non-empty context (fetches `AGENTS.md` into the
|
|
162
|
+
* workspace root). All coexist, and `buildPodManifest` attaches the creds
|
|
163
|
+
* Secret's `envFrom` to each. */
|
|
164
|
+
private buildInitContainers;
|
|
165
|
+
/** Create the Pod; on failure, best-effort delete the Secret(s) already
|
|
166
|
+
* created for it (they exist before the Pod per the ordering rule), so a
|
|
167
|
+
* failed create doesn't orphan them — then rethrow. A ResourceQuota rejection
|
|
168
|
+
* is backpressure, not a failure: rethrow a typed error so the orchestrator
|
|
169
|
+
* stamps `error_quota` and the run requeues (see the Concurrency section of
|
|
170
|
+
* `spec/09-sandbox.md`). */
|
|
171
|
+
private createPodOrCleanupSecrets;
|
|
172
|
+
/** Delegates to {@link waitForContainerStart} (`pod-lifecycle.ts`) — see
|
|
173
|
+
* there for the started/fatal/init-container-check rationale. */
|
|
174
|
+
private waitForContainerStart;
|
|
175
|
+
/** Delegates to {@link waitForPodGone} (`pod-lifecycle.ts`) — see there for
|
|
176
|
+
* the RWO Multi-Attach rationale. */
|
|
177
|
+
private waitForPodGone;
|
|
178
|
+
dispose(): Promise<void>;
|
|
179
|
+
}
|