@dynamicagents/plugins 0.11.1 → 0.12.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.
- package/README.md +12 -13
- package/dist/arc-agi/analysis.d.ts +16 -30
- package/dist/arc-agi/analysis.js +20 -47
- package/dist/arc-agi/game-tools.d.ts +5 -6
- package/dist/arc-agi/index.d.ts +6 -8
- package/dist/arc-agi/index.js +3 -3
- package/dist/arc-agi/main-agent.d.ts +5 -8
- package/dist/arc-agi/main-agent.js +5 -8
- package/dist/arc-agi/recipe.d.ts +17 -20
- package/dist/arc-agi/recipe.js +17 -20
- package/dist/arc-agi/soul.d.ts +16 -27
- package/dist/arc-agi/soul.js +16 -27
- package/dist/arc-agi/store.d.ts +4 -5
- package/dist/arc-agi/store.js +4 -5
- package/dist/arc-agi/tools.d.ts +1 -1
- package/dist/arc-agi/tools.js +10 -12
- package/dist/arc-agi/types.d.ts +6 -7
- package/dist/claude-code/config.d.ts +88 -11
- package/dist/claude-code/config.js +11 -2
- package/dist/claude-code/credentials.d.ts +21 -9
- package/dist/claude-code/credentials.js +43 -9
- package/dist/claude-code/egress.d.ts +7 -13
- package/dist/claude-code/egress.js +9 -10
- package/dist/claude-code/events.d.ts +47 -0
- package/dist/claude-code/events.js +96 -10
- package/dist/claude-code/index.d.ts +31 -13
- package/dist/claude-code/index.js +62 -15
- package/dist/claude-code/run.d.ts +135 -41
- package/dist/claude-code/run.js +366 -61
- package/dist/computer/advisory.d.ts +31 -18
- package/dist/computer/advisory.js +30 -5
- package/dist/computer/context.d.ts +23 -0
- package/dist/computer/context.js +225 -0
- package/dist/computer/file-lock.d.ts +5 -0
- package/dist/computer/file-lock.js +39 -0
- package/dist/computer/gate.d.ts +8 -8
- package/dist/computer/gate.js +7 -7
- package/dist/computer/host/ca-trust.d.ts +88 -0
- package/dist/computer/host/ca-trust.js +303 -0
- package/dist/computer/host/container-deps.d.ts +54 -0
- package/dist/computer/host/container-deps.js +224 -0
- package/dist/computer/host/container-fault.d.ts +38 -0
- package/dist/computer/host/container-fault.js +58 -0
- package/dist/computer/host/git-host.d.ts +62 -0
- package/dist/computer/host/git-host.js +156 -0
- package/dist/computer/host/git-identity.d.ts +57 -0
- package/dist/computer/host/git-identity.js +147 -0
- package/dist/computer/host/install-job.d.ts +121 -0
- package/dist/computer/host/install-job.js +766 -0
- package/dist/computer/host/sync.d.ts +111 -0
- package/dist/computer/host/sync.js +124 -0
- package/dist/computer/host/wake.d.ts +19 -0
- package/dist/computer/host/wake.js +10 -0
- package/dist/computer/host/workspace.d.ts +424 -0
- package/dist/computer/host/workspace.js +1258 -0
- package/dist/computer/index.d.ts +70 -50
- package/dist/computer/index.js +79 -767
- package/dist/computer/install.d.ts +8 -12
- package/dist/computer/install.js +6 -9
- package/dist/computer/paths.d.ts +21 -16
- package/dist/computer/paths.js +40 -38
- package/dist/computer/read.d.ts +18 -22
- package/dist/computer/read.js +24 -27
- package/dist/computer/render.d.ts +28 -0
- package/dist/computer/render.js +34 -1
- package/dist/computer/shell.d.ts +45 -0
- package/dist/computer/shell.js +80 -0
- package/dist/computer/tools-exec.d.ts +3 -0
- package/dist/computer/tools-exec.js +269 -0
- package/dist/computer/tools-file.d.ts +4 -0
- package/dist/computer/tools-file.js +124 -0
- package/dist/computer/tools-find.d.ts +3 -0
- package/dist/computer/tools-find.js +216 -0
- package/dist/recall/index.d.ts +9 -3
- package/dist/recall/index.js +22 -12
- package/dist/repo/checkout.d.ts +34 -4
- package/dist/repo/checkout.js +36 -1
- package/dist/repo/context.d.ts +109 -0
- package/dist/repo/context.js +530 -0
- package/dist/repo/index.d.ts +6 -29
- package/dist/repo/index.js +17 -1027
- package/dist/repo/tools-clone.d.ts +4 -0
- package/dist/repo/tools-clone.js +192 -0
- package/dist/repo/tools-forge.d.ts +4 -0
- package/dist/repo/tools-forge.js +179 -0
- package/dist/repo/tools-review.d.ts +3 -0
- package/dist/repo/tools-review.js +373 -0
- package/dist/repo/tools-worktree.d.ts +4 -0
- package/dist/repo/tools-worktree.js +221 -0
- package/dist/triage/index.d.ts +6 -1
- package/dist/triage/index.js +32 -23
- package/dist/workspace/index.d.ts +3 -3
- package/dist/workspace/index.js +3 -3
- package/package.json +21 -15
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { RepoGitResult } from "../../repo/index.js";
|
|
2
|
+
import type { GitClient } from "@cloudflare/computer/git";
|
|
3
|
+
/**
|
|
4
|
+
* The git operations that need the forge 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 `./workspace.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 forge 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
|
+
push(req: {
|
|
57
|
+
url: string;
|
|
58
|
+
dir: string;
|
|
59
|
+
branch: string;
|
|
60
|
+
allowedHosts: string[];
|
|
61
|
+
}): Promise<RepoGitResult>;
|
|
62
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
export class WorkspaceGitHost {
|
|
2
|
+
deps;
|
|
3
|
+
constructor(deps) {
|
|
4
|
+
this.deps = deps;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Each operation takes `url` explicitly rather than a remote name: resolving
|
|
8
|
+
* `origin` would read `.git/config`, a workspace file a co-installed shell
|
|
9
|
+
* tool can write.
|
|
10
|
+
*/
|
|
11
|
+
async clone(req) {
|
|
12
|
+
return this.#run(req.allowedHosts, async (git, onAuth) => {
|
|
13
|
+
// Spelled out rather than `git.clone`, and the reason is the credential.
|
|
14
|
+
//
|
|
15
|
+
// `clone` is the one network operation the client does not give an
|
|
16
|
+
// `onAuth` callback — it authenticates only through a `headers` option,
|
|
17
|
+
// which means attaching the token to the very first request to a URL the
|
|
18
|
+
// *model* chose. Composing the same work out of `fetch` puts every
|
|
19
|
+
// credentialed request on this side of `onAuth` instead, where the host is
|
|
20
|
+
// checked at the moment the token would be handed over. The cost is four
|
|
21
|
+
// calls instead of one; `clone` is these four.
|
|
22
|
+
await git.init({ dir: req.dir });
|
|
23
|
+
await git.remoteAdd({
|
|
24
|
+
dir: req.dir,
|
|
25
|
+
name: "origin",
|
|
26
|
+
url: req.url,
|
|
27
|
+
force: true
|
|
28
|
+
});
|
|
29
|
+
const fetched = await git.fetch({
|
|
30
|
+
url: req.url,
|
|
31
|
+
dir: req.dir,
|
|
32
|
+
onAuth,
|
|
33
|
+
// Omission is passed through as omission, because the tool the model
|
|
34
|
+
// reads says so: `repo_clone` describes `depth` as "omit for full
|
|
35
|
+
// history; needed if you must rebase", and `/repo` deliberately leaves
|
|
36
|
+
// the key off when it is unset. Defaulting to 1 here made every such
|
|
37
|
+
// clone shallow, so the one thing the model was told to omit it for —
|
|
38
|
+
// rebasing — failed on a repository it had asked for in full.
|
|
39
|
+
...(req.depth === undefined ? {} : { depth: req.depth }),
|
|
40
|
+
singleBranch: true,
|
|
41
|
+
tags: false,
|
|
42
|
+
...(req.branch ? { ref: req.branch } : {})
|
|
43
|
+
});
|
|
44
|
+
const landed = req.branch ?? fetched.defaultBranch?.replace(/^refs\/heads\//, "");
|
|
45
|
+
if (!landed)
|
|
46
|
+
throw new Error(`cloned ${req.url} but the remote named no default branch to check out`);
|
|
47
|
+
await git.checkout({ dir: req.dir, ref: landed });
|
|
48
|
+
// What a real `git clone` writes and the container's git will look for:
|
|
49
|
+
// without it the branch tracks nothing, and a subagent reaching for a bare
|
|
50
|
+
// `git status` in the shell sees a branch with no upstream.
|
|
51
|
+
await git.configSet({
|
|
52
|
+
dir: req.dir,
|
|
53
|
+
path: `branch.${landed}.remote`,
|
|
54
|
+
value: "origin"
|
|
55
|
+
});
|
|
56
|
+
await git.configSet({
|
|
57
|
+
dir: req.dir,
|
|
58
|
+
path: `branch.${landed}.merge`,
|
|
59
|
+
value: `refs/heads/${landed}`
|
|
60
|
+
});
|
|
61
|
+
return landed;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
async fetch(req) {
|
|
65
|
+
return this.#run(req.allowedHosts, async (git, onAuth) => {
|
|
66
|
+
const result = await git.fetch({
|
|
67
|
+
url: req.url,
|
|
68
|
+
dir: req.dir,
|
|
69
|
+
onAuth,
|
|
70
|
+
prune: true,
|
|
71
|
+
tags: false,
|
|
72
|
+
singleBranch: false,
|
|
73
|
+
...(req.depth ? { depth: req.depth } : {})
|
|
74
|
+
});
|
|
75
|
+
return `fetched ${req.url} (default branch ${result.defaultBranch ?? "unknown"})`;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
async push(req) {
|
|
79
|
+
return this.#run(req.allowedHosts, async (git, onAuth) => {
|
|
80
|
+
const result = await git.push({
|
|
81
|
+
url: req.url,
|
|
82
|
+
dir: req.dir,
|
|
83
|
+
ref: req.branch,
|
|
84
|
+
remoteRef: req.branch,
|
|
85
|
+
onAuth
|
|
86
|
+
// No `force`, ever, and not a knob: `/repo` refuses anything but a plain
|
|
87
|
+
// branch name precisely so that a push cannot be turned into a force
|
|
88
|
+
// push, and this is the other end of that promise.
|
|
89
|
+
});
|
|
90
|
+
// isomorphic-git reports a rejected push in the *result* rather than by
|
|
91
|
+
// throwing — a non-fast-forward comes back `ok: false` with the reason on
|
|
92
|
+
// the ref. Reading only the absence of an exception would report every
|
|
93
|
+
// rejected push as a success, in the one plugin whose entire theme is that
|
|
94
|
+
// a failed command is not a completed operation.
|
|
95
|
+
if (!result.ok) {
|
|
96
|
+
const perRef = Object.entries(result.refs)
|
|
97
|
+
.filter(([, status]) => !status.ok)
|
|
98
|
+
.map(([ref, status]) => `${ref}: ${status.error ?? "rejected"}`)
|
|
99
|
+
.join("; ");
|
|
100
|
+
// `||`, not `??`, on the second rung: `perRef` is a joined string, so
|
|
101
|
+
// "no failing ref carried a reason" is `""` rather than nullish — and
|
|
102
|
+
// `??` would hand that through as the error message. A rejected push
|
|
103
|
+
// reporting a blank reason is the one outcome worse than a generic one.
|
|
104
|
+
throw new Error(result.error ?? (perRef || "the remote rejected the push"));
|
|
105
|
+
}
|
|
106
|
+
return `pushed ${req.branch} to ${req.url}`;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The shared body: entry-point bookkeeping, the credential, and the translation
|
|
111
|
+
* back into something that survives RPC.
|
|
112
|
+
*
|
|
113
|
+
* A thrown `GitError` loses its prototype crossing a Durable Object boundary,
|
|
114
|
+
* so `instanceof` on the far side is not available and the caller would be left
|
|
115
|
+
* pattern-matching a string. The `code` is lifted here, while the error is
|
|
116
|
+
* still itself, and travels as data.
|
|
117
|
+
*/
|
|
118
|
+
async #run(allowedHosts, body) {
|
|
119
|
+
// Bound to the credential rather than checked before the call, which is
|
|
120
|
+
// strictly stronger: this is the moment the token would be handed over, and
|
|
121
|
+
// it sees the URL git actually authenticated against — including one it
|
|
122
|
+
// reached by redirect. A host nobody allowed gets no credential and the
|
|
123
|
+
// request fails unauthenticated, rather than the token being offered to it
|
|
124
|
+
// and *then* the mistake being noticed.
|
|
125
|
+
const onAuth = (url) => {
|
|
126
|
+
let host;
|
|
127
|
+
try {
|
|
128
|
+
const parsed = new URL(url);
|
|
129
|
+
if (parsed.protocol !== "https:")
|
|
130
|
+
return {};
|
|
131
|
+
host = parsed.hostname;
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return {};
|
|
135
|
+
}
|
|
136
|
+
if (!allowedHosts.includes(host)) {
|
|
137
|
+
console.warn(`[${this.deps.tag()}] refused to authenticate to a host`, {
|
|
138
|
+
host
|
|
139
|
+
});
|
|
140
|
+
return {};
|
|
141
|
+
}
|
|
142
|
+
return { username: "x-access-token", password: this.deps.token() };
|
|
143
|
+
};
|
|
144
|
+
try {
|
|
145
|
+
return { ok: true, detail: await body(this.deps.git(), onAuth) };
|
|
146
|
+
}
|
|
147
|
+
catch (err) {
|
|
148
|
+
const code = err?.code;
|
|
149
|
+
return {
|
|
150
|
+
ok: false,
|
|
151
|
+
...(typeof code === "string" ? { code } : {}),
|
|
152
|
+
message: err instanceof Error ? err.message : String(err)
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { type Workspace } from "@cloudflare/computer";
|
|
2
|
+
import type { Scheduler } from "@dynamicagents/core/alarm";
|
|
3
|
+
import { type InstallPlan, type InstallState } from "../install.js";
|
|
4
|
+
import type { WorkspaceWakeHandlers } from "./wake.js";
|
|
5
|
+
export interface InstallJobDeps {
|
|
6
|
+
storage: DurableObjectStorage;
|
|
7
|
+
scheduler: Scheduler<WorkspaceWakeHandlers>;
|
|
8
|
+
workspace: () => Workspace;
|
|
9
|
+
/** How this deployment installs dependencies for this agent's checkouts. */
|
|
10
|
+
plan: () => InstallPlan;
|
|
11
|
+
/** How long an install may run before it is killed. */
|
|
12
|
+
timeoutMs: () => number;
|
|
13
|
+
/** Set only when the workspace is over its ceiling. */
|
|
14
|
+
headroom: () => {
|
|
15
|
+
bytes: number;
|
|
16
|
+
capBytes: number;
|
|
17
|
+
} | undefined;
|
|
18
|
+
/** The object's own entry-point bookkeeping, which an install still owes. */
|
|
19
|
+
touch: () => Promise<void>;
|
|
20
|
+
ready: () => Promise<void>;
|
|
21
|
+
/** Hand a drain to the invocation, for the caller that can hold one. */
|
|
22
|
+
waitUntil: (promise: Promise<unknown>) => void;
|
|
23
|
+
/** A container was replaced, so nothing believed about it still holds. */
|
|
24
|
+
containerGone: () => Promise<void>;
|
|
25
|
+
tag: () => string;
|
|
26
|
+
id: () => string;
|
|
27
|
+
}
|
|
28
|
+
export declare class InstallJob {
|
|
29
|
+
#private;
|
|
30
|
+
private readonly deps;
|
|
31
|
+
constructor(deps: InstallJobDeps);
|
|
32
|
+
/**
|
|
33
|
+
* Start a dependency install the moment we can see one will be needed.
|
|
34
|
+
*
|
|
35
|
+
* The signal is {@link CONTAINER_TREE_KEY}: a local read, true only while the
|
|
36
|
+
* container that ran the install is the one running.
|
|
37
|
+
*
|
|
38
|
+
* Armed as soon as a container is up or a command is about to start one,
|
|
39
|
+
* because the model's first minute is README-reading and `git status` — an
|
|
40
|
+
* install armed there runs *through* that minute, where one armed on the first
|
|
41
|
+
* `npm` command charges its full time to that command.
|
|
42
|
+
*
|
|
43
|
+
* It writes `running` before anything is running: the alarm has not fired yet,
|
|
44
|
+
* and a `done` record would let an `npm` command through against a tree that
|
|
45
|
+
* is not there. That also makes this self-limiting — the next call sees
|
|
46
|
+
* `running` and stops.
|
|
47
|
+
*/
|
|
48
|
+
armIfTreeMissing(): Promise<void>;
|
|
49
|
+
/** Where the last install ran, for the container setup's marker read. */
|
|
50
|
+
dir(): Promise<string | undefined>;
|
|
51
|
+
/** The container went away, and its tree with it. */
|
|
52
|
+
containerGone(): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Check the record against the marker a new isolate's setup read.
|
|
55
|
+
*
|
|
56
|
+
* The record can outlive its container in an isolate that did not watch it
|
|
57
|
+
* exit; the marker cannot.
|
|
58
|
+
*/
|
|
59
|
+
reconcile(marker: string | null): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* The record exactly as the job wrote it, with no staleness bound applied.
|
|
62
|
+
*
|
|
63
|
+
* {@link state} is what almost everything wants. This is for the one caller
|
|
64
|
+
* that must not repair anything on the way past: the container-idle handler,
|
|
65
|
+
* which only needs to know whether something is running before it destroys the
|
|
66
|
+
* container underneath it.
|
|
67
|
+
*/
|
|
68
|
+
read(): Promise<InstallState>;
|
|
69
|
+
/**
|
|
70
|
+
* Start installing this checkout's dependencies, and return without waiting.
|
|
71
|
+
*
|
|
72
|
+
* Called from `repo_clone` through the repo plugin's `afterCheckout` hook, so
|
|
73
|
+
* it runs inside a model turn and must not block on the install — 225 seconds
|
|
74
|
+
* for slack-gatekeeper, against a chunk step that dies at ten minutes.
|
|
75
|
+
*
|
|
76
|
+
* That caller is a model turn, which lives long enough to hold the drain handed
|
|
77
|
+
* to `ctx.waitUntil` below. **A short-lived caller cannot**, which is why an
|
|
78
|
+
* install the alarm drives is awaited inside that alarm rather than calling
|
|
79
|
+
* this.
|
|
80
|
+
*/
|
|
81
|
+
start(req: {
|
|
82
|
+
dir: string;
|
|
83
|
+
repo?: string;
|
|
84
|
+
}): Promise<InstallState>;
|
|
85
|
+
/**
|
|
86
|
+
* Whether this container holds a finished tree, asked only when it qualifies a
|
|
87
|
+
* `deps-broken` advisory (see `deriveAdvisories`).
|
|
88
|
+
*/
|
|
89
|
+
treePresentIfItMatters(install: InstallState): Promise<boolean>;
|
|
90
|
+
/**
|
|
91
|
+
* The install record itself, with its staleness bound and re-attach applied.
|
|
92
|
+
*
|
|
93
|
+
* Split from {@link advisories} so `startInstall` can consult the record
|
|
94
|
+
* without going through the `node_modules` probe, which needs a container and
|
|
95
|
+
* has nothing to say about whether an install may start.
|
|
96
|
+
*
|
|
97
|
+
* Re-attaches on the way past. An isolate reset leaves the record saying
|
|
98
|
+
* `running` with nothing draining it, and without this the state would say
|
|
99
|
+
* `running` forever while the command had long since finished.
|
|
100
|
+
*/
|
|
101
|
+
state(): Promise<InstallState>;
|
|
102
|
+
/**
|
|
103
|
+
* When a reinstall was queued, if one is waiting to run.
|
|
104
|
+
*
|
|
105
|
+
* Read by {@link file://../advisory.ts deriveAdvisories}, which is the only
|
|
106
|
+
* caller that needs it: a `failed` record with a repair already queued is a
|
|
107
|
+
* transient condition wearing a permanent record's clothes.
|
|
108
|
+
*/
|
|
109
|
+
reinstallArmedAt(): Promise<number | undefined>;
|
|
110
|
+
/**
|
|
111
|
+
* The armed reinstall came due.
|
|
112
|
+
*
|
|
113
|
+
* `clearArmed` first and unconditionally: this handler runs for minutes, and
|
|
114
|
+
* the stamp left in place is what a second arming would recognise as its own.
|
|
115
|
+
* `startInstall`'s in-flight guard would catch a double, but the cheaper
|
|
116
|
+
* answer is not to schedule one.
|
|
117
|
+
*/
|
|
118
|
+
onRun(): Promise<void>;
|
|
119
|
+
/** The watchdog: an install still running that nobody is draining. */
|
|
120
|
+
onWatch(): Promise<void>;
|
|
121
|
+
}
|