@astrosheep/keiyaku 4.6.19 → 4.6.20

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 (102) hide show
  1. package/README.md +7 -3
  2. package/build/plugins/pi/README.md +111 -0
  3. package/build/plugins/pi/akuma-tools.ts +310 -0
  4. package/build/plugins/pi/keiyaku.ts +2 -0
  5. package/build/src/akuma/akuma-call.d.ts +4 -1
  6. package/build/src/akuma/akuma-call.js +24 -7
  7. package/build/src/akuma/akuma-instance.d.ts +28 -8
  8. package/build/src/akuma/akuma-instance.js +85 -42
  9. package/build/src/akuma/akuma-owner.d.ts +18 -9
  10. package/build/src/akuma/akuma-owner.js +31 -25
  11. package/build/src/akuma/akuma-selection-execution.d.ts +4 -1
  12. package/build/src/akuma/akuma-selection-execution.js +8 -4
  13. package/build/src/akuma/akuma.d.ts +17 -0
  14. package/build/src/akuma/body-launch.d.ts +107 -0
  15. package/build/src/akuma/body-launch.js +57 -0
  16. package/build/src/akuma/body-supervisor.d.ts +7 -6
  17. package/build/src/akuma/body-supervisor.js +17 -12
  18. package/build/src/akuma/body.d.ts +13 -94
  19. package/build/src/akuma/body.js +124 -296
  20. package/build/src/akuma/call-input.d.ts +2 -0
  21. package/build/src/akuma/call-input.js +21 -1
  22. package/build/src/akuma/call-request.d.ts +6 -2
  23. package/build/src/akuma/call-request.js +9 -1
  24. package/build/src/akuma/detached-body.d.ts +9 -0
  25. package/build/src/akuma/detached-body.js +94 -0
  26. package/build/src/akuma/execution-instructions.d.ts +8 -0
  27. package/build/src/akuma/execution-instructions.js +17 -0
  28. package/build/src/akuma/heart/facts.d.ts +21 -1
  29. package/build/src/akuma/heart/facts.js +10 -0
  30. package/build/src/akuma/heart/index.d.ts +16 -1
  31. package/build/src/akuma/heart/index.js +95 -30
  32. package/build/src/akuma/heart/rows.d.ts +14 -2
  33. package/build/src/akuma/heart/rows.js +48 -4
  34. package/build/src/akuma/heart/schema.d.ts +4 -1
  35. package/build/src/akuma/heart/schema.js +87 -30
  36. package/build/src/akuma/heart/soul.js +4 -0
  37. package/build/src/akuma/heart/storage.d.ts +1 -0
  38. package/build/src/akuma/heart/storage.js +59 -15
  39. package/build/src/akuma/heart/timeline.d.ts +6 -4
  40. package/build/src/akuma/heart/timeline.js +14 -4
  41. package/build/src/akuma/in-process-body.d.ts +5 -0
  42. package/build/src/akuma/in-process-body.js +57 -0
  43. package/build/src/akuma/index.d.ts +1 -1
  44. package/build/src/akuma/projection.d.ts +44 -1
  45. package/build/src/akuma/projection.js +13 -1
  46. package/build/src/akuma/provider.d.ts +4 -0
  47. package/build/src/akuma/providers/acp/core.js +1 -1
  48. package/build/src/akuma/providers/acp/index.js +3 -0
  49. package/build/src/akuma/providers/claude/index.js +8 -5
  50. package/build/src/akuma/providers/codex-app-server/configuration.d.ts +5 -0
  51. package/build/src/akuma/providers/codex-app-server/configuration.js +72 -0
  52. package/build/src/akuma/providers/codex-app-server/index.js +7 -10
  53. package/build/src/akuma/providers/execution-environment.d.ts +8 -2
  54. package/build/src/akuma/providers/execution-environment.js +10 -1
  55. package/build/src/akuma/providers/grok-build/index.js +23 -16
  56. package/build/src/akuma/providers/index.d.ts +1 -0
  57. package/build/src/akuma/providers/index.js +8 -0
  58. package/build/src/akuma/providers/opencode-sdk/index.js +9 -0
  59. package/build/src/akuma/providers/opencode-sdk/session.d.ts +6 -0
  60. package/build/src/akuma/providers/opencode-sdk/session.js +4 -3
  61. package/build/src/akuma/providers/paseo/index.js +8 -2
  62. package/build/src/akuma/providers/pi/index.js +27 -10
  63. package/build/src/akuma/publication.d.ts +4 -3
  64. package/build/src/akuma/publication.js +21 -18
  65. package/build/src/akuma/selection-observation.d.ts +51 -0
  66. package/build/src/akuma/selection-owner-port.d.ts +2 -1
  67. package/build/src/akuma/selection-owner-port.js +4 -3
  68. package/build/src/akuma/turn-drive.d.ts +4 -2
  69. package/build/src/akuma/turn-drive.js +58 -21
  70. package/build/src/akuma-body.d.ts +0 -10
  71. package/build/src/akuma-body.js +13 -118
  72. package/build/src/body-host.d.ts +28 -0
  73. package/build/src/body-host.js +86 -0
  74. package/build/src/body-requests.d.ts +13 -0
  75. package/build/src/body-requests.js +131 -0
  76. package/build/src/cli/commands/akuma-grammar.d.ts +8 -1
  77. package/build/src/cli/commands/akuma-grammar.js +36 -6
  78. package/build/src/cli/commands/akuma.js +11 -0
  79. package/build/src/cli/commands/report.d.ts +6 -0
  80. package/build/src/cli/commands/report.js +31 -0
  81. package/build/src/cli/parse.js +1 -0
  82. package/build/src/cli/render/akuma-activity.js +27 -17
  83. package/build/src/cli/render/terminal.d.ts +5 -0
  84. package/build/src/cli/render/terminal.js +7 -0
  85. package/build/src/cli/runtime.js +4 -1
  86. package/build/src/index.d.ts +3 -1
  87. package/build/src/index.js +1 -0
  88. package/build/src/library/akuma-creation.d.ts +7 -3
  89. package/build/src/library/akuma-creation.js +23 -11
  90. package/build/src/library/akumas.d.ts +4 -1
  91. package/build/src/library/akumas.js +13 -5
  92. package/build/src/library/selection.d.ts +2 -1
  93. package/build/src/library/selection.js +6 -3
  94. package/build/src/plugin/public.d.ts +11 -0
  95. package/build/src/plugin/runtime.js +1 -0
  96. package/build/src/runtime/proc/windows-launch.exe +0 -0
  97. package/package.json +2 -2
  98. package/plugins/paseo/plugin/server/keiyaku.ts +1 -0
  99. package/plugins/paseo/plugin/server/mirror.ts +2 -2
  100. package/plugins/pi/README.md +111 -0
  101. package/plugins/pi/akuma-tools.ts +310 -0
  102. package/plugins/pi/keiyaku.ts +2 -0
