lastlight-core 0.21.11 → 0.21.13

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.
Files changed (150) hide show
  1. package/deploy/k8s/README.md +111 -34
  2. package/deploy/k8s/architecture.md +199 -0
  3. package/deploy/k8s/configmap.yaml +14 -3
  4. package/deploy/k8s/harness-deployment.yaml +111 -0
  5. package/deploy/k8s/kustomization.yaml +10 -8
  6. package/deploy/k8s/sandbox-namespace.yaml +14 -0
  7. package/deploy/k8s/sandbox-quota.yaml +37 -0
  8. package/deploy/k8s/sandbox-rbac.yaml +60 -0
  9. package/dist/admin/routes.js +66 -10
  10. package/dist/admin/routes.js.map +1 -1
  11. package/dist/config/config.d.ts +36 -0
  12. package/dist/config/config.js +101 -3
  13. package/dist/config/config.js.map +1 -1
  14. package/dist/cron/review-discovery.d.ts +54 -0
  15. package/dist/cron/review-discovery.js +70 -0
  16. package/dist/cron/review-discovery.js.map +1 -0
  17. package/dist/engine/executors/orchestrator.js +124 -58
  18. package/dist/engine/executors/orchestrator.js.map +1 -1
  19. package/dist/engine/github/github.d.ts +8 -0
  20. package/dist/engine/github/github.js +14 -0
  21. package/dist/engine/github/github.js.map +1 -1
  22. package/dist/engine/github/profiles.d.ts +12 -1
  23. package/dist/engine/github/profiles.js +33 -1
  24. package/dist/engine/github/profiles.js.map +1 -1
  25. package/dist/index.js +55 -14
  26. package/dist/index.js.map +1 -1
  27. package/dist/sandbox/artifact-backend.d.ts +40 -0
  28. package/dist/sandbox/artifact-backend.js +67 -0
  29. package/dist/sandbox/artifact-backend.js.map +1 -0
  30. package/dist/sandbox/artifact-store.d.ts +55 -0
  31. package/dist/sandbox/artifact-store.js +203 -0
  32. package/dist/sandbox/artifact-store.js.map +1 -0
  33. package/dist/sandbox/docker.d.ts +2 -1
  34. package/dist/sandbox/docker.js +3 -3
  35. package/dist/sandbox/docker.js.map +1 -1
  36. package/dist/sandbox/k8s/agent-context-registry.d.ts +25 -0
  37. package/dist/sandbox/k8s/agent-context-registry.js +45 -0
  38. package/dist/sandbox/k8s/agent-context-registry.js.map +1 -0
  39. package/dist/sandbox/k8s/agent-context-route.d.ts +13 -0
  40. package/dist/sandbox/k8s/agent-context-route.js +21 -0
  41. package/dist/sandbox/k8s/agent-context-route.js.map +1 -0
  42. package/dist/sandbox/k8s/artifact-upload-route.d.ts +12 -0
  43. package/dist/sandbox/k8s/artifact-upload-route.js +40 -0
  44. package/dist/sandbox/k8s/artifact-upload-route.js.map +1 -0
  45. package/dist/sandbox/k8s/client.d.ts +22 -0
  46. package/dist/sandbox/k8s/client.js +35 -0
  47. package/dist/sandbox/k8s/client.js.map +1 -0
  48. package/dist/sandbox/k8s/egress-apply.d.ts +14 -0
  49. package/dist/sandbox/k8s/egress-apply.js +44 -0
  50. package/dist/sandbox/k8s/egress-apply.js.map +1 -0
  51. package/dist/sandbox/k8s/egress-ensurer.d.ts +37 -0
  52. package/dist/sandbox/k8s/egress-ensurer.js +54 -0
  53. package/dist/sandbox/k8s/egress-ensurer.js.map +1 -0
  54. package/dist/sandbox/k8s/egress-policy.d.ts +112 -0
  55. package/dist/sandbox/k8s/egress-policy.js +118 -0
  56. package/dist/sandbox/k8s/egress-policy.js.map +1 -0
  57. package/dist/sandbox/k8s/init-agent-context.d.ts +20 -0
  58. package/dist/sandbox/k8s/init-agent-context.js +35 -0
  59. package/dist/sandbox/k8s/init-agent-context.js.map +1 -0
  60. package/dist/sandbox/k8s/init-clone.d.ts +53 -0
  61. package/dist/sandbox/k8s/init-clone.js +114 -0
  62. package/dist/sandbox/k8s/init-clone.js.map +1 -0
  63. package/dist/sandbox/k8s/init-skills.d.ts +13 -0
  64. package/dist/sandbox/k8s/init-skills.js +28 -0
  65. package/dist/sandbox/k8s/init-skills.js.map +1 -0
  66. package/dist/sandbox/k8s/kubernetes-sandbox.d.ts +179 -0
  67. package/dist/sandbox/k8s/kubernetes-sandbox.js +418 -0
  68. package/dist/sandbox/k8s/kubernetes-sandbox.js.map +1 -0
  69. package/dist/sandbox/k8s/log-stream.d.ts +4 -0
  70. package/dist/sandbox/k8s/log-stream.js +43 -0
  71. package/dist/sandbox/k8s/log-stream.js.map +1 -0
  72. package/dist/sandbox/k8s/naming.d.ts +19 -0
  73. package/dist/sandbox/k8s/naming.js +35 -0
  74. package/dist/sandbox/k8s/naming.js.map +1 -0
  75. package/dist/sandbox/k8s/pod-lifecycle.d.ts +40 -0
  76. package/dist/sandbox/k8s/pod-lifecycle.js +151 -0
  77. package/dist/sandbox/k8s/pod-lifecycle.js.map +1 -0
  78. package/dist/sandbox/k8s/pod-status.d.ts +46 -0
  79. package/dist/sandbox/k8s/pod-status.js +83 -0
  80. package/dist/sandbox/k8s/pod-status.js.map +1 -0
  81. package/dist/sandbox/k8s/pod.d.ts +79 -0
  82. package/dist/sandbox/k8s/pod.js +115 -0
  83. package/dist/sandbox/k8s/pod.js.map +1 -0
  84. package/dist/sandbox/k8s/pvc.d.ts +20 -0
  85. package/dist/sandbox/k8s/pvc.js +26 -0
  86. package/dist/sandbox/k8s/pvc.js.map +1 -0
  87. package/dist/sandbox/k8s/quota.d.ts +34 -0
  88. package/dist/sandbox/k8s/quota.js +52 -0
  89. package/dist/sandbox/k8s/quota.js.map +1 -0
  90. package/dist/sandbox/k8s/reclaim.d.ts +50 -0
  91. package/dist/sandbox/k8s/reclaim.js +141 -0
  92. package/dist/sandbox/k8s/reclaim.js.map +1 -0
  93. package/dist/sandbox/k8s/resource-name.d.ts +33 -0
  94. package/dist/sandbox/k8s/resource-name.js +49 -0
  95. package/dist/sandbox/k8s/resource-name.js.map +1 -0
  96. package/dist/sandbox/k8s/run-agent-script.d.ts +60 -0
  97. package/dist/sandbox/k8s/run-agent-script.js +48 -0
  98. package/dist/sandbox/k8s/run-agent-script.js.map +1 -0
  99. package/dist/sandbox/k8s/run-id.d.ts +23 -0
  100. package/dist/sandbox/k8s/run-id.js +32 -0
  101. package/dist/sandbox/k8s/run-id.js.map +1 -0
  102. package/dist/sandbox/k8s/run-secrets.d.ts +75 -0
  103. package/dist/sandbox/k8s/run-secrets.js +115 -0
  104. package/dist/sandbox/k8s/run-secrets.js.map +1 -0
  105. package/dist/sandbox/k8s/secret.d.ts +20 -0
  106. package/dist/sandbox/k8s/secret.js +38 -0
  107. package/dist/sandbox/k8s/secret.js.map +1 -0
  108. package/dist/sandbox/k8s/skill-bundle-route.d.ts +10 -0
  109. package/dist/sandbox/k8s/skill-bundle-route.js +18 -0
  110. package/dist/sandbox/k8s/skill-bundle-route.js.map +1 -0
  111. package/dist/sandbox/k8s/skill-bundle.d.ts +36 -0
  112. package/dist/sandbox/k8s/skill-bundle.js +85 -0
  113. package/dist/sandbox/k8s/skill-bundle.js.map +1 -0
  114. package/dist/sandbox/k8s/sweep.d.ts +47 -0
  115. package/dist/sandbox/k8s/sweep.js +29 -0
  116. package/dist/sandbox/k8s/sweep.js.map +1 -0
  117. package/dist/sandbox/k8s/workspace-provisioner.d.ts +51 -0
  118. package/dist/sandbox/k8s/workspace-provisioner.js +64 -0
  119. package/dist/sandbox/k8s/workspace-provisioner.js.map +1 -0
  120. package/dist/sandbox/sandbox.d.ts +20 -1
  121. package/dist/sandbox/sandbox.js +22 -1
  122. package/dist/sandbox/sandbox.js.map +1 -1
  123. package/dist/state/workflow-run-store.d.ts +11 -0
  124. package/dist/state/workflow-run-store.js +19 -0
  125. package/dist/state/workflow-run-store.js.map +1 -1
  126. package/dist/workflows/admission.d.ts +19 -0
  127. package/dist/workflows/admission.js +81 -13
  128. package/dist/workflows/admission.js.map +1 -1
  129. package/dist/workflows/handlers/post-review.d.ts +21 -0
  130. package/dist/workflows/handlers/post-review.js +56 -13
  131. package/dist/workflows/handlers/post-review.js.map +1 -1
  132. package/dist/workflows/resume.js +6 -0
  133. package/dist/workflows/resume.js.map +1 -1
  134. package/dist/workflows/runner.d.ts +11 -2
  135. package/dist/workflows/runner.js +73 -15
  136. package/dist/workflows/runner.js.map +1 -1
  137. package/dist/workflows/simple.d.ts +13 -1
  138. package/dist/workflows/simple.js +46 -4
  139. package/dist/workflows/simple.js.map +1 -1
  140. package/package.json +21 -20
  141. package/skills/issue-triage/SKILL.md +17 -0
  142. package/workflows/cron-review.yaml +14 -1
  143. package/workflows/dependabot-pr-merge.yaml +14 -9
  144. package/workflows/issue-triage.yaml +6 -0
  145. package/workflows/prompts/dependabot-pr-merge.md +53 -11
  146. package/deploy/k8s/deployment.yaml +0 -63
  147. package/deploy/k8s/generic-device-plugin.yaml +0 -63
  148. package/deploy/k8s/namespace.yaml +0 -10
  149. package/deploy/k8s/pvc.yaml +0 -13
  150. package/deploy/k8s/service.yaml +0 -12
