@akanjs/devkit 3.3.0-rc.2 → 3.3.0-rc.21
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/CHANGELOG.md +284 -20
- package/DEV_RUNTIME_KNOBS.md +1 -1
- package/README.ko.md +3 -2
- package/README.md +3 -3
- package/akanApp/akanApp.host.test.ts +1 -1
- package/akanConfig/akanConfig.test.ts +57 -8
- package/akanConfig/akanConfig.ts +16 -69
- package/akanConfig/dockerImage.ts +17 -0
- package/akanConfig/nativeKeys.ts +52 -0
- package/app/applicationBuildRunner.test.ts +321 -1
- package/app/applicationBuildRunner.ts +90 -3
- package/artifact/implicitRootLayoutRender.test.tsx +4 -1
- package/codeAgent/agent/CodeAgent.ts +36 -16
- package/codeAgent/agent/CodeAgentAllowed.ts +35 -0
- package/codeAgent/agent/CodeAgentCommandLine.ts +372 -0
- package/codeAgent/agent/CodeAgentGate.ts +23 -4
- package/codeAgent/agent/CodeAgentRpcHost.ts +1 -1
- package/codeAgent/agent/codeAgent.test.ts +62 -0
- package/codeAgent/agent/codeAgentCommandLine.test.ts +212 -0
- package/codeAgent/agent/codeAgentContract.test.ts +117 -5
- package/codeAgent/skills/akan-agent/SKILL.md +8 -1
- package/codeAgent/skills/akan-code/SKILL.md +38 -3
- package/codeAgent/skills/akan-err/SKILL.md +11 -2
- package/codeAgent/skills/akan-page/SKILL.md +21 -26
- package/codeAgent/skills/akan-runtime/SKILL.md +41 -16
- package/codeAgent/skills/akan-service/SKILL.md +2 -2
- package/docs/apiReference.test.ts +14 -0
- package/docs/apiReference.ts +21 -3
- package/docs/declarationReader.ts +28 -1
- package/executors/appExecutor.ts +16 -7
- package/executors/workspaceExecutor.ts +7 -4
- package/frontendBuild/buildRouteClient.test.ts +2 -7
- package/frontendBuild/clientEntryDiscovery.test.ts +35 -0
- package/frontendBuild/clientEntryDiscovery.ts +16 -3
- package/frontendBuild/cssCompiler.test.ts +112 -0
- package/frontendBuild/cssCompiler.ts +41 -21
- package/frontendBuild/devBarrelImports.test.ts +30 -0
- package/frontendBuild/devBarrelImports.ts +2 -2
- package/frontendBuild/pagesBundleBuilder.ts +3 -1
- package/frontendBuild/plainStylesheet.test.ts +155 -0
- package/frontendBuild/plainStylesheet.ts +197 -0
- package/frontendBuild/rscServerRendererGuard.test.ts +60 -0
- package/frontendBuild/rscServerRendererGuard.ts +68 -0
- package/guideline/agentAssets.test.ts +10 -0
- package/guideline/agentAssets.ts +52 -11
- package/incrementalBuilder/buildBatch.proc.ts +9 -9
- package/incrementalBuilder/buildBatchProtocol.ts +1 -1
- package/incrementalBuilder/builderBoot.ts +5 -5
- package/incrementalBuilder/builderGraphPayloads.ts +4 -4
- package/incrementalBuilder/builderLanes.ts +2 -2
- package/incrementalBuilder/builderWatch.ts +8 -8
- package/incrementalBuilder/csrRegistry.ts +4 -4
- package/incrementalBuilder/incrementalBuilder.proc.ts +8 -8
- package/incrementalBuilder/ssrRegistry.ts +6 -6
- package/index.ts +1 -1
- package/integration/renderAdmissionSoak.test.ts +99 -0
- package/integration/renderAdmissionSoak.ts +609 -0
- package/lint/__fixtures__/no-arbitrary-color/every-color-function/bad.tsx +11 -0
- package/lint/__fixtures__/no-arbitrary-color/every-color-function/good.tsx +2 -0
- package/lint/__fixtures__/no-daisyui-legacy-class/every-class/bad.tsx +34 -0
- package/lint/__fixtures__/no-daisyui-legacy-class/every-class/good.tsx +2 -0
- package/lint/__fixtures__/no-inline-color/every-color-function/bad.tsx +10 -0
- package/lint/__fixtures__/no-inline-color/every-color-function/good.tsx +2 -0
- package/lint/__fixtures__/no-raw-palette-class/every-palette/bad.tsx +22 -0
- package/lint/__fixtures__/no-raw-palette-class/every-palette/good.tsx +2 -0
- package/lint/biomeCheck.test.ts +145 -0
- package/lint/biomeCheck.ts +131 -0
- package/lint/no-arbitrary-color.grit +5 -0
- package/lint/no-conditional-st-hook.grit +5 -1
- package/lint/no-daisyui-legacy-class.grit +8 -0
- package/lint/no-document-cookie.grit +3 -0
- package/lint/no-inline-color.grit +10 -2
- package/lint/no-oversized-list-limit.grit +2 -0
- package/lint/no-raw-palette-class.grit +7 -0
- package/lint/no-unpublished-form-setter.grit +2 -0
- package/lint/no-web-only-api-outside-webkit.grit +5 -0
- package/lint/no-web-storage.grit +3 -0
- package/lint/withheldEnvFile.ts +17 -0
- package/mobile/nativeApp.test.ts +7 -5
- package/mobile/nativeApp.ts +2 -2
- package/mobile/nativeConfig.test.ts +117 -1
- package/mobile/nativeConfig.ts +66 -22
- package/mobile/serverBundleSecrets.ts +43 -0
- package/package.json +14 -169
- package/packageExports.test.ts +38 -24
- package/test/secretEnvFixture.ts +134 -0
- package/transforms/barrelAnalyzer.ts +2 -2
- package/transforms/secretEnvDeclaration.test.ts +208 -0
- package/transforms/secretEnvDeclaration.ts +213 -0
- package/transforms/secretEnvFile.test.ts +117 -0
- package/transforms/secretEnvFile.ts +113 -0
- package/transforms/secretEnvName.test.ts +54 -0
- package/transforms/secretEnvName.ts +29 -0
- package/transforms/secretEnvSource.test.ts +148 -0
- package/transforms/secretEnvSource.ts +166 -0
- package/transforms/serverEnvEvaluationError.ts +11 -0
- package/transforms/serverEnvPlugin.test.ts +2 -1
- package/transforms/serverEnvPlugin.ts +13 -0
- package/transforms/serverEnvProfile.test.ts +115 -2
- package/transforms/serverEnvProfile.ts +117 -40
- package/transforms/serverEnvSecrets.test.ts +292 -0
- package/transforms/transforms.test.ts +3 -3
- package/tunnel/createTunnel.test.ts +29 -8
- package/tunnel/createTunnel.ts +18 -11
- package/typecheck/projectTypecheck.test.ts +29 -0
- package/typecheck/typeChecker.test.ts +49 -0
- package/typecheck/typeChecker.ts +9 -7
- package/typecheck/withheldDiagnostics.ts +41 -0
- package/util/fileEditor.ts +1 -0
- package/util/selectModel.ts +1 -0
- package/workspace/getRelatedCnsts.ts +7 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { toError } from "akanjs/common";
|
|
3
3
|
import { BUILD_ENV_FILE } from "akanjs/server/lifecycle/buildEnv";
|
|
4
|
+
import { SecretEnv } from "akanjs/server/lifecycle/secretEnv";
|
|
4
5
|
import type { BunPlugin } from "bun";
|
|
5
6
|
import { ProductionLockfile } from "../akanConfig/productionLockfile";
|
|
6
7
|
import type { App } from "../commandDecorators";
|
|
@@ -14,6 +15,10 @@ import {
|
|
|
14
15
|
SsrBaseArtifactBuilder,
|
|
15
16
|
VendorImportScanner,
|
|
16
17
|
} from "../frontendBuild";
|
|
18
|
+
import { ServerBundleSecrets } from "../mobile/serverBundleSecrets";
|
|
19
|
+
import { SecretEnvDeclaration, type SecretEnvDeclared } from "../transforms/secretEnvDeclaration";
|
|
20
|
+
import { SecretEnvFile } from "../transforms/secretEnvFile";
|
|
21
|
+
import { ServerEnvEvaluationError } from "../transforms/serverEnvEvaluationError";
|
|
17
22
|
import { createServerEnvPlugin } from "../transforms/serverEnvPlugin";
|
|
18
23
|
import { ServerEnvProfile } from "../transforms/serverEnvProfile";
|
|
19
24
|
import { ProjectTypecheck } from "../typecheck/projectTypecheck";
|
|
@@ -59,6 +64,12 @@ export interface ApplicationBuildRunnerOptions {
|
|
|
59
64
|
environment?: string;
|
|
60
65
|
/** Bundles `env/env.server.<environment>.<profile>.ts`, which may hold no secret, in place of the environment's file. */
|
|
61
66
|
profile?: string;
|
|
67
|
+
/**
|
|
68
|
+
* An image build's: `read` leaves the server env's secret strings out of the server, which reads each from its process
|
|
69
|
+
* env, and `inline` keeps them in it as what an unset variable falls back to. Unset, as for the server a desktop app
|
|
70
|
+
* carries, or under a `profile`, the env files are bundled as written.
|
|
71
|
+
*/
|
|
72
|
+
secretEnv?: "read" | "inline";
|
|
62
73
|
/**
|
|
63
74
|
* `enforce` fails on an overage, a route with no entry, or a missing or unreadable akan.budget.json; `update` and
|
|
64
75
|
* `raise` rewrite the file first; `report` only warns.
|
|
@@ -109,6 +120,8 @@ export class ApplicationBuildRunner {
|
|
|
109
120
|
#reporter?: BuildProgressReporter;
|
|
110
121
|
#environment?: string;
|
|
111
122
|
#profile?: string;
|
|
123
|
+
#secretEnv?: "read" | "inline";
|
|
124
|
+
#secrets: SecretEnvDeclared = { variables: [], unmoved: [], moved: [] };
|
|
112
125
|
#budget: RouteJsBudgetMode;
|
|
113
126
|
#modulesByRoute?: Record<string, string[]>;
|
|
114
127
|
#spinner?: boolean;
|
|
@@ -123,6 +136,7 @@ export class ApplicationBuildRunner {
|
|
|
123
136
|
reporter,
|
|
124
137
|
environment,
|
|
125
138
|
profile,
|
|
139
|
+
secretEnv,
|
|
126
140
|
budget = "report",
|
|
127
141
|
}: ApplicationBuildRunnerOptions = {},
|
|
128
142
|
) {
|
|
@@ -132,6 +146,7 @@ export class ApplicationBuildRunner {
|
|
|
132
146
|
this.#reporter = reporter;
|
|
133
147
|
this.#environment = environment;
|
|
134
148
|
this.#profile = profile;
|
|
149
|
+
this.#secretEnv = profile ? undefined : secretEnv;
|
|
135
150
|
this.#budget = budget;
|
|
136
151
|
}
|
|
137
152
|
|
|
@@ -164,6 +179,7 @@ export class ApplicationBuildRunner {
|
|
|
164
179
|
async build({ spinner = false }: BuildOptions = {}): Promise<BuildResult> {
|
|
165
180
|
// serial build is needed because of Bun.build is unstable for parallel build
|
|
166
181
|
this.#spinner = spinner;
|
|
182
|
+
if (this.#verify) this.#app.useVerifyDist();
|
|
167
183
|
const { web, assets, baseDevEnv } = await this.#app.getConfig();
|
|
168
184
|
const environment = this.#environment ?? baseDevEnv.env;
|
|
169
185
|
WorkspaceExecutor.assertDeployableEnv(baseDevEnv, environment, "akan build");
|
|
@@ -171,6 +187,7 @@ export class ApplicationBuildRunner {
|
|
|
171
187
|
//? Before any phase: a profile that would ship a secret stops the build, not the image after it.
|
|
172
188
|
if (this.#profile)
|
|
173
189
|
await ServerEnvProfile.assertShippable({ envDir: this.#envDir, environment, profile: this.#profile });
|
|
190
|
+
if (this.#secretEnv) await this.#declareSecrets(environment);
|
|
174
191
|
await this.#runPhase("prepare", "Preparing output directory", () => this.#app.prepareCommand("build"));
|
|
175
192
|
if (!this.#fast) await this.#runPhase("typecheck", "Typechecking", () => this.typecheck());
|
|
176
193
|
await this.#runPhase(
|
|
@@ -220,10 +237,68 @@ export class ApplicationBuildRunner {
|
|
|
220
237
|
: "no files",
|
|
221
238
|
);
|
|
222
239
|
const routeJs = await this.#runBudgetPhase(environment);
|
|
240
|
+
await this.assertSecretsLeftOut();
|
|
223
241
|
await this.#runPhase("metadata", "Writing production metadata", () => this.buildAppMeta());
|
|
242
|
+
this.#reportSecretEnv(environment);
|
|
224
243
|
return this.#resultOf(environment, routeJs);
|
|
225
244
|
}
|
|
226
245
|
|
|
246
|
+
//* A build that cannot load the env file cannot say what it left out, so it stops; under --inline-secrets, which
|
|
247
|
+
//* leaves nothing out, it goes on as a build without the setting does.
|
|
248
|
+
async #declareSecrets(environment: string) {
|
|
249
|
+
try {
|
|
250
|
+
this.#secrets = await SecretEnvDeclaration.of(this.#envDir, environment);
|
|
251
|
+
} catch (error) {
|
|
252
|
+
if (!(error instanceof ServerEnvEvaluationError)) throw error;
|
|
253
|
+
if (this.#secretEnv === "read")
|
|
254
|
+
throw new Error(
|
|
255
|
+
`${error.message}\nA build leaves the secret values of the server env out of what it writes, and names the variables the server reads them from by loading the env file: with no variable of this shell first, then with them. Make the file load at that line, by setting the variable it reads there in this shell or giving it a fallback, and build again. \`akan build --inline-secrets\` builds with the env files as written until akanjs 3.5.0 removes it.`,
|
|
256
|
+
);
|
|
257
|
+
this.#app.logger.warn(
|
|
258
|
+
`--inline-secrets: ${error.message}. The secret values of the server env could not be listed, so this build holds the env files as written: the server reads no secret from a variable of its process env, and names none at boot.`,
|
|
259
|
+
);
|
|
260
|
+
this.#secretEnv = undefined;
|
|
261
|
+
}
|
|
262
|
+
//? Before any phase, and by the env's value alone: a search of the files written misses a short or a plain one.
|
|
263
|
+
if (this.#secretEnv === "read" && this.#secrets.unmoved.length)
|
|
264
|
+
throw new Error(
|
|
265
|
+
SecretEnvFile.unmovedStop(
|
|
266
|
+
this.#app.name,
|
|
267
|
+
environment,
|
|
268
|
+
path
|
|
269
|
+
.relative(this.#app.workspace.workspaceRoot, path.join(this.#envDir, "env.server.ts"))
|
|
270
|
+
.replaceAll("\\", "/"),
|
|
271
|
+
this.#secrets.unmoved,
|
|
272
|
+
),
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
//? Before the metadata phase: a build that still holds a secret gets no Dockerfile to build an image from.
|
|
277
|
+
async assertSecretsLeftOut() {
|
|
278
|
+
if (this.#secretEnv !== "read" || !this.#secrets.moved.length) return;
|
|
279
|
+
const { workspaceRoot } = this.#app.workspace;
|
|
280
|
+
const note = await new ServerBundleSecrets(workspaceRoot, this.#app.cwdPath).assertImageClean(
|
|
281
|
+
this.#app.dist.cwdPath,
|
|
282
|
+
this.#secrets.moved,
|
|
283
|
+
);
|
|
284
|
+
if (note) this.#app.logger.warn(note);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
#reportSecretEnv(environment: string) {
|
|
288
|
+
const { variables } = this.#secrets;
|
|
289
|
+
const { logger, name } = this.#app;
|
|
290
|
+
const names = variables.map((variable) => variable.name).join(", ");
|
|
291
|
+
const count = `${variables.length} secret value${variables.length === 1 ? "" : "s"}`;
|
|
292
|
+
if (variables.length && this.#secretEnv === "inline")
|
|
293
|
+
logger.warn(
|
|
294
|
+
`--inline-secrets keeps ${count} of the server env in this build, where whoever can read the image reads them: ${names}. A variable the deployment sets still wins over the built-in value. akanjs 3.5.0 removes the flag: set them where the server is deployed and build without it.`,
|
|
295
|
+
);
|
|
296
|
+
else if (variables.length)
|
|
297
|
+
logger.info(
|
|
298
|
+
`The server reads ${count} from its process env when it starts, not from this build: ${names}. Set them where it is deployed; \`akan secret-env ${name} --env ${environment}\` lists them and writes them from the env file.`,
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
|
|
227
302
|
#runBudgetPhase(environment: string) {
|
|
228
303
|
return this.#runPhase(
|
|
229
304
|
"budget",
|
|
@@ -304,10 +379,11 @@ export class ApplicationBuildRunner {
|
|
|
304
379
|
const environment = this.#environment ?? akanConfig.baseDevEnv.env;
|
|
305
380
|
const packageJson = akanConfig.getProductionPackageJson();
|
|
306
381
|
const lockfile = await this.#pruneLockfile(packageJson);
|
|
307
|
-
const
|
|
382
|
+
const env = { ...akanConfig.getProductionEnv(environment), ...this.#secretEnvList() };
|
|
383
|
+
const dockerfile = akanConfig.dockerfileFor(environment, { lockfile: lockfile !== null, env });
|
|
308
384
|
await Promise.all([
|
|
309
385
|
this.#app.dist.writeJson("package.json", packageJson),
|
|
310
|
-
this.#app.dist.writeJson(BUILD_ENV_FILE,
|
|
386
|
+
this.#app.dist.writeJson(BUILD_ENV_FILE, env),
|
|
311
387
|
...(lockfile !== null
|
|
312
388
|
? [this.#app.dist.writeFile(`${this.#app.dist.cwdPath}/${ProductionLockfile.fileName}`, lockfile)]
|
|
313
389
|
: []),
|
|
@@ -320,6 +396,15 @@ export class ApplicationBuildRunner {
|
|
|
320
396
|
]);
|
|
321
397
|
}
|
|
322
398
|
|
|
399
|
+
//? Names and kinds alone: the image carries the list of what its deployment owes, never a value.
|
|
400
|
+
#secretEnvList(): Record<string, string> {
|
|
401
|
+
if (!this.#secrets.variables.length) return {};
|
|
402
|
+
return {
|
|
403
|
+
[SecretEnv.listKey]: SecretEnv.format(this.#secrets.variables),
|
|
404
|
+
...(this.#secretEnv === "inline" ? { [SecretEnv.fallbackKey]: "image" } : {}),
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
|
|
323
408
|
async #pruneLockfile(packageJson: PackageJson): Promise<string | null> {
|
|
324
409
|
try {
|
|
325
410
|
return await ProductionLockfile.prune(this.#app.workspace.workspaceRoot, packageJson);
|
|
@@ -355,6 +440,7 @@ export class ApplicationBuildRunner {
|
|
|
355
440
|
environment: this.#environment ?? baseEnv,
|
|
356
441
|
environments: ["local", "testing", ...branches],
|
|
357
442
|
profile: this.#profile,
|
|
443
|
+
secrets: this.#secretEnv,
|
|
358
444
|
onLibEnv: (file, { profileFile, stripped }) => {
|
|
359
445
|
if (profileFile || !stripped.length || this.#warnedLibEnvs.has(file)) return;
|
|
360
446
|
this.#warnedLibEnvs.add(file);
|
|
@@ -370,7 +456,8 @@ export class ApplicationBuildRunner {
|
|
|
370
456
|
//? `bun main.js` in dist/apps/<app> is a documented way to run a build, and a verify output has no CSR bundle or
|
|
371
457
|
//? production env file, so its main.js refuses to boot before any app module runs.
|
|
372
458
|
#verifyBanner() {
|
|
373
|
-
const
|
|
459
|
+
const { name, dist, workspace } = this.#app;
|
|
460
|
+
const message = `${path.relative(workspace.workspaceRoot, dist.cwdPath)} holds the partial output of akan verify, not a build. Run \`akan build ${name}\` and start dist/apps/${name}.`;
|
|
374
461
|
return `console.error(${JSON.stringify(message)});process.exit(1);`;
|
|
375
462
|
}
|
|
376
463
|
|
|
@@ -282,7 +282,10 @@ describe("The generated System root layout, built and rendered", () => {
|
|
|
282
282
|
"(bare)/bar.tsx": pageSource,
|
|
283
283
|
};
|
|
284
284
|
await withBuiltPages({ routes, unbounded: "(bare)" }, async (render) => {
|
|
285
|
-
const beforeScripts = (html: string) =>
|
|
285
|
+
const beforeScripts = (html: string) => {
|
|
286
|
+
const body = html.indexOf("<body>");
|
|
287
|
+
return html.slice(body, html.indexOf("<script", body));
|
|
288
|
+
};
|
|
286
289
|
const bounded = await render("ids");
|
|
287
290
|
const bare = beforeScripts((await render("bar")).html);
|
|
288
291
|
expect(beforeScripts(bounded.html)).toContain('<section id="user"><b id="_R_');
|
|
@@ -70,6 +70,15 @@ export interface CodeAgentOptions {
|
|
|
70
70
|
resume?: string;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
const textOf = (content: unknown) => {
|
|
74
|
+
if (typeof content === "string") return content.trim();
|
|
75
|
+
if (!Array.isArray(content)) return "";
|
|
76
|
+
return content
|
|
77
|
+
.map((part) => (typeof part === "object" && part && "text" in part ? String(part.text) : ""))
|
|
78
|
+
.join("")
|
|
79
|
+
.trim();
|
|
80
|
+
};
|
|
81
|
+
|
|
73
82
|
export class CodeAgent {
|
|
74
83
|
readonly #profile: CodeAgentProfile;
|
|
75
84
|
readonly #gate: CodeAgentGate;
|
|
@@ -171,6 +180,10 @@ export class CodeAgent {
|
|
|
171
180
|
return this.#profile;
|
|
172
181
|
}
|
|
173
182
|
|
|
183
|
+
get allowed() {
|
|
184
|
+
return this.#gate.allowed;
|
|
185
|
+
}
|
|
186
|
+
|
|
174
187
|
get canSeeImages() {
|
|
175
188
|
const model = this.#session?.model;
|
|
176
189
|
return model ? akanCodeModelSupportsImages(model) : false;
|
|
@@ -269,21 +282,12 @@ export class CodeAgent {
|
|
|
269
282
|
const turnId = `restored:${session.sessionId}`;
|
|
270
283
|
for (const message of session.messages) {
|
|
271
284
|
if (message.role !== "user" && message.role !== "assistant") continue;
|
|
272
|
-
const text =
|
|
285
|
+
const text = textOf(message.content);
|
|
273
286
|
if (text) this.#emit({ type: "message", turnId, role: message.role, text });
|
|
274
287
|
}
|
|
275
288
|
this.#emitContextNow();
|
|
276
289
|
}
|
|
277
290
|
|
|
278
|
-
static #textOf(content: unknown) {
|
|
279
|
-
if (typeof content === "string") return content.trim();
|
|
280
|
-
if (!Array.isArray(content)) return "";
|
|
281
|
-
return content
|
|
282
|
-
.map((part) => (typeof part === "object" && part && "text" in part ? String(part.text) : ""))
|
|
283
|
-
.join("")
|
|
284
|
-
.trim();
|
|
285
|
-
}
|
|
286
|
-
|
|
287
291
|
on(listener: (event: CodeAgentEvent) => void) {
|
|
288
292
|
this.#listeners.add(listener);
|
|
289
293
|
return () => this.#listeners.delete(listener);
|
|
@@ -339,9 +343,13 @@ export class CodeAgent {
|
|
|
339
343
|
return true;
|
|
340
344
|
}
|
|
341
345
|
|
|
342
|
-
async approve(approvalId: string, approved: boolean) {
|
|
346
|
+
async approve(approvalId: string, approved: boolean, remember?: "session") {
|
|
343
347
|
if (this.#asks.resolveApproval(approvalId, approved)) {
|
|
344
|
-
|
|
348
|
+
const remembered = this.allowed.settle(approvalId, approved && remember === "session");
|
|
349
|
+
this.#emit({ type: "approval_resolved", approvalId, approved, ...(remembered.length ? { remembered } : {}) });
|
|
350
|
+
for (const covered of this.allowed.covered())
|
|
351
|
+
if (this.#asks.resolveApproval(covered, true))
|
|
352
|
+
this.#emit({ type: "approval_resolved", approvalId: covered, approved: true });
|
|
345
353
|
return true;
|
|
346
354
|
}
|
|
347
355
|
if (this.#profile.interaction.approval !== "suspend") return false;
|
|
@@ -542,7 +550,12 @@ export class CodeAgent {
|
|
|
542
550
|
event.input,
|
|
543
551
|
"This reaches a host outside the profile's list, which needs the user's approval, and nobody can be asked in this session. Use a listed host, or say what you need fetched.",
|
|
544
552
|
);
|
|
545
|
-
const approved = await this.#requestApproval(
|
|
553
|
+
const approved = await this.#requestApproval(
|
|
554
|
+
event.toolCallId,
|
|
555
|
+
event.toolName,
|
|
556
|
+
verdict.approval,
|
|
557
|
+
verdict.remember,
|
|
558
|
+
);
|
|
546
559
|
if (approved) return undefined;
|
|
547
560
|
return this.#refuse(event.toolCallId, event.toolName, event.input, "The user declined this action.");
|
|
548
561
|
});
|
|
@@ -555,24 +568,31 @@ export class CodeAgent {
|
|
|
555
568
|
return { block: true, reason };
|
|
556
569
|
}
|
|
557
570
|
|
|
558
|
-
async #requestApproval(toolCallId: string, name: string,
|
|
571
|
+
async #requestApproval(toolCallId: string, name: string, summary: string, offered?: string[]) {
|
|
559
572
|
// Nobody to ask means nobody to refuse: a pod would otherwise deny every write it was created to make.
|
|
560
573
|
if (!this.#profile.ui.canPrompt) return true;
|
|
561
574
|
const approvalId = this.#asks.nextId("a");
|
|
575
|
+
const suspends = this.#profile.interaction.approval === "suspend";
|
|
576
|
+
// A suspended approval ends its turn, and the retry is a new call, so there is no session answer to offer.
|
|
577
|
+
const remember = suspends ? undefined : offered;
|
|
562
578
|
const request = {
|
|
563
579
|
approvalId,
|
|
564
580
|
toolCallId,
|
|
565
581
|
name,
|
|
566
582
|
summary: codeAgentClip(summary, codeAgentLabelChars),
|
|
567
583
|
policy: this.#profile.approval,
|
|
584
|
+
...(remember ? { remember } : {}),
|
|
568
585
|
};
|
|
569
586
|
this.#emit({ type: "approval", request });
|
|
570
|
-
if (
|
|
587
|
+
if (suspends) {
|
|
571
588
|
this.#suspended.addApproval(request);
|
|
572
589
|
this.#mapper.noteOutcome("awaiting");
|
|
573
590
|
return false;
|
|
574
591
|
}
|
|
575
|
-
|
|
592
|
+
if (remember) this.allowed.offer(approvalId, remember);
|
|
593
|
+
const approved = await this.#asks.openApproval(approvalId);
|
|
594
|
+
this.allowed.settle(approvalId, false);
|
|
595
|
+
return approved;
|
|
576
596
|
}
|
|
577
597
|
|
|
578
598
|
/** The rendered answer; `undefined` when skipped, suspended, or nobody can be prompted. */
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Kept in this process only: a resumed or reloaded session starts with nothing allowed.
|
|
2
|
+
export class CodeAgentAllowed {
|
|
3
|
+
readonly #names = new Set<string>();
|
|
4
|
+
readonly #offers = new Map<string, string[]>();
|
|
5
|
+
|
|
6
|
+
get names() {
|
|
7
|
+
return [...this.#names].sort();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
missing(names: string[]) {
|
|
11
|
+
return names.filter((name) => !this.#names.has(name));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
offer(approvalId: string, names: string[]) {
|
|
15
|
+
this.#offers.set(approvalId, names);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
settle(approvalId: string, remember: boolean) {
|
|
19
|
+
const names = this.#offers.get(approvalId) ?? [];
|
|
20
|
+
this.#offers.delete(approvalId);
|
|
21
|
+
if (!remember) return [];
|
|
22
|
+
for (const name of names) this.#names.add(name);
|
|
23
|
+
return names;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
covered() {
|
|
27
|
+
return [...this.#offers].filter(([, names]) => !this.missing(names).length).map(([approvalId]) => approvalId);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
clear() {
|
|
31
|
+
const count = this.#names.size;
|
|
32
|
+
this.#names.clear();
|
|
33
|
+
return count;
|
|
34
|
+
}
|
|
35
|
+
}
|