@@ -0,0 +1,57 @@
1
+ import { z } from "zod";
2
+ import { abortable, abortableDelay } from "./abort.js";
3
+ import { decodeSoulSeed } from "./heart/soul.js";
4
+ import { sessionAdmissionSchema } from "./heart/rows.js";
5
+ import { akumaPathsSchema } from "./identity.js";
6
+ const launchSeedSchema = z.unknown().transform((value, context) => {
7
+ try {
8
+ return decodeSoulSeed(value);
9
+ }
10
+ catch {
11
+ context.addIssue({ code: "custom", message: "invalid Body birth seed" });
12
+ return z.NEVER;
13
+ }
14
+ });
15
+ export const bodyLaunchSchema = z
16
+ .object({
17
+ paths: akumaPathsSchema,
18
+ seed: launchSeedSchema.optional(),
19
+ birthSession: sessionAdmissionSchema.optional(),
20
+ initialBody: z.string().optional(),
21
+ initiator: z.string().optional(),
22
+ birthInitiator: z.string().optional(),
23
+ initialSchemaJson: z.string().optional(),
24
+ refuseIfHeld: z.boolean().optional(),
25
+ handoffFromBodySequence: z.number().int().positive().optional(),
26
+ completion: z.object({ contractId: z.string().optional() }).strict().optional(),
27
+ })
28
+ .strict();
29
+ /** Observe durable custody first, including once more after live launch completion. */
30
+ export async function observeBodyLaunch(child, observe, schedule = abortableDelay, signal) {
31
+ for (;;) {
32
+ signal?.throwIfAborted();
33
+ const value = await observe();
34
+ if (value !== null)
35
+ return { kind: "observed", value };
36
+ const controller = new AbortController();
37
+ const timer = schedule(100, controller.signal).then(() => ({ kind: "timer" }));
38
+ let winner;
39
+ try {
40
+ const waited = Promise.race([child.completed.then((end) => ({ kind: "completed", end })), timer]);
41
+ winner = signal === undefined ? await waited : await abortable(waited, signal);
42
+ }
43
+ finally {
44
+ controller.abort();
45
+ await timer.catch(() => undefined);
46
+ }
47
+ if (winner.kind === "timer")
48
+ continue;
49
+ const final = await observe();
50
+ return final === null ? winner : { kind: "observed", value: final };
51
+ }
52
+ }
53
+ export function launchEndWake(end) {
54
+ return end.held
55
+ ? { kind: "held" }
56
+ : { kind: "failed", diagnostic: end.diagnostic, ...(end.child === undefined ? {} : { child: end.child }) };
57
+ }
@@ -2,10 +2,10 @@ import { type BodyControlSnapshot, type HeldAkumaLeash } from "./heart/index.js"
2
2
  import type { AkumaPaths } from "./identity.js";
