@brainervirus/workit-pi 5.0.0 → 6.0.1

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 (4) hide show
  1. package/README.md +18 -23
  2. package/dist/worker.js +69 -312
  3. package/dist/workit.js +3047 -8940
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -1,26 +1,21 @@
1
1
  # @brainervirus/workit-pi
2
2
 
3
3
  [![CI](https://github.com/BrainerVirus/workit/actions/workflows/ci.yml/badge.svg)](https://github.com/BrainerVirus/workit/actions/workflows/ci.yml)
4
- [![license: MIT](https://img.shields.io/badge/license-MIT-green.svg)](../../LICENSE)
5
-
6
- Workit native extension for Pi (stock 0.85.1 package contract) — eight core-backed operation tools, eleven method skills, session/compaction continuity, and a coordinator that supervises fresh reviewer/investigator processes plus explicitly scoped implementers.
7
-
8
- ## Requirements
9
-
10
- - **Node.js ≥ 24**
11
- - **Pi coding agent 0.85.1** (peer dependency)
12
-
13
- ## Install
14
-
15
- Install this package alongside the Pi peer dependency. Pi discovers the
16
- extension and skills through the `pi` manifest section in `package.json`
17
- (`./dist/workit.js` plus `./skills`); see the Pi documentation for how it
18
- resolves extension packages in your setup.
19
-
20
- ## Notes
21
-
22
- - Only an observed child process may acquire the shared writer; cancellation or restart uncertainty blocks replacement ownership.
23
- - The extension is a workflow control, not an OS sandbox: a supported literal
24
- branch-creation command is checked against workspace naming policy; other
25
- shell forms stay under the host's native permission rules.
26
- - Approval uses native `ctx.ui.confirm`, or `needs_input` when headless.
4
+ [![license: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/BrainerVirus/workit/blob/main/LICENSE)
5
+
6
+ [Workit](https://github.com/BrainerVirus/workit) for Pi (stock 0.85.1): a native extension with the
7
+ seven task families plus read-only `workit_context`, the eleven method
8
+ skills, session and compaction continuity, and a coordinator that launches
9
+ fresh reviewer/investigator processes and scoped implementers. Requires
10
+ Node.js 24+.
11
+
12
+ ```bash
13
+ pi install npm:@brainervirus/workit-pi
14
+ pi install ./packages/workit-pi -l --approve # local checkout
15
+ ```
16
+
17
+ Pi discovers the extension and skills from the package's `pi` manifest
18
+ (`./dist/workit.js`, `./skills`). Pi project trust still gates mutations;
19
+ shell writes are agent-guided, since an extension is not an OS sandbox.
20
+ Delivery limits come from Pi's permissions plus the workspace
21
+ [grants](https://github.com/BrainerVirus/workit/blob/main/docs/guides/grants.md).
package/dist/worker.js CHANGED
@@ -7516,7 +7516,6 @@ var OPERATION_FAMILIES = [
7516
7516
  "finding",
7517
7517
  "decision",
7518
7518
  "worker",
7519
- "writer",
7520
7519
  "state"
7521
7520
  ];
7522
7521
  var uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
@@ -7599,20 +7598,13 @@ var refSchema = discriminatedUnion("kind", [
7599
7598
  id
7600
7599
  }).strict(),
7601
7600
  object({ kind: literal("host"), host: hostSchema, handle: nonEmpty }).strict(),
7602
- object({ kind: literal("external"), url: text.url() }).strict(),
7603
- object({
7604
- kind: literal("standing"),
7605
- workspace: nonEmpty,
7606
- class: nonEmpty,
7607
- configDigest: nullableDigest
7608
- }).strict()
7601
+ object({ kind: literal("external"), url: text.url() }).strict()
7609
7602
  ]);
7610
7603
  var provenanceSchema = object({
7611
7604
  kind: _enum(["host_observed", "agent_reported", "imported"]),
7612
7605
  host: hostSchema,
7613
7606
  session: refSchema.nullable(),
7614
- workerId: nullableId,
7615
- receipts: array(refSchema)
7607
+ workerId: nullableId
7616
7608
  }).strict();
7617
7609
  var entrySchema = (data) => object({ id, recordedAt: utc, provenance: provenanceSchema, data }).strict();
7618
7610
  var factSchema = object({
@@ -7855,22 +7847,13 @@ var decisionSchema = object({
7855
7847
  workspaceId: id,
7856
7848
  scope: scopeSchema,
7857
7849
  presented: text,
7858
- approvedContent: text,
7859
- displayed: text.optional(),
7860
7850
  contentRefs: array(refSchema),
7861
- statedChoice: object({ ref: text, text }).strict().optional(),
7862
- standing: object({ workspace: nonEmpty, class: nonEmpty }).strict().optional()
7851
+ statedChoice: object({ ref: text, text }).strict().optional()
7863
7852
  }).strict(),
7864
7853
  digest,
7865
7854
  response: _enum(["approved", "rejected", "stated"]),
7866
7855
  requirementIds: array(digest),
7867
- revoked: object({ at: utc, reason: text }).strict().nullable(),
7868
- consumption: object({
7869
- state: _enum(["reserved", "consumed", "uncertain"]),
7870
- at: utc,
7871
- actionRef: refSchema,
7872
- historicalActionId: text.optional()
7873
- }).strict().nullable()
7856
+ revoked: object({ at: utc, reason: text }).strict().nullable()
7874
7857
  }).strict();
7875
7858
  var findingSchema = object({
7876
7859
  claim: text,
@@ -7903,11 +7886,6 @@ var workerSchema = object({
7903
7886
  coordinator: refSchema.optional(),
7904
7887
  report: workerReportSchema.nullable()
7905
7888
  }).strict();
7906
- var ownerSchema = object({
7907
- taskId: id,
7908
- workerId: nullableId,
7909
- session: object({ kind: literal("host"), host: hostSchema, handle: nonEmpty }).strict()
7910
- }).strict();
7911
7889
  var closureSchema = object({
7912
7890
  outcome: outcomeSchema,
7913
7891
  at: utc,
@@ -7915,30 +7893,6 @@ var closureSchema = object({
7915
7893
  decisionIds: array(id),
7916
7894
  evidenceIds: array(id)
7917
7895
  }).strict();
7918
- var actionProgressSchema = object({
7919
- decisionId: id,
7920
- steps: array(nonEmpty),
7921
- completedSteps: array(nonEmpty)
7922
- }).strict().check((ctx) => {
7923
- const { steps, completedSteps } = ctx.value;
7924
- const valid = new Set(steps).size === steps.length && new Set(completedSteps).size === completedSteps.length && completedSteps.every((step, index) => steps[index] === step);
7925
- if (!valid)
7926
- ctx.issues.push({
7927
- code: "custom",
7928
- input: ctx.value,
7929
- message: "completed action steps must be a unique prefix of approved steps",
7930
- path: ["completedSteps"]
7931
- });
7932
- });
7933
- var actionProgressListSchema = array(actionProgressSchema).check((ctx) => {
7934
- if (new Set(ctx.value.map((progress) => progress.decisionId)).size !== ctx.value.length)
7935
- ctx.issues.push({
7936
- code: "custom",
7937
- input: ctx.value,
7938
- message: "action progress decision ids must be unique",
7939
- path: ["decisionId"]
7940
- });
7941
- });
7942
7896
  var runtimeSchema = object({
7943
7897
  createdWith: text.nullable(),
7944
7898
  updatedWith: text
@@ -7964,7 +7918,6 @@ var taskRecordSchema = object({
7964
7918
  candidates: array(candidateSchema),
7965
7919
  evidence: array(entrySchema(evidenceSchema)),
7966
7920
  decisions: array(entrySchema(decisionSchema)),
7967
- actionProgress: actionProgressListSchema.optional(),
7968
7921
  findings: array(entrySchema(findingSchema)),
7969
7922
  workers: array(entrySchema(workerSchema)),
7970
7923
  critical: array(nonEmpty).optional()
@@ -7975,7 +7928,6 @@ var workspaceRecordSchema = object({
7975
7928
  revision,
7976
7929
  root: nonEmpty,
7977
7930
  runtime: runtimeSchema.optional(),
7978
- writer: object({ state: _enum(["held", "uncertain"]), owner: ownerSchema, acquiredAt: utc }).strict().nullable(),
7979
7931
  critical: array(nonEmpty).optional()
7980
7932
  }).strict();
7981
7933
  var capabilitySchema = object({
@@ -8011,8 +7963,7 @@ var taskSummarySchema = object({
8011
7963
  closure: closureSchema.nullable(),
8012
7964
  progress: progressSchema,
8013
7965
  policy: policySchema.nullable(),
8014
- requirements: array(requirementEvaluationSchema),
8015
- writer: workspaceRecordSchema.shape.writer
7966
+ requirements: array(requirementEvaluationSchema)
8016
7967
  }).strict();
8017
7968
  var taskListItemSchema = taskSummarySchema.omit({ policy: true, requirements: true }).extend({ source: provenanceSchema.pick({ host: true, kind: true }) }).strict();
8018
7969
  var exportBundleSchema = object({
@@ -8072,8 +8023,7 @@ var taskOperations = {
8072
8023
  action: literal("resume"),
8073
8024
  ...taskId,
8074
8025
  ...revisions,
8075
- expectedWorkspaceRevision: revision.optional(),
8076
- authorityRefs: array(refSchema).optional()
8026
+ expectedWorkspaceRevision: revision.optional()
8077
8027
  }),
8078
8028
  close: operation({
8079
8029
  action: literal("close"),
@@ -8168,30 +8118,12 @@ var workerOperations = {
8168
8118
  reason: text
8169
8119
  })
8170
8120
  };
8171
- var writerOperations = {
8172
- acquire: operation({
8173
- action: literal("acquire"),
8174
- ...taskId,
8175
- expectedRevision: revision.optional(),
8176
- expectedWorkspaceRevision: revision.optional(),
8177
- workerId: nullableId.optional(),
8178
- reason: text.optional()
8179
- }),
8180
- release: operation({
8181
- action: literal("release"),
8182
- ...taskId,
8183
- expectedRevision: revision.optional(),
8184
- expectedWorkspaceRevision: revision.optional(),
8185
- reason: text.optional()
8186
- })
8187
- };
8188
8121
  var stateOperations = {
8189
8122
  export: operation({ action: literal("export"), ...taskId }),
8190
8123
  import: operation({
8191
8124
  action: literal("import"),
8192
8125
  expectedWorkspaceRevision: revision.nullable().optional(),
8193
- bundle: exportBundleSchema,
8194
- authorityRefs: array(refSchema)
8126
+ bundle: exportBundleSchema
8195
8127
  })
8196
8128
  };
8197
8129
  var operationSchemas = {
@@ -8201,7 +8133,6 @@ var operationSchemas = {
8201
8133
  finding: discriminatedUnion("action", Object.values(findingOperations)),
8202
8134
  decision: discriminatedUnion("action", Object.values(decisionOperations)),
8203
8135
  worker: discriminatedUnion("action", Object.values(workerOperations)),
8204
- writer: discriminatedUnion("action", Object.values(writerOperations)),
8205
8136
  state: discriminatedUnion("action", Object.values(stateOperations))
8206
8137
  };
8207
8138
  var withImplicitTask = (options) => Object.values(options).map((option) => ("taskId" in option.shape) ? option.extend({ taskId: id.optional() }) : option);
@@ -8213,7 +8144,6 @@ var advertisedOperationSchemas = {
8213
8144
  finding: advertised(findingOperations),
8214
8145
  decision: advertised(decisionOperations),
8215
8146
  worker: advertised(workerOperations),
8216
- writer: advertised(writerOperations),
8217
8147
  state: advertised(stateOperations)
8218
8148
  };
8219
8149
  var compiledOperationSchemas = Object.fromEntries(OPERATION_FAMILIES.map((family) => [family, compile(operationSchemas[family])]));
@@ -8293,8 +8223,24 @@ function candidateDigest(input) {
8293
8223
  head: input.head
8294
8224
  });
8295
8225
  }
8296
- // packages/workit-core/src/core/task-store.ts
8297
- import { AsyncLocalStorage } from "node:async_hooks";
8226
+ // packages/workit-core/src/core/package-root.ts
8227
+ import { existsSync } from "node:fs";
8228
+ import path from "node:path";
8229
+ import { fileURLToPath } from "node:url";
8230
+ var packageRoot = () => {
8231
+ let dir = path.dirname(fileURLToPath(import.meta.url));
8232
+ while (true) {
8233
+ const parent = path.dirname(dir);
8234
+ if (existsSync(path.join(dir, "package.json")) || parent === dir)
8235
+ return dir;
8236
+ dir = parent;
8237
+ }
8238
+ };
8239
+ var assetRoot = () => {
8240
+ const root = packageRoot();
8241
+ const assets = path.join(root, "assets");
8242
+ return existsSync(assets) ? assets : root;
8243
+ };
8298
8244
 
8299
8245
  // packages/workit-core/src/core/store-lock.ts
8300
8246
  var metadataLockSchema = object({
@@ -8342,11 +8288,10 @@ var SLOT = Symbol.for("workit.migrationReporter");
8342
8288
  var AUTO_COMPACT_BYTES = 2 * 1024 * 1024;
8343
8289
  var TOMBSTONE = Symbol("tombstone");
8344
8290
  var STALE_TEMPORARY_MS = 60 * 60000;
8345
- var externalActionLockRoots = new AsyncLocalStorage;
8346
8291
  var heldInProcess = new Map;
8347
- // packages/workit-core/src/core/workspaces.ts
8348
- import path from "node:path";
8349
-
8292
+ // packages/workit-core/src/git/rev.ts
8293
+ var MAX_BUFFER = 256 * 1024 * 1024;
8294
+ var MAX_UNTRACKED_BYTES = 5 * 1024 * 1024;
8350
8295
  // packages/workit-core/src/core/config.ts
8351
8296
  var PRESETS = {
8352
8297
  gitflow: {
@@ -8377,6 +8322,7 @@ var COMMIT_PRESETS = [
8377
8322
  ];
8378
8323
 
8379
8324
  // packages/workit-core/src/core/workspaces.ts
8325
+ import path2 from "node:path";
8380
8326
  var nonBlank = string2().refine((value) => value.trim().length > 0, "must not be blank");
8381
8327
  var branchPreset = custom((value) => typeof value === "string" && Object.hasOwn(PRESETS, value), "unsupported branch preset");
8382
8328
  var commitPreset = custom((value) => typeof value === "string" && COMMIT_PRESETS.includes(value), "unsupported commit preset");
@@ -8429,7 +8375,7 @@ var releaseTrackSchema = object({
8429
8375
  context.addIssue({ code: "custom", path: [field], message: "entries must be unique" });
8430
8376
  }
8431
8377
  }
8432
- if (track.versionSource.kind === "package-json" && (path.posix.isAbsolute(track.versionSource.path.replaceAll("\\", "/")) || /^[A-Za-z]:\//u.test(track.versionSource.path.replaceAll("\\", "/")) || track.versionSource.path.replaceAll("\\", "/").split("/").includes(".."))) {
8378
+ if (track.versionSource.kind === "package-json" && (path2.posix.isAbsolute(track.versionSource.path.replaceAll("\\", "/")) || /^[A-Za-z]:\//u.test(track.versionSource.path.replaceAll("\\", "/")) || track.versionSource.path.replaceAll("\\", "/").split("/").includes(".."))) {
8433
8379
  context.addIssue({
8434
8380
  code: "custom",
8435
8381
  path: ["versionSource", "path"],
@@ -8447,6 +8393,11 @@ var workspaceConfigSchema = object({
8447
8393
  account: nonBlank.optional()
8448
8394
  }).passthrough().optional(),
8449
8395
  autoApprove: union([boolean2(), array(nonBlank)]).optional(),
8396
+ defaultEndpoint: _enum(["commit", "pr"]).optional(),
8397
+ autonomy: object(Object.fromEntries(["push", "pr", "merge", "release", "rerun"].map((kind) => [
8398
+ kind,
8399
+ union([boolean2(), literal("verified")]).optional()
8400
+ ]))).passthrough().optional(),
8450
8401
  youtrack: object({ baseUrl: nonBlank.optional(), link_issues: boolean2().optional() }).passthrough().optional(),
8451
8402
  issues: object({ provider: literal("github").optional(), link_on_pr: boolean2().optional() }).passthrough().optional(),
8452
8403
  branchPolicy: workspaceBranchPolicySchema.optional(),
@@ -8486,126 +8437,6 @@ var workspacesFileSchema = object({ workspaces: array(workspaceConfigSchema).opt
8486
8437
  var runtimeWorkspaceIndexSchema = object({
8487
8438
  workspaces: array(object({ name: nonBlank, glob: nonBlank }).passthrough()).optional()
8488
8439
  }).passthrough();
8489
-
8490
- // packages/workit-core/src/core/authority.ts
8491
- var verifiedAuthorities = new WeakMap;
8492
-
8493
- // packages/workit-core/src/git/rev.ts
8494
- var MAX_BUFFER = 256 * 1024 * 1024;
8495
- var MAX_UNTRACKED_BYTES = 5 * 1024 * 1024;
8496
- // packages/workit-core/src/core/external-action.ts
8497
- var chainStepSchema = union([
8498
- string2().min(1),
8499
- object({ branch: string2().min(1) }).strict(),
8500
- object({ pr: literal(true) }).strict()
8501
- ]);
8502
- var externalActionSchema = discriminatedUnion("operation", [
8503
- object({
8504
- operation: literal("git.branch_setup"),
8505
- payload: object({
8506
- action: _enum(["setup", "reapply_stash"]).optional(),
8507
- sdd_dir: string2().optional(),
8508
- target_branch: string2().optional(),
8509
- stash: _enum(["yes", "no"]).optional(),
8510
- cwd: string2().min(1).optional()
8511
- }).strict()
8512
- }).strict(),
8513
- object({
8514
- operation: literal("git.commit"),
8515
- payload: object({
8516
- message: string2().min(1).optional(),
8517
- plan_steps: array(chainStepSchema).min(1).max(32).optional(),
8518
- plan_branch: string2().min(1).optional(),
8519
- cwd: string2().min(1).optional()
8520
- }).strict()
8521
- }).strict(),
8522
- object({
8523
- operation: literal("git.push"),
8524
- payload: object({ branch: string2().min(1).optional(), cwd: string2().min(1).optional() }).strict()
8525
- }).strict(),
8526
- object({
8527
- operation: literal("hosting.pull_request"),
8528
- payload: object({
8529
- title: string2().min(1),
8530
- body: string2().optional(),
8531
- draft: boolean2().optional(),
8532
- target_branch: string2().optional(),
8533
- babysit: boolean2().optional(),
8534
- cwd: string2().min(1).optional()
8535
- }).strict()
8536
- }).strict(),
8537
- object({
8538
- operation: literal("hosting.merge"),
8539
- payload: object({
8540
- target_branch: string2().min(1).optional(),
8541
- source_branch: string2().min(1).optional(),
8542
- cwd: string2().min(1).optional()
8543
- }).strict()
8544
- }).strict(),
8545
- object({
8546
- operation: literal("hosting.delete_branch"),
8547
- payload: object({ branch: string2().min(1), cwd: string2().min(1).optional() }).strict()
8548
- }).strict(),
8549
- object({
8550
- operation: literal("youtrack.update"),
8551
- payload: object({
8552
- issueId: string2().min(1),
8553
- markdown: string2().min(1),
8554
- minutes: number2().positive().optional()
8555
- }).strict()
8556
- }).strict(),
8557
- object({
8558
- operation: literal("youtrack.time"),
8559
- payload: object({
8560
- issueId: string2().min(1),
8561
- minutes: number2().positive(),
8562
- text: string2().optional(),
8563
- dateMs: number2().finite().optional()
8564
- }).strict()
8565
- }).strict(),
8566
- object({
8567
- operation: literal("youtrack.meeting"),
8568
- payload: object({
8569
- issueId: string2().min(1),
8570
- minutes: number2().positive(),
8571
- text: string2().min(1)
8572
- }).strict()
8573
- }).strict(),
8574
- object({
8575
- operation: literal("changelog.apply"),
8576
- payload: object({
8577
- entries: union([
8578
- record(string2(), array(string2())),
8579
- array(object({ category: string2().min(1), text: string2().min(1) }).strict())
8580
- ]).optional(),
8581
- path: string2().optional(),
8582
- normalize_only: boolean2().optional()
8583
- }).strict()
8584
- }).strict(),
8585
- object({
8586
- operation: literal("context.read"),
8587
- payload: object({
8588
- kind: _enum([
8589
- "git",
8590
- "pr",
8591
- "youtrack",
8592
- "github_issue",
8593
- "gitlab_issue",
8594
- "changelog",
8595
- "release",
8596
- "affected"
8597
- ]),
8598
- range: string2().optional(),
8599
- issueId: string2().optional(),
8600
- issueUrl: string2().optional(),
8601
- issueRef: string2().optional(),
8602
- mode: string2().optional(),
8603
- specPath: string2().optional(),
8604
- planPath: string2().optional(),
8605
- cwd: string2().min(1).optional()
8606
- }).strict()
8607
- }).strict()
8608
- ]);
8609
8440
  // packages/workit-core/src/core/policy-resolver.ts
8610
8441
  var resolverInputSchema = object({
8611
8442
  intent: intentSchema,
@@ -8621,7 +8452,6 @@ var resolverInputSchema = object({
8621
8452
 
8622
8453
  // packages/workit-core/src/core/task-engine.ts
8623
8454
  var verifiedWorkers = new WeakMap;
8624
- var dispatchReservations = new WeakMap;
8625
8455
  var TASK_SCOPED_ACTIONS = new Set([
8626
8456
  "task.inspect",
8627
8457
  "task.revise",
@@ -8640,8 +8470,6 @@ var TASK_SCOPED_ACTIONS = new Set([
8640
8470
  "worker.assign",
8641
8471
  "worker.report",
8642
8472
  "worker.cancel",
8643
- "writer.acquire",
8644
- "writer.release",
8645
8473
  "state.export"
8646
8474
  ]);
8647
8475
  var CREATING_ACTIONS = new Set([
@@ -8651,10 +8479,37 @@ var CREATING_ACTIONS = new Set([
8651
8479
  "evidence.record",
8652
8480
  "finding.record",
8653
8481
  "decision.record",
8654
- "worker.assign",
8655
- "writer.acquire"
8482
+ "worker.assign"
8656
8483
  ]);
8657
8484
  var retryPause = new Int32Array(new SharedArrayBuffer(4));
8485
+ // packages/workit-core/src/core/templates.ts
8486
+ var repoRoot = assetRoot();
8487
+
8488
+ // packages/workit-core/src/core/scripts.ts
8489
+ var PLUGIN_ROOT = packageRoot();
8490
+ var ASSET_ROOT = assetRoot();
8491
+
8492
+ // packages/workit-core/src/core/context-read.ts
8493
+ var contextReadSchema = object({
8494
+ kind: _enum([
8495
+ "git",
8496
+ "pr",
8497
+ "youtrack",
8498
+ "github_issue",
8499
+ "gitlab_issue",
8500
+ "changelog",
8501
+ "release",
8502
+ "affected"
8503
+ ]),
8504
+ range: string2().optional(),
8505
+ issueId: string2().optional(),
8506
+ issueUrl: string2().optional(),
8507
+ issueRef: string2().optional(),
8508
+ mode: string2().optional(),
8509
+ specPath: string2().optional(),
8510
+ planPath: string2().optional(),
8511
+ cwd: string2().min(1).optional()
8512
+ }).strict();
8658
8513
  // packages/workit-pi/src/worker-protocol.ts
8659
8514
  var MAX_WORKER_LINE_BYTES = 64 * 1024;
8660
8515
  var MAX_WORKER_STDERR_BYTES = 64 * 1024;
@@ -8789,14 +8644,12 @@ function launchWorker(assignment, options) {
8789
8644
  child: null,
8790
8645
  pid: null,
8791
8646
  spawned: false,
8792
- dispatch: null,
8793
8647
  state: "assigned",
8794
8648
  report: null,
8795
8649
  events: [],
8796
8650
  stdoutBuffer: "",
8797
8651
  stderr: "",
8798
8652
  exit: null,
8799
- writerReady: options.writerReady === true,
8800
8653
  ready: false,
8801
8654
  protocolError: null,
8802
8655
  pendingPrompt: options.pendingPrompt,
@@ -8927,57 +8780,13 @@ var consumeWorkerOutput = (handle, chunk) => {
8927
8780
  function sendWorkerPrompt(handle, prompt) {
8928
8781
  if (!handle.child?.stdin || handle.state !== "running" || !handle.ready)
8929
8782
  return false;
8930
- if (handle.assignment.role === "implementer" && !handle.writerReady)
8931
- return false;
8932
8783
  return handle.child.stdin.write(JSON.stringify({ id: "workit", type: "prompt", message: prompt }) + `
8933
8784
  `);
8934
8785
  }
8935
- var prepareWorkerLaunch = (binding, handle) => {
8936
- const result = binding.core.prepareWorkerDispatch({
8937
- taskId: binding.taskId,
8938
- workerId: binding.workerId,
8939
- expectedRevision: binding.expectedRevision,
8940
- expectedWorkspaceRevision: binding.expectedWorkspaceRevision,
8941
- observation: { stage: "prepare", sessionId: handle.sessionId }
8942
- });
8943
- advanceBinding(binding, result);
8944
- if (result.ok)
8945
- handle.dispatch = result.data;
8946
- return result;
8947
- };
8948
- var commitWorkerNotStarted = (binding, handle) => {
8949
- const dispatch = handle.dispatch;
8950
- if (!dispatch)
8951
- return failure2("recovery_required", "worker launch reservation is not live");
8952
- const result = binding.core.commitWorkerDispatch({
8953
- dispatch,
8954
- taskId: binding.taskId,
8955
- workerId: binding.workerId,
8956
- expectedRevision: binding.expectedRevision,
8957
- expectedWorkspaceRevision: binding.expectedWorkspaceRevision,
8958
- outcome: "not_started",
8959
- session: null,
8960
- observation: { stage: "not_started", sessionId: handle.sessionId }
8961
- });
8962
- advanceBinding(binding, result);
8963
- if (result.ok)
8964
- handle.dispatch = null;
8965
- return result;
8966
- };
8967
8786
  var observeWorkerStart = (binding, handle) => {
8968
8787
  const session = { kind: "host", host: "pi", handle: binding.sessionId };
8969
8788
  const observation = binding.observation ?? { pid: handle.pid, sessionId: handle.sessionId };
8970
- const dispatch = handle.dispatch;
8971
- const result = dispatch ? binding.core.commitWorkerDispatch({
8972
- dispatch,
8973
- taskId: binding.taskId,
8974
- workerId: binding.workerId,
8975
- expectedRevision: binding.expectedRevision,
8976
- expectedWorkspaceRevision: binding.expectedWorkspaceRevision,
8977
- outcome: "started",
8978
- session,
8979
- observation
8980
- }) : binding.core.observeWorkerLifecycle({
8789
+ const result = binding.core.observeWorkerLifecycle({
8981
8790
  taskId: binding.taskId,
8982
8791
  workerId: binding.workerId,
8983
8792
  expectedRevision: binding.expectedRevision,
@@ -8986,8 +8795,6 @@ var observeWorkerStart = (binding, handle) => {
8986
8795
  session,
8987
8796
  observation
8988
8797
  });
8989
- if (dispatch && result.ok)
8990
- handle.dispatch = null;
8991
8798
  advanceBinding(binding, result);
8992
8799
  return result;
8993
8800
  };
@@ -9009,14 +8816,6 @@ var observeWorkerExit = (binding, handle, exit) => {
9009
8816
  advanceBinding(binding, result);
9010
8817
  return result;
9011
8818
  };
9012
- var acquireWorkerWriter = (core, taskId, workerId, expectedRevision, expectedWorkspaceRevision) => core.writer({
9013
- schemaVersion: 1,
9014
- action: "acquire",
9015
- taskId,
9016
- workerId,
9017
- expectedRevision,
9018
- expectedWorkspaceRevision
9019
- });
9020
8819
  var reportWorker = (core, taskId, workerId, report, expectedRevision, expectedWorkspaceRevision) => core.worker({
9021
8820
  schemaVersion: 1,
9022
8821
  action: "report",
@@ -9041,13 +8840,8 @@ var launchSupervisedWorker = (assignment, options) => {
9041
8840
  taskId: options.binding.taskId,
9042
8841
  workerId: options.binding.workerId,
9043
8842
  sessionId: options.binding.sessionId,
9044
- writerReady: assignment.role !== "implementer",
9045
8843
  pendingPrompt: options.prompt,
9046
- onPrepare: (pending) => {
9047
- if (options.onPrepare && !options.onPrepare(pending))
9048
- return false;
9049
- return prepareWorkerLaunch(options.binding, pending).ok;
9050
- },
8844
+ onPrepare: (pending) => !options.onPrepare || options.onPrepare(pending),
9051
8845
  onSpawn: (spawned) => {
9052
8846
  if (options.onSpawn && !options.onSpawn(spawned))
9053
8847
  return false;
@@ -9068,26 +8862,6 @@ var launchSupervisedWorker = (assignment, options) => {
9068
8862
  options.onError?.(errored);
9069
8863
  },
9070
8864
  onReady: (readyHandle) => {
9071
- if (assignment.role === "implementer") {
9072
- const writer = acquireWorkerWriter(options.writerCore ?? options.binding.core, options.binding.taskId, options.binding.workerId, options.binding.expectedRevision, options.binding.expectedWorkspaceRevision);
9073
- readyHandle.writerReady = writer.ok;
9074
- advanceBinding(options.binding, writer);
9075
- if (!writer.ok) {
9076
- readyHandle.protocolError = "worker writer acquisition failed";
9077
- readyHandle.pendingPrompt = undefined;
9078
- const uncertaintyPersisted = options.onUncertain?.(readyHandle, {
9079
- state: "unknown",
9080
- observed: false,
9081
- code: null,
9082
- signal: null,
9083
- stderr: readyHandle.stderr
9084
- });
9085
- if (options.onUncertain && !uncertaintyPersisted)
9086
- readyHandle.protocolError = "worker uncertainty could not be persisted";
9087
- readyHandle.child?.kill("SIGTERM");
9088
- return;
9089
- }
9090
- }
9091
8865
  options.onReady?.(readyHandle);
9092
8866
  },
9093
8867
  onExit: (stopped, exit) => {
@@ -9102,19 +8876,6 @@ var launchSupervisedWorker = (assignment, options) => {
9102
8876
  return handle;
9103
8877
  };
9104
8878
  var nativeWorkerForEvidence = (getHandle) => ({
9105
- verifyDispatch: ({ expected, caller, observation }) => {
9106
- const handle = getHandle();
9107
- const observed = observation;
9108
- if (!handle || caller.host !== "pi" || expected.workerId !== handle.workerId || typeof observed !== "object" || observed === null || observed.stage !== expected.stage || observed.sessionId !== handle.sessionId || handle.spawned || handle.child !== null || handle.exit !== null)
9109
- return failure2("permission_denied", "Pi worker dispatch was not observed by the host");
9110
- return success(null, null, {
9111
- kind: "host_observed",
9112
- host: "pi",
9113
- session: { kind: "host", host: "pi", handle: caller.actor },
9114
- workerId: expected.workerId,
9115
- receipts: [{ kind: "host", host: "pi", handle: "dispatch:" + handle.sessionId }]
9116
- });
9117
- },
9118
8879
  verifyWorker: ({ expected, caller, observation }) => {
9119
8880
  const handle = getHandle();
9120
8881
  if (!handle || caller.host !== "pi" || expected.workerId !== handle.workerId || expected.session?.kind !== "host" || expected.session.host !== "pi" || expected.session.handle !== handle.sessionId || typeof observation !== "object" || observation === null || observation.pid !== handle.pid)
@@ -9128,8 +8889,7 @@ var nativeWorkerForEvidence = (getHandle) => ({
9128
8889
  kind: "host_observed",
9129
8890
  host: "pi",
9130
8891
  session: expected.session,
9131
- workerId: expected.workerId,
9132
- receipts: [{ kind: "host", host: "pi", handle: "pid:" + String(handle.pid ?? "unknown") }]
8892
+ workerId: expected.workerId
9133
8893
  }
9134
8894
  };
9135
8895
  }
@@ -9147,8 +8907,7 @@ var nativeLostWorker = () => ({
9147
8907
  kind: "host_observed",
9148
8908
  host: "pi",
9149
8909
  session: expected.session,
9150
- workerId: expected.workerId,
9151
- receipts: [{ kind: "host", host: "pi", handle: "lost:" + expected.session.handle }]
8910
+ workerId: expected.workerId
9152
8911
  }
9153
8912
  };
9154
8913
  }
@@ -9161,7 +8920,7 @@ async function cancelWorker(handle, options = {}) {
9161
8920
  return { state: "unknown", observed: false, code: null, signal: null, stderr: handle.stderr };
9162
8921
  };
9163
8922
  if (!handle.child) {
9164
- if (handle.spawned || !handle.dispatch || !options.binding || !commitWorkerNotStarted(options.binding, handle).ok)
8923
+ if (handle.spawned)
9165
8924
  return uncertain();
9166
8925
  handle.state = "stopped";
9167
8926
  handle.exit = {
@@ -9212,7 +8971,6 @@ export {
9212
8971
  advanceWorkerBinding,
9213
8972
  cancelWorker,
9214
8973
  cancelWorkerAssignment,
9215
- commitWorkerNotStarted,
9216
8974
  consumeWorkerOutput,
9217
8975
  launchSupervisedWorker,
9218
8976
  launchWorker,
@@ -9222,7 +8980,6 @@ export {
9222
8980
  observeWorkerExit,
9223
8981
  observeWorkerStart,
9224
8982
  parseWorkerResult,
9225
- prepareWorkerLaunch,
9226
8983
  reconcileWorker,
9227
8984
  reportWorker,
9228
8985
  sendWorkerPrompt,