@dynamicagents/plugins 0.11.1 → 0.13.0

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 (134) hide show
  1. package/README.md +59 -79
  2. package/dist/browser/index.d.ts +0 -2
  3. package/dist/browser/index.js +21 -27
  4. package/dist/claude-code/cards.d.ts +53 -0
  5. package/dist/claude-code/cards.js +272 -0
  6. package/dist/claude-code/config.d.ts +73 -31
  7. package/dist/claude-code/config.js +0 -2
  8. package/dist/claude-code/credentials.d.ts +21 -9
  9. package/dist/claude-code/credentials.js +43 -9
  10. package/dist/claude-code/egress.d.ts +15 -14
  11. package/dist/claude-code/egress.js +51 -14
  12. package/dist/claude-code/events.d.ts +153 -9
  13. package/dist/claude-code/events.js +289 -58
  14. package/dist/claude-code/github.d.ts +39 -0
  15. package/dist/claude-code/github.js +82 -0
  16. package/dist/claude-code/index.d.ts +24 -80
  17. package/dist/claude-code/index.js +19 -234
  18. package/dist/claude-code/model.d.ts +152 -0
  19. package/dist/claude-code/model.js +342 -0
  20. package/dist/claude-code/run.d.ts +283 -92
  21. package/dist/claude-code/run.js +620 -114
  22. package/dist/claude-code/session.d.ts +131 -0
  23. package/dist/claude-code/session.js +285 -0
  24. package/dist/claude-code/spec.d.ts +46 -0
  25. package/dist/claude-code/spec.js +83 -0
  26. package/dist/claude-code/verified.d.ts +15 -0
  27. package/dist/claude-code/verified.js +15 -0
  28. package/dist/computer/context.d.ts +19 -0
  29. package/dist/computer/context.js +222 -0
  30. package/dist/computer/file-lock.d.ts +5 -0
  31. package/dist/computer/file-lock.js +40 -0
  32. package/dist/computer/gate.d.ts +12 -12
  33. package/dist/computer/gate.js +12 -12
  34. package/dist/computer/index.d.ts +57 -255
  35. package/dist/computer/index.js +98 -1039
  36. package/dist/computer/paths.d.ts +47 -22
  37. package/dist/computer/paths.js +64 -49
  38. package/dist/computer/proxy.d.ts +45 -0
  39. package/dist/computer/proxy.js +234 -0
  40. package/dist/computer/render.d.ts +27 -38
  41. package/dist/computer/render.js +32 -65
  42. package/dist/computer/tools-exec.d.ts +3 -0
  43. package/dist/computer/tools-exec.js +268 -0
  44. package/dist/computer/tools-file.d.ts +12 -0
  45. package/dist/computer/tools-file.js +64 -0
  46. package/dist/computer/tools-grep.d.ts +3 -0
  47. package/dist/computer/tools-grep.js +129 -0
  48. package/dist/repo/checkout.d.ts +35 -6
  49. package/dist/repo/checkout.js +64 -6
  50. package/dist/repo/context.d.ts +135 -0
  51. package/dist/repo/context.js +582 -0
  52. package/dist/repo/index.d.ts +79 -57
  53. package/dist/repo/index.js +118 -1112
  54. package/dist/repo/tools-checks.d.ts +3 -0
  55. package/dist/repo/tools-checks.js +112 -0
  56. package/dist/repo/tools-clone.d.ts +4 -0
  57. package/dist/repo/tools-clone.js +192 -0
  58. package/dist/repo/tools-pr.d.ts +14 -0
  59. package/dist/repo/tools-pr.js +196 -0
  60. package/dist/repo/tools-review.d.ts +12 -0
  61. package/dist/repo/tools-review.js +393 -0
  62. package/dist/repo/tools-worktree.d.ts +4 -0
  63. package/dist/repo/tools-worktree.js +305 -0
  64. package/dist/repo/tools-worktrees.d.ts +12 -0
  65. package/dist/repo/tools-worktrees.js +48 -0
  66. package/dist/repo/url.d.ts +2 -2
  67. package/dist/repo/url.js +7 -7
  68. package/dist/scratch/index.d.ts +4 -4
  69. package/dist/scratch/index.js +12 -11
  70. package/dist/{computer → workspace}/advisory.d.ts +33 -20
  71. package/dist/{computer → workspace}/advisory.js +32 -7
  72. package/dist/workspace/ca-trust.d.ts +95 -0
  73. package/dist/workspace/ca-trust.js +312 -0
  74. package/dist/workspace/container-deps.d.ts +54 -0
  75. package/dist/workspace/container-deps.js +224 -0
  76. package/dist/workspace/container-fault.d.ts +38 -0
  77. package/dist/workspace/container-fault.js +73 -0
  78. package/dist/workspace/exec.d.ts +94 -0
  79. package/dist/workspace/exec.js +153 -0
  80. package/dist/workspace/format.d.ts +36 -0
  81. package/dist/workspace/format.js +57 -0
  82. package/dist/workspace/git-host.d.ts +79 -0
  83. package/dist/workspace/git-host.js +226 -0
  84. package/dist/workspace/git-identity.d.ts +57 -0
  85. package/dist/workspace/git-identity.js +147 -0
  86. package/dist/workspace/index.d.ts +43 -47
  87. package/dist/workspace/index.js +52 -112
  88. package/dist/workspace/install-job.d.ts +121 -0
  89. package/dist/workspace/install-job.js +866 -0
  90. package/dist/{computer → workspace}/install.d.ts +15 -19
  91. package/dist/{computer → workspace}/install.js +8 -11
  92. package/dist/workspace/object.d.ts +502 -0
  93. package/dist/workspace/object.js +1427 -0
  94. package/dist/workspace/open.d.ts +95 -0
  95. package/dist/workspace/open.js +63 -0
  96. package/dist/workspace/read.d.ts +16 -0
  97. package/dist/workspace/read.js +22 -0
  98. package/dist/workspace/shell.d.ts +45 -0
  99. package/dist/workspace/shell.js +80 -0
  100. package/dist/workspace/sync.d.ts +111 -0
  101. package/dist/workspace/sync.js +124 -0
  102. package/dist/workspace/wake.d.ts +19 -0
  103. package/dist/workspace/wake.js +10 -0
  104. package/package.json +28 -42
  105. package/dist/arc-agi/analysis.d.ts +0 -336
  106. package/dist/arc-agi/analysis.js +0 -829
  107. package/dist/arc-agi/client.d.ts +0 -82
  108. package/dist/arc-agi/client.js +0 -113
  109. package/dist/arc-agi/game-tools.d.ts +0 -25
  110. package/dist/arc-agi/game-tools.js +0 -26
  111. package/dist/arc-agi/index.d.ts +0 -42
  112. package/dist/arc-agi/index.js +0 -175
  113. package/dist/arc-agi/main-agent.d.ts +0 -27
  114. package/dist/arc-agi/main-agent.js +0 -65
  115. package/dist/arc-agi/recipe.d.ts +0 -51
  116. package/dist/arc-agi/recipe.js +0 -100
  117. package/dist/arc-agi/scorecard.d.ts +0 -118
  118. package/dist/arc-agi/scorecard.js +0 -163
  119. package/dist/arc-agi/soul.d.ts +0 -40
  120. package/dist/arc-agi/soul.js +0 -90
  121. package/dist/arc-agi/store.d.ts +0 -154
  122. package/dist/arc-agi/store.js +0 -216
  123. package/dist/arc-agi/tools.d.ts +0 -36
  124. package/dist/arc-agi/tools.js +0 -576
  125. package/dist/arc-agi/types.d.ts +0 -212
  126. package/dist/arc-agi/types.js +0 -19
  127. package/dist/claude-code/recipe.d.ts +0 -53
  128. package/dist/claude-code/recipe.js +0 -100
  129. package/dist/computer/read.d.ts +0 -137
  130. package/dist/computer/read.js +0 -203
  131. package/dist/recall/index.d.ts +0 -99
  132. package/dist/recall/index.js +0 -171
  133. package/dist/triage/index.d.ts +0 -355
  134. package/dist/triage/index.js +0 -302
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Text shared by the workspace and the tools over it: the output bound, the
3
+ * elapsed-time phrase, and what a killed command is told.
4
+ */
5
+ /**
6
+ * Middle-out truncation, so both the first error and the final summary survive.
7
+ *
8
+ * The guard is not defensive padding. Without it a `max` at or below the marker's
9
+ * own length makes `half` zero or negative, and `slice(-0)` is `slice(0)` — the
10
+ * *whole* string — so the function returns more than it was given: 500 characters
11
+ * in, 543 out at `max: 80`. A silent inversion of the one thing it does,
12
+ * reachable from a public config field.
13
+ */
14
+ export function truncateOutput(text, max) {
15
+ if (text.length <= max)
16
+ return text;
17
+ const marker = (dropped) => `\n\n… [${dropped} characters omitted from the middle] …\n\n`;
18
+ // No budget for two halves plus the marker: keep the head, which is where the
19
+ // first error is, and say nothing clever.
20
+ const half = Math.floor((max - marker(text.length).length) / 2);
21
+ if (half < 1)
22
+ return text.slice(0, Math.max(0, max));
23
+ return (text.slice(0, half) + marker(text.length - half * 2) + text.slice(-half));
24
+ }
25
+ /** Elapsed time in the shape a sentence wants. */
26
+ export function humanMs(ms) {
27
+ const s = Math.round(ms / 1000);
28
+ return s < 60
29
+ ? `${s}s`
30
+ : `${Math.floor(s / 60)}m${String(s % 60).padStart(2, "0")}s`;
31
+ }
32
+ /**
33
+ * Why a command has nothing to show for itself.
34
+ *
35
+ * {@link renderResult} states a non-`completed` status on its verdict line;
36
+ * {@link file://./exec.ts workspaceExec} has no verdict line, only the four fields its caller
37
+ * branches on. A *killed* process writes nothing, so without this a `git clone`
38
+ * that hit the ten-minute ceiling reaches the model through
39
+ * `@dynamicagents/plugins/repo` as `clone failed:` with an empty reason — which reads
40
+ * like a bug in the plugin rather than a limit it can work within.
41
+ *
42
+ * Only `cancelled`. A `failed` status is an ordinary non-zero exit, where the
43
+ * command's own stderr is the better explanation and this would be noise on top
44
+ * of it.
45
+ *
46
+ * Both plausible causes are named because the exit code cannot separate them:
47
+ * 137 is SIGKILL, which is what the timeout sends *and* what the kernel sends a
48
+ * container that ran out of memory.
49
+ */
50
+ export function cancelledNote(status, exitCode, timeoutMs) {
51
+ if (status !== "cancelled")
52
+ return undefined;
53
+ return (`the command was killed rather than exiting on its own (exit ${exitCode}), so ` +
54
+ `anything it had not yet written is gone. The two usual causes are the ` +
55
+ `per-command time limit — ${humanMs(timeoutMs)} here — and the container ` +
56
+ `running out of memory.`);
57
+ }
@@ -0,0 +1,79 @@
1
+ import type { RepoGitResult } from "../repo/index.js";
2
+ import type { GitClient } from "@cloudflare/computer/git";
3
+ /**
4
+ * The git operations that need the GitHub token, run on this side.
5
+ *
6
+ * They are here rather than on the `WorkspaceStub` the plugin already holds
7
+ * because `WorkspaceGitStub` exposes only `cli(argv)` across a Durable Object
8
+ * boundary, and argv cannot carry an `onAuth` callback. Routed through here, the
9
+ * credential is read from the workspace object's own `env` and never crosses an
10
+ * RPC boundary, never appears in an argument list, and never enters the
11
+ * container.
12
+ *
13
+ * That last clause is the point, and it is why running credentialed `git` in the
14
+ * container is not an option however carefully it is sandboxed: git executes
15
+ * whatever `.git/config` and `.git/hooks` name, the model has a root shell on
16
+ * that filesystem, and even a disposable git dir leaves the token readable
17
+ * through `/proc` for the life of the process. isomorphic-git runs here and has
18
+ * no hooks, no `ext::` transport, no template directory and no credential
19
+ * helpers.
20
+ *
21
+ * **The caller owns the preconditions.** Bringing the workspace up to date is
22
+ * the workspace object's job and it must happen first: git here reads that
23
+ * object's SQLite, so a commit made in the container that has not been pulled
24
+ * yet is a commit this code cannot see. The workspace object's `gitClone`,
25
+ * `gitFetch` and `gitPush` in `./object.ts` are where that is settled.
26
+ */
27
+ export interface GitHostDeps {
28
+ /** The workspace's own client — isomorphic-git over the local store. */
29
+ git: () => GitClient;
30
+ /** The GitHub credential, read at the moment it would be handed over. */
31
+ token: () => string | undefined;
32
+ tag: () => string;
33
+ }
34
+ export declare class WorkspaceGitHost {
35
+ #private;
36
+ private readonly deps;
37
+ constructor(deps: GitHostDeps);
38
+ /**
39
+ * Each operation takes `url` explicitly rather than a remote name: resolving
40
+ * `origin` would read `.git/config`, a workspace file a co-installed shell
41
+ * tool can write.
42
+ */
43
+ clone(req: {
44
+ url: string;
45
+ dir: string;
46
+ allowedHosts: string[];
47
+ branch?: string;
48
+ depth?: number;
49
+ }): Promise<RepoGitResult>;
50
+ fetch(req: {
51
+ url: string;
52
+ dir: string;
53
+ allowedHosts: string[];
54
+ depth?: number;
55
+ }): Promise<RepoGitResult>;
56
+ /**
57
+ * `remote.origin.url` from the local store, or `undefined` where there is no
58
+ * checkout or no origin. Reads only, and needs no credential.
59
+ */
60
+ origin(dir: string): Promise<string | undefined>;
61
+ push(req: {
62
+ url: string;
63
+ dir: string;
64
+ branch: string;
65
+ allowedHosts: string[];
66
+ }): Promise<RepoGitResult>;
67
+ }
68
+ /**
69
+ * A git error's message with the chain of causes behind it.
70
+ *
71
+ * `@cloudflare/computer/git` wraps isomorphic-git's errors, and classifies some
72
+ * by a heuristic: any failure whose message mentions `.git` beside a missing
73
+ * path or a ref it could not find is reported as "not a git repository" — a
74
+ * sentence that is wrong about a checkout that plainly is one, and names
75
+ * neither the file nor the ref. What actually failed is only on `cause`, which
76
+ * a Durable Object boundary does not carry, so it is folded into the message
77
+ * here while the error is still itself.
78
+ */
79
+ export declare function describeGitError(err: unknown): string;
@@ -0,0 +1,226 @@
1
+ /**
2
+ * What the container's own `git init` would write, over isomorphic-git's.
3
+ *
4
+ * isomorphic-git's `init` writes `core.*` for a filesystem without symlinks or
5
+ * an executable bit that ignores case, and the container's git obeys it. With
6
+ * `symlinks = false`, a command there that rewrites the tree — starter puts a
7
+ * worktree on its branch with `checkout -f` — writes each link as a file holding
8
+ * its target, and `status` calls that clean. With `filemode = false`, a script
9
+ * made executable is committed as 100644. The store models all three.
10
+ */
11
+ const CONTAINER_CORE_CONFIG = {
12
+ "core.symlinks": true,
13
+ "core.filemode": true,
14
+ "core.ignorecase": false
15
+ };
16
+ export class WorkspaceGitHost {
17
+ deps;
18
+ constructor(deps) {
19
+ this.deps = deps;
20
+ }
21
+ /**
22
+ * Each operation takes `url` explicitly rather than a remote name: resolving
23
+ * `origin` would read `.git/config`, a workspace file a co-installed shell
24
+ * tool can write.
25
+ */
26
+ async clone(req) {
27
+ return this.#run(req.allowedHosts, async (git, onAuth) => {
28
+ // Spelled out rather than `git.clone`, and the reason is the credential.
29
+ //
30
+ // `clone` is the one network operation the client does not give an
31
+ // `onAuth` callback — it authenticates only through a `headers` option,
32
+ // which means attaching the token to the very first request to a URL the
33
+ // *model* chose. Composing the same work out of `fetch` puts every
34
+ // credentialed request on this side of `onAuth` instead, where the host is
35
+ // checked at the moment the token would be handed over. The cost is four
36
+ // calls instead of one; `clone` is these four.
37
+ await git.init({ dir: req.dir });
38
+ // Straight after `init`, so a clone that fails part-way leaves nothing
39
+ // behind that the container's git would misread.
40
+ for (const [path, value] of Object.entries(CONTAINER_CORE_CONFIG))
41
+ await git.configSet({ dir: req.dir, path, value });
42
+ await git.remoteAdd({
43
+ dir: req.dir,
44
+ name: "origin",
45
+ url: req.url,
46
+ force: true
47
+ });
48
+ const fetched = await git.fetch({
49
+ url: req.url,
50
+ dir: req.dir,
51
+ onAuth,
52
+ // Omission is passed through as omission, because the tool the model
53
+ // reads says so: `repo_clone` describes `depth` as "omit for full
54
+ // history; needed if you must rebase", and `/repo` deliberately leaves
55
+ // the key off when it is unset. Defaulting to 1 here made every such
56
+ // clone shallow, so the one thing the model was told to omit it for —
57
+ // rebasing — failed on a repository it had asked for in full.
58
+ ...(req.depth === undefined ? {} : { depth: req.depth }),
59
+ singleBranch: true,
60
+ tags: false,
61
+ ...(req.branch ? { ref: req.branch } : {})
62
+ });
63
+ const landed = req.branch ?? fetched.defaultBranch?.replace(/^refs\/heads\//, "");
64
+ if (!landed)
65
+ throw new Error(`cloned ${req.url} but the remote named no default branch to check out`);
66
+ await git.checkout({ dir: req.dir, ref: landed });
67
+ // What a real `git clone` writes and the container's git will look for:
68
+ // without it the branch tracks nothing, and an agent reaching for a bare
69
+ // `git status` in the shell sees a branch with no upstream.
70
+ await git.configSet({
71
+ dir: req.dir,
72
+ path: `branch.${landed}.remote`,
73
+ value: "origin"
74
+ });
75
+ await git.configSet({
76
+ dir: req.dir,
77
+ path: `branch.${landed}.merge`,
78
+ value: `refs/heads/${landed}`
79
+ });
80
+ return landed;
81
+ });
82
+ }
83
+ async fetch(req) {
84
+ return this.#run(req.allowedHosts, async (git, onAuth) => {
85
+ const result = await git.fetch({
86
+ url: req.url,
87
+ dir: req.dir,
88
+ onAuth,
89
+ prune: true,
90
+ tags: false,
91
+ singleBranch: false,
92
+ // Every branch is fetched, but isomorphic-git still resolves one ref
93
+ // against the remote's list, and left to itself it picks the current
94
+ // branch's upstream. A checkout left on a branch whose pull request
95
+ // merged — and whose remote branch went with it — then fails every
96
+ // fetch with `Could not find refs/heads/<branch>`. The remote's HEAD
97
+ // is always listed.
98
+ remoteRef: "HEAD",
99
+ ...(req.depth ? { depth: req.depth } : {})
100
+ });
101
+ return `fetched ${req.url} (default branch ${result.defaultBranch ?? "unknown"})`;
102
+ });
103
+ }
104
+ /**
105
+ * `remote.origin.url` from the local store, or `undefined` where there is no
106
+ * checkout or no origin. Reads only, and needs no credential.
107
+ */
108
+ async origin(dir) {
109
+ try {
110
+ const url = await this.deps
111
+ .git()
112
+ .configGet({ dir, path: "remote.origin.url" });
113
+ return typeof url === "string" && url ? url : undefined;
114
+ }
115
+ catch {
116
+ return undefined;
117
+ }
118
+ }
119
+ async push(req) {
120
+ return this.#run(req.allowedHosts, async (git, onAuth) => {
121
+ const result = await git.push({
122
+ url: req.url,
123
+ dir: req.dir,
124
+ ref: req.branch,
125
+ remoteRef: req.branch,
126
+ onAuth
127
+ // No `force`, ever, and not a knob: `/repo` refuses anything but a plain
128
+ // branch name precisely so that a push cannot be turned into a force
129
+ // push, and this is the other end of that promise.
130
+ });
131
+ // isomorphic-git reports a rejected push in the *result* rather than by
132
+ // throwing — a non-fast-forward comes back `ok: false` with the reason on
133
+ // the ref. Reading only the absence of an exception would report every
134
+ // rejected push as a success, in the one plugin whose entire theme is that
135
+ // a failed command is not a completed operation.
136
+ if (!result.ok) {
137
+ const perRef = Object.entries(result.refs)
138
+ .filter(([, status]) => !status.ok)
139
+ .map(([ref, status]) => `${ref}: ${status.error ?? "rejected"}`)
140
+ .join("; ");
141
+ // `||`, not `??`, on the second rung: `perRef` is a joined string, so
142
+ // "no failing ref carried a reason" is `""` rather than nullish — and
143
+ // `??` would hand that through as the error message. A rejected push
144
+ // reporting a blank reason is the one outcome worse than a generic one.
145
+ throw new Error(result.error ?? (perRef || "the remote rejected the push"));
146
+ }
147
+ return `pushed ${req.branch} to ${req.url}`;
148
+ });
149
+ }
150
+ /**
151
+ * The shared body: entry-point bookkeeping, the credential, and the translation
152
+ * back into something that survives RPC.
153
+ *
154
+ * A thrown `GitError` loses its prototype crossing a Durable Object boundary,
155
+ * so `instanceof` on the far side is not available and the caller would be left
156
+ * pattern-matching a string. The `code` is lifted here, while the error is
157
+ * still itself, and travels as data.
158
+ */
159
+ async #run(allowedHosts, body) {
160
+ // Bound to the credential rather than checked before the call, which is
161
+ // strictly stronger: this is the moment the token would be handed over, and
162
+ // it sees the URL git actually authenticated against — including one it
163
+ // reached by redirect. A host nobody allowed gets no credential and the
164
+ // request fails unauthenticated, rather than the token being offered to it
165
+ // and *then* the mistake being noticed.
166
+ const onAuth = (url) => {
167
+ let host;
168
+ try {
169
+ const parsed = new URL(url);
170
+ if (parsed.protocol !== "https:")
171
+ return {};
172
+ host = parsed.hostname;
173
+ }
174
+ catch {
175
+ return {};
176
+ }
177
+ if (!allowedHosts.includes(host)) {
178
+ console.warn(`[${this.deps.tag()}] refused to authenticate to a host`, {
179
+ host
180
+ });
181
+ return {};
182
+ }
183
+ return { username: "x-access-token", password: this.deps.token() };
184
+ };
185
+ try {
186
+ return { ok: true, detail: await body(this.deps.git(), onAuth) };
187
+ }
188
+ catch (err) {
189
+ const code = err?.code;
190
+ const message = describeGitError(err);
191
+ console.error(`[${this.deps.tag()}] git failed`, { code, message });
192
+ return {
193
+ ok: false,
194
+ ...(typeof code === "string" ? { code } : {}),
195
+ message
196
+ };
197
+ }
198
+ }
199
+ }
200
+ /**
201
+ * A git error's message with the chain of causes behind it.
202
+ *
203
+ * `@cloudflare/computer/git` wraps isomorphic-git's errors, and classifies some
204
+ * by a heuristic: any failure whose message mentions `.git` beside a missing
205
+ * path or a ref it could not find is reported as "not a git repository" — a
206
+ * sentence that is wrong about a checkout that plainly is one, and names
207
+ * neither the file nor the ref. What actually failed is only on `cause`, which
208
+ * a Durable Object boundary does not carry, so it is folded into the message
209
+ * here while the error is still itself.
210
+ */
211
+ export function describeGitError(err) {
212
+ const parts = [];
213
+ const seen = new Set();
214
+ let at = err;
215
+ for (let depth = 0; at !== undefined && at !== null && depth < 4; depth++) {
216
+ const e = at;
217
+ const text = typeof e.message === "string" ? e.message : String(at);
218
+ if (!seen.has(text)) {
219
+ seen.add(text);
220
+ const name = typeof e.name === "string" ? e.name : "";
221
+ parts.push(name && depth > 0 ? `${name}: ${text}` : text);
222
+ }
223
+ at = e.cause;
224
+ }
225
+ return parts.join(" ← ");
226
+ }
@@ -0,0 +1,57 @@
1
+ import type { Workspace } from "@cloudflare/computer";
2
+ /**
3
+ * The identity a commit made in this container carries when nothing nearer
4
+ * answers for it.
5
+ *
6
+ * `/repo` configures the checkouts it clones and names the identity on every
7
+ * commit it makes — see {@link file://../repo/checkout.ts writeGitIdentity}.
8
+ * Neither reaches a repository the container made for itself: a submodule
9
+ * checked out by a bootstrap, a `git init`, a second clone from the shell. Those
10
+ * have no identity at all, and git refuses to commit without one — so whatever
11
+ * is driving the shell has to invent a name to get past the refusal, and that
12
+ * invention is what ends up in the history.
13
+ *
14
+ * This is the layer underneath, so there is nothing to invent: every repository
15
+ * in the container starts out attributed to the deployment.
16
+ *
17
+ * **System scope, not global.** `--global` writes `$HOME/.gitconfig`, and a
18
+ * command run through the runtime cannot count on `HOME` being set to anything
19
+ * in particular — nor is the identity a property of one user of the container.
20
+ * `--system` is also the *lowest* precedence git has, which is the right place
21
+ * for it: a checkout's own config still wins, and so does the environment
22
+ * `/repo` and the session's launch put on a commit.
23
+ */
24
+ /** Written to `/etc/gitconfig`; the values arrive as variables, never inline. */
25
+ export declare const GIT_IDENTITY_COMMAND: string;
26
+ export interface ContainerGitIdentityDeps {
27
+ workspace: () => Workspace;
28
+ author: () => {
29
+ name: string;
30
+ email: string;
31
+ };
32
+ /** Log prefix and object id, for the one line an operator can see. */
33
+ tag: () => string;
34
+ id: () => string;
35
+ }
36
+ /**
37
+ * The write above, once per container.
38
+ *
39
+ * In memory, with {@link file://./ca-trust.ts}'s lifetime and for its reason: it
40
+ * describes one container, and an isolate that lost it re-runs an idempotent
41
+ * command.
42
+ */
43
+ export declare class ContainerGitIdentity {
44
+ #private;
45
+ private readonly deps;
46
+ constructor(deps: ContainerGitIdentityDeps);
47
+ forget(): void;
48
+ /**
49
+ * Configure this container if it has not been configured yet.
50
+ *
51
+ * **Never throws**, like the CA install and unlike the dependency setup. What
52
+ * a failure costs is an attribution, and every later commit says plainly that
53
+ * it has no identity to use — where a throw here would fail a workspace that
54
+ * is otherwise entirely usable.
55
+ */
56
+ ensure(): Promise<void>;
57
+ }
@@ -0,0 +1,147 @@
1
+ var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
2
+ if (value !== null && value !== void 0) {
3
+ if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
4
+ var dispose, inner;
5
+ if (async) {
6
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
7
+ dispose = value[Symbol.asyncDispose];
8
+ }
9
+ if (dispose === void 0) {
10
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
11
+ dispose = value[Symbol.dispose];
12
+ if (async) inner = dispose;
13
+ }
14
+ if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
15
+ if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
16
+ env.stack.push({ value: value, dispose: dispose, async: async });
17
+ }
18
+ else if (async) {
19
+ env.stack.push({ async: true });
20
+ }
21
+ return value;
22
+ };
23
+ var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
24
+ return function (env) {
25
+ function fail(e) {
26
+ env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
27
+ env.hasError = true;
28
+ }
29
+ var r, s = 0;
30
+ function next() {
31
+ while (r = env.stack.pop()) {
32
+ try {
33
+ if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
34
+ if (r.dispose) {
35
+ var result = r.dispose.call(r.value);
36
+ if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
37
+ }
38
+ else s |= 1;
39
+ }
40
+ catch (e) {
41
+ fail(e);
42
+ }
43
+ }
44
+ if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
45
+ if (env.hasError) throw env.error;
46
+ }
47
+ return next();
48
+ };
49
+ })(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
50
+ var e = new Error(message);
51
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
52
+ });
53
+ /**
54
+ * The identity a commit made in this container carries when nothing nearer
55
+ * answers for it.
56
+ *
57
+ * `/repo` configures the checkouts it clones and names the identity on every
58
+ * commit it makes — see {@link file://../repo/checkout.ts writeGitIdentity}.
59
+ * Neither reaches a repository the container made for itself: a submodule
60
+ * checked out by a bootstrap, a `git init`, a second clone from the shell. Those
61
+ * have no identity at all, and git refuses to commit without one — so whatever
62
+ * is driving the shell has to invent a name to get past the refusal, and that
63
+ * invention is what ends up in the history.
64
+ *
65
+ * This is the layer underneath, so there is nothing to invent: every repository
66
+ * in the container starts out attributed to the deployment.
67
+ *
68
+ * **System scope, not global.** `--global` writes `$HOME/.gitconfig`, and a
69
+ * command run through the runtime cannot count on `HOME` being set to anything
70
+ * in particular — nor is the identity a property of one user of the container.
71
+ * `--system` is also the *lowest* precedence git has, which is the right place
72
+ * for it: a checkout's own config still wins, and so does the environment
73
+ * `/repo` and the session's launch put on a commit.
74
+ */
75
+ /** Written to `/etc/gitconfig`; the values arrive as variables, never inline. */
76
+ export const GIT_IDENTITY_COMMAND = [
77
+ 'git config --system user.name "$GIT_NAME"',
78
+ 'git config --system user.email "$GIT_EMAIL"',
79
+ "echo IDENTITY OK"
80
+ ].join(" && ");
81
+ /** How long the write may take before it is not going to happen. */
82
+ const IDENTITY_TIMEOUT_MS = 30_000;
83
+ /**
84
+ * The write above, once per container.
85
+ *
86
+ * In memory, with {@link file://./ca-trust.ts}'s lifetime and for its reason: it
87
+ * describes one container, and an isolate that lost it re-runs an idempotent
88
+ * command.
89
+ */
90
+ export class ContainerGitIdentity {
91
+ deps;
92
+ #done = false;
93
+ constructor(deps) {
94
+ this.deps = deps;
95
+ }
96
+ forget() {
97
+ this.#done = false;
98
+ }
99
+ /**
100
+ * Configure this container if it has not been configured yet.
101
+ *
102
+ * **Never throws**, like the CA install and unlike the dependency setup. What
103
+ * a failure costs is an attribution, and every later commit says plainly that
104
+ * it has no identity to use — where a throw here would fail a workspace that
105
+ * is otherwise entirely usable.
106
+ */
107
+ async ensure() {
108
+ if (this.#done)
109
+ return;
110
+ const author = this.deps.author();
111
+ try {
112
+ const env_1 = { stack: [], error: void 0, hasError: false };
113
+ try {
114
+ const handle = __addDisposableResource(env_1, await this.deps
115
+ .workspace()
116
+ .runtime.exec(GIT_IDENTITY_COMMAND, {
117
+ cwd: "/",
118
+ encoding: "utf8",
119
+ timeoutMs: IDENTITY_TIMEOUT_MS,
120
+ env: { GIT_NAME: author.name, GIT_EMAIL: author.email }
121
+ }), false);
122
+ const result = await handle.result();
123
+ const output = `${result.stdout ?? ""}${result.stderr ?? ""}`;
124
+ this.#done = result.exitCode === 0 && output.includes("IDENTITY OK");
125
+ if (this.#done)
126
+ return;
127
+ console.warn(`[${this.deps.tag()}] could not set the container's git identity`, {
128
+ id: this.deps.id(),
129
+ output: output.trim()
130
+ });
131
+ }
132
+ catch (e_1) {
133
+ env_1.error = e_1;
134
+ env_1.hasError = true;
135
+ }
136
+ finally {
137
+ __disposeResources(env_1);
138
+ }
139
+ }
140
+ catch (err) {
141
+ console.warn(`[${this.deps.tag()}] could not set the container's git identity`, {
142
+ id: this.deps.id(),
143
+ err: String(err)
144
+ });
145
+ }
146
+ }
147
+ }