3
3
  export declare const CONTROL_RESPONSE_MS = 1000;
4
4
  export declare class BodySupervisor {
5
- private readonly paths;
6
- private readonly bodySequence;
7
- private readonly leash;
5
+ private readonly body;
8
6
  private readonly reader;
7
+ private readonly launchSignal?;
8
+ readonly forceSignal?: AbortSignal | undefined;
9
9
  readonly signal: AbortSignal;
10
10
  private readonly controller;
11
11
  private readonly finished;
@@ -13,14 +13,15 @@ export declare class BodySupervisor {
13
13
  private waiter;
14
14
  private observation;
15
15
  private stopping?;
16
+ private readonly cancelLaunch;
16
17
  private constructor();
17
- static open(paths: AkumaPaths, bodySequence: number, leash: HeldAkumaLeash): Promise<BodySupervisor>;
18
- get reason(): "control" | "heart-gone" | undefined;
18
+ static open(paths: AkumaPaths, bodySequence: number, leash: HeldAkumaLeash, signal?: AbortSignal, forceSignal?: AbortSignal): Promise<BodySupervisor>;
19
+ get reason(): "control" | "heart-gone" | "launch" | undefined;
19
20
  current(): BodyControlSnapshot;
20
21
  recordHung(diagnostic: string, at: string): Promise<void>;
21
22
  refresh(): Promise<BodyControlSnapshot>;
22
23
  next(after: BodyControlSnapshot): Promise<BodyControlSnapshot>;
23
- cancel(reason: "control" | "heart-gone"): void;
24
+ cancel(reason: "control" | "heart-gone" | "launch"): void;
24
25
  close(): Promise<void>;
25
26
  private observe;
26
27
  }
@@ -4,10 +4,10 @@ import { createBodyHeartReader } from "./heart/index.js";
4
4
  const BODY_CONTROL_OBSERVATION_MS = 100;
5
5
  export const CONTROL_RESPONSE_MS = 1_000;
6
6
  export class BodySupervisor {
7
- paths;
8
- bodySequence;
9
- leash;
7
+ body;
10
8
  reader;
9
+ launchSignal;
10
+ forceSignal;
11
11
  signal;
12
12
  controller = new AbortController();
13
13
  finished = new AbortController();
@@ -15,18 +15,22 @@ export class BodySupervisor {
15
15
  waiter;
16
16
  observation;
17
17
  stopping;
18
- constructor(paths, bodySequence, leash, reader, observation) {
19
- this.paths = paths;
20
- this.bodySequence = bodySequence;
21
- this.leash = leash;
18
+ cancelLaunch = () => this.cancel("launch");
19
+ constructor(body, reader, observation, launchSignal, forceSignal) {
20
+ this.body = body;
22
21
  this.reader = reader;
22
+ this.launchSignal = launchSignal;
23
+ this.forceSignal = forceSignal;
23
24
  this.signal = this.controller.signal;
24
25
  this.observation = observation;
26
+ launchSignal?.addEventListener("abort", this.cancelLaunch, { once: true });
27
+ if (launchSignal?.aborted)
28
+ this.cancelLaunch();
25
29
  this.observer = this.observe();
26
30
  }
27
- static async open(paths, bodySequence, leash) {
31
+ static async open(paths, bodySequence, leash, signal, forceSignal) {
28
32
  const reader = createBodyHeartReader(paths);
29
- return new BodySupervisor(paths, bodySequence, leash, reader, await reader.read());
33
+ return new BodySupervisor({ paths, sequence: bodySequence, leash }, reader, await reader.read(), signal, forceSignal);
30
34
  }
31
35
  get reason() {
32
36
  return this.stopping;
@@ -35,7 +39,7 @@ export class BodySupervisor {
35
39
  return this.observation;
36
40
  }
37
41
  async recordHung(diagnostic, at) {
38
- await this.leash.recordBodyHung(this.paths, { sequence: this.bodySequence, diagnostic, at });
42
+ await this.body.leash.recordBodyHung(this.body.paths, { sequence: this.body.sequence, diagnostic, at });
39
43
  }
40
44
  async refresh() {
41
45
  const snapshot = await this.reader.read();
@@ -57,12 +61,13 @@ export class BodySupervisor {
57
61
  if (this.stopping !== undefined)
58
62
  return;
59
63
  this.stopping = reason;
60
- this.controller.abort(new Error(reason === "control" ? "Akuma Body interrupted by durable control" : "Akuma Heart disappeared"));
64
+ this.controller.abort(new Error(reason === "heart-gone" ? "Akuma Heart disappeared" : "Akuma Body interrupted"));
61
65
  this.waiter?.(this.observation);
62
66
  this.waiter = undefined;
63
67
  }
64
68
  async close() {
65
69
  this.finished.abort();
70
+ this.launchSignal?.removeEventListener("abort", this.cancelLaunch);
66
71
  try {
67
72
  await this.observer;
68
73
  }
@@ -76,7 +81,7 @@ export class BodySupervisor {
76
81
  const snapshot = this.observation;
77
82
  if (snapshot.soul === null)
78
83
  return this.cancel("heart-gone");
79
- if (snapshot.stop?.bodySequence === this.bodySequence || snapshot.pause?.bodySequence === this.bodySequence) {
84
+ if (snapshot.stop?.bodySequence === this.body.sequence || snapshot.pause?.bodySequence === this.body.sequence) {
80
85
  return this.cancel("control");
81
86
  }
82
87
  try {
@@ -1,109 +1,28 @@
1
- import { z } from "zod";
2
- import type { AkumaCallRequestChildLaunch } from "./call-request.js";
3
1
  import { type AkumaPaths } from "./identity.js";
4
2
  import { type TellResult } from "./call-initial-tell.js";
5
3
  export type { TellResult, TellWake } from "./call-initial-tell.js";
6
4
  import { type WorldRoot } from "../world.js";
7
5
  import type { ProviderAdapter } from "./provider.js";
6
+ import type { ExecutionAssociationReader } from "./execution-instructions.js";
8
7
  import type { ErasedRequestCommand } from "./request-wire.js";
9
- import { type OwnedProcess } from "../runtime/proc/run.js";
10
- export declare const LEASH_HELD_EXIT = 75;
8
+ import { type BodyLaunch, type BodyLauncher, type LiveBodyLaunch } from "./body-launch.js";
11
9
  export { CONTROL_RESPONSE_MS } from "./body-supervisor.js";
12
- export declare const bodyLaunchSchema: z.ZodObject<{
13
- paths: z.ZodObject<{
14
- directory: z.ZodString;
15
- heart: z.ZodString;
16
- leash: z.ZodString;
17
- log: z.ZodString;
18
- requests: z.ZodString;
19
- }, z.core.$strict>;
20
- seed: z.ZodOptional<z.ZodPipe<z.ZodUnknown, z.ZodTransform<Omit<Readonly<{
21
- id: import("./identity.js").AkuId;
22
- archetype: string;
23
- description?: string;
24
- provider: import("./provider-recipe.js").ProviderExecution;
25
- options: import("./provider-recipe.js").ProviderOptions;
26
- cwd: string;
27
- origin: import("./heart/facts.js").AkumaOrigin;
28
- caller?: import("./caller.js").AkumaCaller;
29
- allowed: import("./allowed.js").AllowedActions;
30
- createdAt: string;
31
- }>, "createdAt">, unknown>>>;
32
- birthSession: z.ZodOptional<z.ZodObject<{
33
- provider: z.ZodString;
34
- coordinate: z.ZodUnion<readonly [z.ZodPipe<z.ZodObject<{
35
- sessionFile: z.ZodString;
36
- sessionId: z.ZodOptional<z.ZodString>;
37
- }, z.core.$strict>, z.ZodTransform<{
38
- sessionFile: string;
39
- sessionId?: never;
40
- } | {
41
- sessionFile: string;
42
- sessionId: string;
43
- }, {
44
- sessionFile: string;
45
- sessionId?: string | undefined;
46
- }>>, z.ZodObject<{
47
- sessionId: z.ZodString;
48
- }, z.core.$strict>]>;
49
- cwd: z.ZodString;
50
- options: z.ZodPipe<z.ZodObject<{
51
- model: z.ZodOptional<z.ZodString>;
52
- effort: z.ZodOptional<z.ZodString>;
53
- network: z.ZodOptional<z.ZodEnum<{
54
- disabled: "disabled";
55
- enabled: "enabled";
56
- }>>;
57
- systemPrompt: z.ZodOptional<z.ZodString>;
58
- systemPromptMode: z.ZodOptional<z.ZodEnum<{
59
- replace: "replace";
60
- append: "append";
61
- }>>;
62
- }, z.core.$strip>, z.ZodTransform<Readonly<{
63
- systemPromptMode?: "replace" | "append";
64
- systemPrompt?: string;
65
- network?: "disabled" | "enabled";
66
- effort?: string;
67
- model?: string;
68
- }>, {
69
- model?: string | undefined;
70
- effort?: string | undefined;
71
- network?: "disabled" | "enabled" | undefined;
72
- systemPrompt?: string | undefined;
73
- systemPromptMode?: "replace" | "append" | undefined;
74
- }>>;
75
- admittedAt: z.ZodString;
76
- }, z.core.$strict>>;
77
- initialBody: z.ZodOptional<z.ZodString>;
78
- initiator: z.ZodOptional<z.ZodString>;
79
- birthInitiator: z.ZodOptional<z.ZodString>;
80
- initialSchemaJson: z.ZodOptional<z.ZodString>;
81
- refuseIfHeld: z.ZodOptional<z.ZodBoolean>;
82
- completion: z.ZodOptional<z.ZodObject<{
83
- contractId: z.ZodOptional<z.ZodString>;
84
- }, z.core.$strict>>;
85
- }, z.core.$strict>;
86
- export type BodyLaunch = z.infer<typeof bodyLaunchSchema>;
87
10
  export type TellWakeRuntime = Readonly<{
88
- spawn(paths: AkumaPaths): Promise<OwnedProcess>;
11
+ spawn(paths: AkumaPaths): Promise<LiveBodyLaunch>;
89
12
  schedule?(milliseconds: number, signal: AbortSignal): Promise<void>;
90
13
  }>;
91
- type BodyRuntime = Readonly<{
14
+ export type BodyRuntime = Readonly<{
92
15
  now(): string;
93
- spawnChild?(launch: AkumaCallRequestChildLaunch): Promise<OwnedProcess>;
94
- spawnBody?(launch: BodyLaunch): Promise<OwnedProcess>;
16
+ spawn: BodyLauncher;
17
+ requestSpawn: BodyLauncher;
18
+ signal?: AbortSignal;
19
+ forceSignal?: AbortSignal;
95
20
  world: WorldRoot;
96
21
  externalCommands: Readonly<Record<string, ErasedRequestCommand>>;
22
+ executionAssociation?: ExecutionAssociationReader;
97
23
  }>;
24
+ export declare function tellWakeRuntime(spawn: BodyLauncher): TellWakeRuntime;
98
25
  export declare function recordPluginDiagnostic(paths: AkumaPaths, occurrence: string, error: unknown): Promise<void>;
99
- export declare function bodyProcessInput(launch: BodyLaunch, bodyModuleUrl?: string): Promise<{
100
- argv: string[];
101
- cwd: string;
102
- env: Record<string, string>;
103
- log: string;
104
- }>;
105
- export declare function handoffPendingTells(paths: AkumaPaths, spawn?: (launch: BodyLaunch) => Promise<OwnedProcess>): Promise<void>;
106
- export declare function driveAkumaBody(launch: BodyLaunch, adapter?: ProviderAdapter, runtimeInput?: Partial<BodyRuntime>): Promise<"held" | void>;
107
- export declare function spawnAkumaBody(launch: BodyLaunch): Promise<OwnedProcess>;
108
- export declare function runAkumaBody(launch: BodyLaunch, world: WorldRoot, externalCommands: Readonly<Record<string, ErasedRequestCommand>>): Promise<"held" | void>;
109
- export declare function wakeRecordedTell(paths: AkumaPaths, tellId: string, runtime?: TellWakeRuntime, signal?: AbortSignal): Promise<TellResult>;
26
+ export declare function handoffPendingTells(paths: AkumaPaths, spawn: BodyLauncher): Promise<void>;
27
+ export declare function driveAkumaBody(launch: BodyLaunch, adapter: ProviderAdapter | undefined, runtimeInput: Pick<BodyRuntime, "spawn" | "requestSpawn"> & Partial<Omit<BodyRuntime, "spawn" | "requestSpawn">>): Promise<"held" | "hung" | void>;
28
+ export declare function wakeRecordedTell(paths: AkumaPaths, tellId: string, runtime: TellWakeRuntime, signal?: AbortSignal): Promise<TellResult>;