@@ -0,0 +1,75 @@
1
+ import type { CoreV1Api, V1Pod } from "@kubernetes/client-node";
2
+ import type { Rfc1123Label } from "./resource-name.js";
3
+ /** The Secret names a `create()` call produced — the creds Secret always, the
4
+ * prompt Secret only for a `runAgent` run. The orchestrator folds these into
5
+ * its {@link RunHandles} (pod + secrets) for cascade-safe disposal. */
6
+ export interface RunSecretsResult {
7
+ credsSecret: string;
8
+ promptSecret?: string;
9
+ }
10
+ /** Inputs for one run's Secrets. `promptText` present ⇒ a prompt Secret is
11
+ * created (a `runAgent` run); absent ⇒ creds only (a `runCommand` run). The
12
+ * three tokens, when set, ride the creds Secret so the pod's `envFrom` exposes
13
+ * them to the main container and the init containers (skills-init /
14
+ * agent-context-init / the post-run artifact upload). */
15
+ export interface CreateSecretsInput {
16
+ podLabel: Rfc1123Label;
17
+ env: Record<string, string>;
18
+ skillToken?: string;
19
+ agentContextToken?: string;
20
+ artifactToken?: string;
21
+ promptText?: string;
22
+ }
23
+ /**
24
+ * Owns the per-run Secret lifecycle for a `KubernetesSandbox` pod: create the
25
+ * creds (and, for `runAgent`, prompt) Secrets BEFORE the pod (a pod whose
26
+ * `envFrom`/volume names a missing Secret fails to start), patch each Secret's
27
+ * `ownerReferences` to the created pod so deleting the pod cascade-GCs them,
28
+ * and best-effort delete them directly as a backstop. Extracted from
29
+ * `KubernetesSandbox` (F1) so the Secret handling is independently testable
30
+ * against a fake `CoreV1Api`.
31
+ */
32
+ export declare class RunSecrets {
33
+ private readonly core;
34
+ private readonly namespace;
35
+ constructor(core: CoreV1Api, namespace: string);
36
+ /**
37
+ * Create this run's Secrets and return their names. Per-run creds travel in
38
+ * the pod's OWN Secret, never inline on the pod spec (inline env is `kubectl
39
+ * get pod -o yaml`-visible — issue #223); the skill/agent-context/artifact
40
+ * tokens ride the same map so the init containers (skills-init /
41
+ * agent-context-init) and the post-run upload authenticate via the same
42
+ * `envFrom`. The prompt travels a second Secret mounted read-only and piped to
43
+ * the agent's stdin.
44
+ */
45
+ create(input: CreateSecretsInput): Promise<RunSecretsResult>;
46
+ /**
47
+ * Create the creds + prompt Secrets concurrently (one round-trip instead of
48
+ * two sequential ones). `Promise.allSettled`, not `Promise.all`, because
49
+ * parallelizing widens the pre-existing orphan risk: sequentially, only
50
+ * "prompt fails after creds already exists" was reachable (creds is awaited
51
+ * first). Run concurrently, "creds fails while prompt succeeds" becomes
52
+ * reachable too. Either Secret has no ownerReference yet (that patch runs
53
+ * after pod-create), no parent Pod to cascade-GC it, and the reclaim sweep
54
+ * (`reclaim.ts`) only reaps Pods/PVCs, never Secrets — so on ANY failure,
55
+ * best-effort delete whichever Secret DID get created, then rethrow (the
56
+ * creds error takes priority if both failed), keeping the whole create
57
+ * atomic from the caller's view exactly as the sequential version was.
58
+ */
59
+ private createBoth;
60
+ /**
61
+ * Cascade-GC ref: patch each Secret's `ownerReferences` to the created pod's
62
+ * uid, so deleting the pod GCs them too. The body must be an RFC 6902 JSON
63
+ * Patch document (client-node 1.4.0 always negotiates `application/json-patch+json`
64
+ * for `patchNamespacedSecret`), and `add` (not `replace`) because
65
+ * `ownerReferences` doesn't exist on a freshly created Secret. The two
66
+ * patches target independent Secrets with no cleanup coupling between them
67
+ * (unlike `create`'s orphan risk), so they run concurrently via
68
+ * `Promise.all` — one round-trip instead of two.
69
+ */
70
+ patchOwnerRefs(pod: V1Pod, podName: string, secrets: RunSecretsResult): Promise<void>;
71
+ /** Best-effort Secret delete — used both by the pod-create failure path and
72
+ * `dispose`; swallows the error since the Secret may already be gone
73
+ * (cascade-GC'd with the pod, or the reclaim sweep). */
74
+ deleteBestEffort(name: string): Promise<void>;
75
+ }
@@ -0,0 +1,115 @@
1
+ import { buildSecretManifest, podOwnerReference, secretNameFor } from "./secret.js";
2
+ /**
3
+ * Owns the per-run Secret lifecycle for a `KubernetesSandbox` pod: create the
4
+ * creds (and, for `runAgent`, prompt) Secrets BEFORE the pod (a pod whose
5
+ * `envFrom`/volume names a missing Secret fails to start), patch each Secret's
6
+ * `ownerReferences` to the created pod so deleting the pod cascade-GCs them,
7
+ * and best-effort delete them directly as a backstop. Extracted from
8
+ * `KubernetesSandbox` (F1) so the Secret handling is independently testable
9
+ * against a fake `CoreV1Api`.
10
+ */
11
+ export class RunSecrets {
12
+ core;
13
+ namespace;
14
+ constructor(core, namespace) {
15
+ this.core = core;
16
+ this.namespace = namespace;
17
+ }
18
+ /**
19
+ * Create this run's Secrets and return their names. Per-run creds travel in
20
+ * the pod's OWN Secret, never inline on the pod spec (inline env is `kubectl
21
+ * get pod -o yaml`-visible — issue #223); the skill/agent-context/artifact
22
+ * tokens ride the same map so the init containers (skills-init /
23
+ * agent-context-init) and the post-run upload authenticate via the same
24
+ * `envFrom`. The prompt travels a second Secret mounted read-only and piped to
25
+ * the agent's stdin.
26
+ */
27
+ async create(input) {
28
+ const { podLabel, env, skillToken, agentContextToken, artifactToken, promptText } = input;
29
+ const credsSecret = secretNameFor(podLabel, "creds");
30
+ const credsBody = buildSecretManifest({
31
+ name: credsSecret,
32
+ namespace: this.namespace,
33
+ data: {
34
+ ...env,
35
+ ...(skillToken && { LASTLIGHT_SKILL_TOKEN: skillToken }),
36
+ ...(agentContextToken && { LASTLIGHT_AGENT_CONTEXT_TOKEN: agentContextToken }),
37
+ ...(artifactToken && { LASTLIGHT_ARTIFACT_TOKEN: artifactToken }),
38
+ },
39
+ labels: { "lastlight.io/pod": podLabel.value },
40
+ });
41
+ if (promptText === undefined) {
42
+ await this.core.createNamespacedSecret({ namespace: this.namespace, body: credsBody });
43
+ return { credsSecret };
44
+ }
45
+ const promptSecret = secretNameFor(podLabel, "prompt");
46
+ const promptBody = buildSecretManifest({
47
+ name: promptSecret,
48
+ namespace: this.namespace,
49
+ data: { prompt: promptText },
50
+ labels: { "lastlight.io/pod": podLabel.value },
51
+ });
52
+ await this.createBoth({ credsSecret, credsBody, promptSecret, promptBody });
53
+ return { credsSecret, promptSecret };
54
+ }
55
+ /**
56
+ * Create the creds + prompt Secrets concurrently (one round-trip instead of
57
+ * two sequential ones). `Promise.allSettled`, not `Promise.all`, because
58
+ * parallelizing widens the pre-existing orphan risk: sequentially, only
59
+ * "prompt fails after creds already exists" was reachable (creds is awaited
60
+ * first). Run concurrently, "creds fails while prompt succeeds" becomes
61
+ * reachable too. Either Secret has no ownerReference yet (that patch runs
62
+ * after pod-create), no parent Pod to cascade-GC it, and the reclaim sweep
63
+ * (`reclaim.ts`) only reaps Pods/PVCs, never Secrets — so on ANY failure,
64
+ * best-effort delete whichever Secret DID get created, then rethrow (the
65
+ * creds error takes priority if both failed), keeping the whole create
66
+ * atomic from the caller's view exactly as the sequential version was.
67
+ */
68
+ async createBoth(args) {
69
+ const { credsSecret, credsBody, promptSecret, promptBody } = args;
70
+ const [credsResult, promptResult] = await Promise.allSettled([
71
+ this.core.createNamespacedSecret({ namespace: this.namespace, body: credsBody }),
72
+ this.core.createNamespacedSecret({ namespace: this.namespace, body: promptBody }),
73
+ ]);
74
+ if (credsResult.status === "fulfilled" && promptResult.status === "fulfilled")
75
+ return;
76
+ if (credsResult.status === "fulfilled")
77
+ await this.deleteBestEffort(credsSecret);
78
+ if (promptResult.status === "fulfilled")
79
+ await this.deleteBestEffort(promptSecret);
80
+ const failed = credsResult.status === "rejected" ? credsResult : promptResult;
81
+ throw failed.reason;
82
+ }
83
+ /**
84
+ * Cascade-GC ref: patch each Secret's `ownerReferences` to the created pod's
85
+ * uid, so deleting the pod GCs them too. The body must be an RFC 6902 JSON
86
+ * Patch document (client-node 1.4.0 always negotiates `application/json-patch+json`
87
+ * for `patchNamespacedSecret`), and `add` (not `replace`) because
88
+ * `ownerReferences` doesn't exist on a freshly created Secret. The two
89
+ * patches target independent Secrets with no cleanup coupling between them
90
+ * (unlike `create`'s orphan risk), so they run concurrently via
91
+ * `Promise.all` — one round-trip instead of two.
92
+ */
93
+ async patchOwnerRefs(pod, podName, secrets) {
94
+ const uid = pod.metadata?.uid;
95
+ if (!uid)
96
+ throw new Error(`k8s sandbox pod ${podName} was created without a uid`);
97
+ const patch = [
98
+ { op: "add", path: "/metadata/ownerReferences", value: [podOwnerReference(podName, uid)] },
99
+ ];
100
+ const names = [secrets.credsSecret, ...(secrets.promptSecret ? [secrets.promptSecret] : [])];
101
+ await Promise.all(names.map((name) => this.core.patchNamespacedSecret({ name, namespace: this.namespace, body: patch })));
102
+ }
103
+ /** Best-effort Secret delete — used both by the pod-create failure path and
104
+ * `dispose`; swallows the error since the Secret may already be gone
105
+ * (cascade-GC'd with the pod, or the reclaim sweep). */
106
+ async deleteBestEffort(name) {
107
+ try {
108
+ await this.core.deleteNamespacedSecret({ name, namespace: this.namespace });
109
+ }
110
+ catch {
111
+ /* already gone */
112
+ }
113
+ }
114
+ }
115
+ //# sourceMappingURL=run-secrets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-secrets.js","sourceRoot":"","sources":["../../../src/sandbox/k8s/run-secrets.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAwBpF;;;;;;;;GAQG;AACH,MAAM,OAAO,UAAU;IAEF;IACA;IAFnB,YACmB,IAAe,EACf,SAAiB;QADjB,SAAI,GAAJ,IAAI,CAAW;QACf,cAAS,GAAT,SAAS,CAAQ;IACjC,CAAC;IAEJ;;;;;;;;OAQG;IACH,KAAK,CAAC,MAA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C;QAClF,MAAM,KAAK,GAAG;YACZ,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,2BAA2B,EAAE,KAAK,EAAE,CAAC,iBAAiB,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,EAAE;SAC3F,CAAC;QACF,MAAM,KAAK,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC7F,MAAM,OAAO,CAAC,GAAG,CACf,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACjB,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAClF,CACF,CAAC;IACJ,CAAC;IAED;;6DAEyD;IACzD,KAAK,CAAC,gBAAgB,CAAC,IAAY;QACjC,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;QAC9E,CAAC;QAAC,MAAM,CAAC;YACP,kBAAkB;QACpB,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,20 @@
1
+ import type { V1Secret, V1OwnerReference } from "@kubernetes/client-node";
2
+ import { Rfc1123Label } from "./resource-name.js";
3
+ export declare function buildSecretManifest(i: {
4
+ name: string;
5
+ namespace: string;
6
+ data: Record<string, string>;
7
+ labels?: Record<string, string>;
8
+ }): V1Secret;
9
+ /** Cascade-GC ref: when the Pod is deleted, k8s GCs the owned Secret. */
10
+ export declare function podOwnerReference(podName: string, podUid: string): V1OwnerReference;
11
+ /** Derives the creds/prompt Secret name from a pod name. Takes the
12
+ * `Rfc1123Label` `podNameFor` (naming.ts) returns — not a raw string — so a
13
+ * Secret name can only ever be derived from an actual pod name; the
14
+ * compiler rejects anything else, which is what makes the "stays within 63
15
+ * chars" invariant a structural fact rather than a comment (F6).
16
+ * `podNameFor` reserves an 8-char budget so this never overflows for a
17
+ * label it produced; `Rfc1123Label.withSuffix` is the enforced backstop —
18
+ * it throws instead of silently emitting an invalid >63-char Secret name
19
+ * if that budget were ever wrong. */
20
+ export declare function secretNameFor(podName: Rfc1123Label, kind: "creds" | "prompt"): string;
@@ -0,0 +1,38 @@
1
+ export function buildSecretManifest(i) {
2
+ return {
3
+ apiVersion: "v1",
4
+ kind: "Secret",
5
+ type: "Opaque",
6
+ metadata: {
7
+ name: i.name,
8
+ namespace: i.namespace,
9
+ labels: { "app.kubernetes.io/managed-by": "lastlight", ...(i.labels ?? {}) },
10
+ },
11
+ // stringData: k8s base64-encodes on write; keeps the builder plaintext-simple.
12
+ stringData: i.data,
13
+ };
14
+ }
15
+ /** Cascade-GC ref: when the Pod is deleted, k8s GCs the owned Secret. */
16
+ export function podOwnerReference(podName, podUid) {
17
+ return {
18
+ apiVersion: "v1",
19
+ kind: "Pod",
20
+ name: podName,
21
+ uid: podUid,
22
+ controller: true,
23
+ blockOwnerDeletion: true,
24
+ };
25
+ }
26
+ /** Derives the creds/prompt Secret name from a pod name. Takes the
27
+ * `Rfc1123Label` `podNameFor` (naming.ts) returns — not a raw string — so a
28
+ * Secret name can only ever be derived from an actual pod name; the
29
+ * compiler rejects anything else, which is what makes the "stays within 63
30
+ * chars" invariant a structural fact rather than a comment (F6).
31
+ * `podNameFor` reserves an 8-char budget so this never overflows for a
32
+ * label it produced; `Rfc1123Label.withSuffix` is the enforced backstop —
33
+ * it throws instead of silently emitting an invalid >63-char Secret name
34
+ * if that budget were ever wrong. */
35
+ export function secretNameFor(podName, kind) {
36
+ return podName.withSuffix(kind).value;
37
+ }
38
+ //# sourceMappingURL=secret.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secret.js","sourceRoot":"","sources":["../../../src/sandbox/k8s/secret.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,mBAAmB,CAAC,CAKnC;IACC,OAAO;QACL,UAAU,EAAE,IAAI;QAChB,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE;YACR,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,SAAS,EAAE,CAAC,CAAC,SAAS;YACtB,MAAM,EAAE,EAAE,8BAA8B,EAAE,WAAW,EAAE,GAAG,CAAC,CAAC,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE;SAC7E;QACD,+EAA+E;QAC/E,UAAU,EAAE,CAAC,CAAC,IAAI;KACnB,CAAC;AACJ,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,iBAAiB,CAAC,OAAe,EAAE,MAAc;IAC/D,OAAO;QACL,UAAU,EAAE,IAAI;QAChB,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,OAAO;QACb,GAAG,EAAE,MAAM;QACX,UAAU,EAAE,IAAI;QAChB,kBAAkB,EAAE,IAAI;KACzB,CAAC;AACJ,CAAC;AAED;;;;;;;;sCAQsC;AACtC,MAAM,UAAU,aAAa,CAAC,OAAqB,EAAE,IAAwB;IAC3E,OAAO,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC;AACxC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { Hono } from "hono";
2
+ import type { SkillBundleRegistry } from "./skill-bundle.js";
3
+ /**
4
+ * Mount the internal skill-bundle endpoint on the shared Hono app. A sandbox
5
+ * Pod's initContainer fetches `GET /internal/skill-bundle` with the per-run
6
+ * token (`Authorization: Bearer <token>`) it received in its creds Secret; the
7
+ * token gates each Pod to its own bundle. Backend-agnostic — with no k8s runs,
8
+ * nothing is ever registered, so every request 401s.
9
+ */
10
+ export declare function mountSkillBundle(app: Hono, registry: SkillBundleRegistry): void;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Mount the internal skill-bundle endpoint on the shared Hono app. A sandbox
3
+ * Pod's initContainer fetches `GET /internal/skill-bundle` with the per-run
4
+ * token (`Authorization: Bearer <token>`) it received in its creds Secret; the
5
+ * token gates each Pod to its own bundle. Backend-agnostic — with no k8s runs,
6
+ * nothing is ever registered, so every request 401s.
7
+ */
8
+ export function mountSkillBundle(app, registry) {
9
+ app.get("/internal/skill-bundle", (c) => {
10
+ const header = c.req.header("authorization") ?? "";
11
+ const token = header.replace(/^Bearer\s+/i, "").trim();
12
+ const tar = token ? registry.get(token) : undefined;
13
+ if (!tar)
14
+ return c.body(null, 401);
15
+ return c.body(new Uint8Array(tar), 200, { "Content-Type": "application/gzip" });
16
+ });
17
+ }
18
+ //# sourceMappingURL=skill-bundle-route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skill-bundle-route.js","sourceRoot":"","sources":["../../../src/sandbox/k8s/skill-bundle-route.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAS,EAAE,QAA6B;IACvE,GAAG,CAAC,GAAG,CAAC,wBAAwB,EAAE,CAAC,CAAC,EAAE,EAAE;QACtC,MAAM,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC;QACnD,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACvD,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACpD,IAAI,CAAC,GAAG;YAAE,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QACnC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC,CAAC;IAClF,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,36 @@
1
+ /** In-pod mount root where the skills initContainer unpacks the bundle and the
2
+ * agent loads it from via `--skill`. */
3
+ export declare const SKILLS_MOUNT_DIR = "/lastlight-skills";
4
+ /** Reduce a skill dir name to a shell/path-safe token so the `--skill
5
+ * <SKILLS_MOUNT_DIR>/<name>` path can be interpolated without escaping. */
6
+ export declare function sanitizeSkillName(name: string): string;
7
+ /**
8
+ * Package the resolved skill dirs into a gzipped tar (built via system `tar` —
9
+ * no npm dep). Each dir lands under its sanitized basename, so the tar unpacks
10
+ * to `<name>/SKILL.md`, `<name>/scripts/…`, etc. Synchronous by design: the
11
+ * `Sandbox.stageSkills` port is sync and bundles are tiny (~tens of KB).
12
+ */
13
+ export declare function buildSkillTar(skillPaths: readonly string[]): {
14
+ tar: Buffer;
15
+ names: string[];
16
+ };
17
+ /**
18
+ * In-memory token→bundle store shared by the adapter (writer) and the
19
+ * `/internal/skill-bundle` route (reader). A per-run token gates each Pod to
20
+ * its own bundle. Primary reclaim is explicit: the orchestrator's run
21
+ * bracket calls `evict()` on both success and error. The TTL is a lazy
22
+ * backstop, not a timer — an expired entry is only dropped the next time its
23
+ * token is looked up via `get()`, so a token nobody ever queries again just
24
+ * sits in the Map until the process exits (bounded by process lifetime; a
25
+ * crash frees the whole thing).
26
+ */
27
+ export declare class SkillBundleRegistry {
28
+ private readonly ttlMs;
29
+ private readonly bundles;
30
+ constructor(ttlMs?: number);
31
+ register(tar: Buffer): string;
32
+ get(token: string): Buffer | undefined;
33
+ evict(token: string): void;
34
+ }
35
+ /** Process-wide singleton: the adapter registers, the HTTP route serves. */
36
+ export declare const skillBundleRegistry: SkillBundleRegistry;
@@ -0,0 +1,85 @@
1
+ import { cpSync, mkdtempSync, rmSync } from "node:fs";
2
+ import { tmpdir } from "node:os";
3
+ import { basename, join } from "node:path";
4
+ import { execFileSync } from "node:child_process";
5
+ import { randomUUID } from "node:crypto";
6
+ /** In-pod mount root where the skills initContainer unpacks the bundle and the
7
+ * agent loads it from via `--skill`. */
8
+ export const SKILLS_MOUNT_DIR = "/lastlight-skills";
9
+ const DEFAULT_TTL_MS = 30 * 60_000;
10
+ /** Reduce a skill dir name to a shell/path-safe token so the `--skill
11
+ * <SKILLS_MOUNT_DIR>/<name>` path can be interpolated without escaping. */
12
+ export function sanitizeSkillName(name) {
13
+ const clean = name.replace(/[^A-Za-z0-9_-]/g, "");
14
+ return clean || "skill";
15
+ }
16
+ /**
17
+ * Package the resolved skill dirs into a gzipped tar (built via system `tar` —
18
+ * no npm dep). Each dir lands under its sanitized basename, so the tar unpacks
19
+ * to `<name>/SKILL.md`, `<name>/scripts/…`, etc. Synchronous by design: the
20
+ * `Sandbox.stageSkills` port is sync and bundles are tiny (~tens of KB).
21
+ */
22
+ export function buildSkillTar(skillPaths) {
23
+ if (!skillPaths.length)
24
+ return { tar: Buffer.alloc(0), names: [] };
25
+ const staging = mkdtempSync(join(tmpdir(), "ll-skills-"));
26
+ try {
27
+ const names = [];
28
+ const seen = new Set();
29
+ for (const src of skillPaths) {
30
+ const name = sanitizeSkillName(basename(src));
31
+ if (seen.has(name)) {
32
+ throw new Error(`duplicate skill name after sanitization: "${name}" (from ${src}) — ` +
33
+ "skill dir basenames must be distinct");
34
+ }
35
+ seen.add(name);
36
+ cpSync(src, join(staging, name), { recursive: true, dereference: true });
37
+ names.push(name);
38
+ }
39
+ const tar = execFileSync("tar", ["-czf", "-", "-C", staging, "--", ...names], {
40
+ maxBuffer: 16 * 1024 * 1024,
41
+ });
42
+ return { tar, names };
43
+ }
44
+ finally {
45
+ rmSync(staging, { recursive: true, force: true });
46
+ }
47
+ }
48
+ /**
49
+ * In-memory token→bundle store shared by the adapter (writer) and the
50
+ * `/internal/skill-bundle` route (reader). A per-run token gates each Pod to
51
+ * its own bundle. Primary reclaim is explicit: the orchestrator's run
52
+ * bracket calls `evict()` on both success and error. The TTL is a lazy
53
+ * backstop, not a timer — an expired entry is only dropped the next time its
54
+ * token is looked up via `get()`, so a token nobody ever queries again just
55
+ * sits in the Map until the process exits (bounded by process lifetime; a
56
+ * crash frees the whole thing).
57
+ */
58
+ export class SkillBundleRegistry {
59
+ ttlMs;
60
+ bundles = new Map();
61
+ constructor(ttlMs = DEFAULT_TTL_MS) {
62
+ this.ttlMs = ttlMs;
63
+ }
64
+ register(tar) {
65
+ const token = randomUUID();
66
+ this.bundles.set(token, { tar, expires: Date.now() + this.ttlMs });
67
+ return token;
68
+ }
69
+ get(token) {
70
+ const entry = this.bundles.get(token);
71
+ if (!entry)
72
+ return undefined;
73
+ if (entry.expires <= Date.now()) {
74
+ this.bundles.delete(token);
75
+ return undefined;
76
+ }
77
+ return entry.tar;
78
+ }
79
+ evict(token) {
80
+ this.bundles.delete(token);
81
+ }
82
+ }
83
+ /** Process-wide singleton: the adapter registers, the HTTP route serves. */
84
+ export const skillBundleRegistry = new SkillBundleRegistry();
85
+ //# sourceMappingURL=skill-bundle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skill-bundle.js","sourceRoot":"","sources":["../../../src/sandbox/k8s/skill-bundle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;yCACyC;AACzC,MAAM,CAAC,MAAM,gBAAgB,GAAG,mBAAmB,CAAC;AAEpD,MAAM,cAAc,GAAG,EAAE,GAAG,MAAM,CAAC;AAEnC;4EAC4E;AAC5E,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;IAClD,OAAO,KAAK,IAAI,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AAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACpD,CAAC;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,OAAO,mBAAmB;IAGD;IAFZ,OAAO,GAAG,IAAI,GAAG,EAA4C,CAAC;IAE/E,YAA6B,QAAgB,cAAc;QAA9B,UAAK,GAAL,KAAK,CAAyB;IAAG,CAAC;IAE/D,QAAQ,CAAC,GAAW;QAClB,MAAM,KAAK,GAAG,UAAU,EAAE,CAAC;QAC3B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;QACnE,OAAO,KAAK,CAAC;IACf,CAAC;IAED,GAAG,CAAC,KAAa;QACf,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACtC,IAAI,CAAC,KAAK;YAAE,OAAO,SAAS,CAAC;QAC7B,IAAI,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;YAChC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC3B,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,OAAO,KAAK,CAAC,GAAG,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,KAAa;QACjB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;CACF;AAED,4EAA4E;AAC5E,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,mBAAmB,EAAE,CAAC"}
@@ -0,0 +1,47 @@
1
+ import { type K8sApis } from "./client.js";
2
+ /**
3
+ * The `kubernetes` backend's backstop sweep (Plan 5) — it runs in place of the
4
+ * host-dir sweep (`src/cron/sandbox-sweep.ts`), which is disabled on this
5
+ * backend, so it must cover BOTH surfaces the backend leaves behind:
6
+ *
7
+ * 1. **Cluster PVCs** — idle per-(repo,PR) workspace PVCs, reclaimed via
8
+ * `reclaimSandbox`'s `sweep` selector: age (`retentionHours`) then an LRU
9
+ * cap (`maxIdlePVCs`).
10
+ * 2. **Host-local artifact dirs** — the artifact store is host-local on every
11
+ * backend (`LocalArtifactBackend`), so a pod's uploaded `.lastlight/` lands
12
+ * at `<sandboxDir>/<taskId>` on the harness even under k8s. Reap-on-success
13
+ * (`simple.ts`) and the cancel route gc these on their own paths, but
14
+ * cancel-missed / failed / reuse-success runs would otherwise accumulate
15
+ * indefinitely (nothing else sweeps `<sandboxDir>` on k8s). When `stateDir`
16
+ * is given, this delegates to the same `sweepSandboxes` the host backend
17
+ * uses (age + LRU, same knobs) to bound them.
18
+ *
19
+ * Mirrors the host sweep's config knobs (`cleanup.sandbox.retentionHours` /
20
+ * `.maxDirs`) 1:1.
21
+ *
22
+ * Best-effort and off-cluster-safe: building the client (`makeK8sApis`) or
23
+ * running the PVC reclaim can fail — no kubeconfig in a dev harness, a transient
24
+ * transport error — and this must never throw out of the cron handler that
25
+ * calls it, so those are wrapped in a try/catch that warns and returns. The
26
+ * host-dir sweep is a pure filesystem op (already per-dir best-effort) and runs
27
+ * first, so a cluster-side failure never skips it.
28
+ *
29
+ * `apis` / `namespace` / `isLive` are test seams — production omits them and
30
+ * uses the real client, the resolved `kubernetes.namespace`, and the real
31
+ * live-container probe (a no-op on a k8s host, where docker is absent).
32
+ */
33
+ export interface SweepK8sOpts {
34
+ retentionHours: number;
35
+ maxIdlePVCs: number;
36
+ /** When set, also age/LRU-sweep host-local artifact dirs under
37
+ * `<sandboxDir>/<taskId>`. Omit (existing cluster-only callers) to skip it. */
38
+ stateDir?: string;
39
+ sandboxDir?: string;
40
+ /** LRU cap for host artifact dirs (defaults to `maxIdlePVCs` — the same
41
+ * `cleanup.sandbox.maxDirs` knob feeds both). */
42
+ maxDirs?: number;
43
+ apis?: K8sApis;
44
+ namespace?: string;
45
+ isLive?: (taskId: string) => boolean;
46
+ }
47
+ export declare function sweepK8sSandboxes(opts: SweepK8sOpts): Promise<void>;
@@ -0,0 +1,29 @@
1
+ import { resolveKubernetesConfig } from "../../config/config.js";
2
+ import { sweepSandboxes } from "../../cron/sandbox-sweep.js";
3
+ import { makeK8sApis } from "./client.js";
4
+ import { reclaimSandbox } from "./reclaim.js";
5
+ export async function sweepK8sSandboxes(opts) {
6
+ if (opts.stateDir) {
7
+ sweepSandboxes({
8
+ stateDir: opts.stateDir,
9
+ sandboxDir: opts.sandboxDir,
10
+ retentionHours: opts.retentionHours,
11
+ maxDirs: opts.maxDirs ?? opts.maxIdlePVCs,
12
+ isLive: opts.isLive,
13
+ });
14
+ }
15
+ try {
16
+ const apis = opts.apis ?? makeK8sApis();
17
+ const namespace = opts.namespace ?? resolveKubernetesConfig().namespace;
18
+ await reclaimSandbox(apis, namespace, {
19
+ kind: "sweep",
20
+ staleByHours: opts.retentionHours,
21
+ maxIdlePVCs: opts.maxIdlePVCs,
22
+ });
23
+ }
24
+ catch (err) {
25
+ const message = err instanceof Error ? err.message : String(err);
26
+ console.warn(`[k8s] sweepK8sSandboxes: skipping PVC reclaim — ${message}`);
27
+ }
28
+ }
29
+ //# sourceMappingURL=sweep.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sweep.js","sourceRoot":"","sources":["../../../src/sandbox/k8s/sweep.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAgB,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAgD9C,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,IAAkB;IACxD,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QAClB,cAAc,CAAC;YACb,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,WAAW;YACzC,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC,CAAC;IACL,CAAC;IACD,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,WAAW,EAAE,CAAC;QACxC,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,uBAAuB,EAAE,CAAC,SAAS,CAAC;QACxE,MAAM,cAAc,CAAC,IAAI,EAAE,SAAS,EAAE;YACpC,IAAI,EAAE,OAAO;YACb,YAAY,EAAE,IAAI,CAAC,cAAc;YACjC,WAAW,EAAE,IAAI,CAAC,WAAW;SAC9B,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACjE,OAAO,CAAC,IAAI,CAAC,mDAAmD,OAAO,EAAE,CAAC,CAAC;IAC7E,CAAC;AACH,CAAC"}
@@ -0,0 +1,51 @@
1
+ import { type CoreV1Api } from "@kubernetes/client-node";
2
+ import type { PrePopulateSpec, ProvisionResult } from "../sandbox.js";
3
+ import { type PodSpecInput } from "./pod.js";
4
+ /** The pod's workspace descriptor — an ephemeral in-pod `emptyDir`, or a
5
+ * stable per-(repo,PR) RWO PVC (design B). Mirrors `PodSpecInput.workspace`. */
6
+ type Workspace = PodSpecInput["workspace"];
7
+ /**
8
+ * Everything a `provision()` call hands the orchestrator: the {@link ProvisionResult}
9
+ * returned across the `Sandbox` port, plus the two pieces `runPod` needs later
10
+ * — the {@link Workspace} descriptor (emptyDir vs PVC) and the pre-clone
11
+ * descriptor (clone-init coordinates). Bundling them into one value is what
12
+ * lets `KubernetesSandbox` hold a single provision-scoped field instead of the
13
+ * old loose `pre` + `workspace` pair.
14
+ */
15
+ export interface Provisioned {
16
+ result: ProvisionResult;
17
+ workspace: Workspace;
18
+ pre?: PrePopulateSpec;
19
+ }
20
+ /** The subset of config the provisioner needs to size/class the PVC and derive
21
+ * its stable name. `taskId` keys the per-(repo,PR) claim (see `pvcNameFor`). */
22
+ export interface WorkspaceProvisionerConfig {
23
+ namespace: string;
24
+ storageClassName: string;
25
+ workspaceSize: string;
26
+ taskId: string;
27
+ }
28
+ /**
29
+ * Owns the pod's workspace lifecycle: an ephemeral `emptyDir` for a run with no
30
+ * pre-clone descriptor, or a stable per-(repo,PR) RWO PVC (design B, locked
31
+ * decision #2) when handed one. The PVC is created once and reused across
32
+ * runs/phases — never recreated or resized here (Plan 4/5). Extracted from
33
+ * `KubernetesSandbox` (F1) so the PVC-ensure logic is independently testable
34
+ * against a fake `CoreV1Api`.
35
+ */
36
+ export declare class WorkspaceProvisioner {
37
+ private readonly core;
38
+ private readonly cfg;
39
+ constructor(core: CoreV1Api, cfg: WorkspaceProvisionerConfig);
40
+ /** Provision the workspace for this sandbox. Without a pre-clone descriptor
41
+ * the run gets an ephemeral `emptyDir` and nothing is touched cluster-side;
42
+ * with one, the per-(repo,PR) PVC is ensured and the agent's cwd becomes the
43
+ * checkout subdir the clone-init writes at `<WORKSPACE_DIR>/<repo>`. */
44
+ provision(pre?: PrePopulateSpec): Promise<Provisioned>;
45
+ /** Ensure the named PVC exists, creating it on a 404. The `runId` (when the
46
+ * descriptor carried one) is stamped as a label so `reclaimSandbox` (Plan 5)
47
+ * can select the claim back by the same value — the stamp/select symmetry
48
+ * `RunId` enforces (F7). Any non-404 read error propagates. */
49
+ private ensurePvc;
50
+ }
51
+ export {};
@@ -0,0 +1,64 @@
1
+ import { ApiException } from "@kubernetes/client-node";
2
+ import { WORKSPACE_DIR } from "./pod.js";
3
+ import { buildPvcManifest, pvcNameFor } from "./pvc.js";
4
+ import { RunId } from "./run-id.js";
5
+ /**
6
+ * Owns the pod's workspace lifecycle: an ephemeral `emptyDir` for a run with no
7
+ * pre-clone descriptor, or a stable per-(repo,PR) RWO PVC (design B, locked
8
+ * decision #2) when handed one. The PVC is created once and reused across
9
+ * runs/phases — never recreated or resized here (Plan 4/5). Extracted from
10
+ * `KubernetesSandbox` (F1) so the PVC-ensure logic is independently testable
11
+ * against a fake `CoreV1Api`.
12
+ */
13
+ export class WorkspaceProvisioner {
14
+ core;
15
+ cfg;
16
+ constructor(core, cfg) {
17
+ this.core = core;
18
+ this.cfg = cfg;
19
+ }
20
+ /** Provision the workspace for this sandbox. Without a pre-clone descriptor
21
+ * the run gets an ephemeral `emptyDir` and nothing is touched cluster-side;
22
+ * with one, the per-(repo,PR) PVC is ensured and the agent's cwd becomes the
23
+ * checkout subdir the clone-init writes at `<WORKSPACE_DIR>/<repo>`. */
24
+ async provision(pre) {
25
+ if (!pre) {
26
+ return {
27
+ result: { hostWorkspaceDir: WORKSPACE_DIR, agentCwd: WORKSPACE_DIR },
28
+ workspace: { kind: "emptyDir" },
29
+ };
30
+ }
31
+ const claimName = pvcNameFor(this.cfg.taskId);
32
+ await this.ensurePvc(claimName, pre.runId ? RunId.from(pre.runId) : undefined);
33
+ return {
34
+ result: { hostWorkspaceDir: WORKSPACE_DIR, agentCwd: `${WORKSPACE_DIR}/${pre.repo}` },
35
+ workspace: { kind: "pvc", claimName },
36
+ pre,
37
+ };
38
+ }
39
+ /** Ensure the named PVC exists, creating it on a 404. The `runId` (when the
40
+ * descriptor carried one) is stamped as a label so `reclaimSandbox` (Plan 5)
41
+ * can select the claim back by the same value — the stamp/select symmetry
42
+ * `RunId` enforces (F7). Any non-404 read error propagates. */
43
+ async ensurePvc(name, runId) {
44
+ try {
45
+ await this.core.readNamespacedPersistentVolumeClaim({ name, namespace: this.cfg.namespace });
46
+ return;
47
+ }
48
+ catch (err) {
49
+ if (!(err instanceof ApiException) || err.code !== 404)
50
+ throw err;
51
+ }
52
+ await this.core.createNamespacedPersistentVolumeClaim({
53
+ namespace: this.cfg.namespace,
54
+ body: buildPvcManifest({
55
+ name,
56
+ namespace: this.cfg.namespace,
57
+ storageClassName: this.cfg.storageClassName,
58
+ size: this.cfg.workspaceSize,
59
+ runId,
60
+ }),
61
+ });
62
+ }
63
+ }
64
+ //# sourceMappingURL=workspace-provisioner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspace-provisioner.js","sourceRoot":"","sources":["../../../src/sandbox/k8s/workspace-provisioner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAkB,MAAM,yBAAyB,CAAC;AAEvE,OAAO,EAAE,aAAa,EAAqB,MAAM,UAAU,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AA6BpC;;;;;;;GAOG;AACH,MAAM,OAAO,oBAAoB;IAEZ;IACA;IAFnB,YACmB,IAAe,EACf,GAA+B;QAD/B,SAAI,GAAJ,IAAI,CAAW;QACf,QAAG,GAAH,GAAG,CAA4B;IAC/C,CAAC;IAEJ;;;6EAGyE;IACzE,KAAK,CAAC,SAAS,CAAC,GAAqB;QACnC,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,OAAO;gBACL,MAAM,EAAE,EAAE,gBAAgB,EAAE,aAAa,EAAE,QAAQ,EAAE,aAAa,EAAE;gBACpE,SAAS,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE;aAChC,CAAC;QACJ,CAAC;QACD,MAAM,SAAS,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC9C,MAAM,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAC/E,OAAO;YACL,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