@agimon-ai/po-task 0.0.0-alpha.8 → 0.0.0-alpha.80

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 (93) hide show
  1. package/LICENSE +149 -21
  2. package/README.md +12 -2
  3. package/dist/apiContracts.cjs +1 -0
  4. package/dist/apiContracts.cjs.map +1 -1
  5. package/dist/apiContracts.mjs +1 -0
  6. package/dist/apiContracts.mjs.map +1 -1
  7. package/dist/{delegation-Dsqf7fUM.mjs → delegation-5TOl_dEq.mjs} +4 -3
  8. package/dist/delegation-5TOl_dEq.mjs.map +1 -0
  9. package/dist/{delegation-frvEXhIz.cjs → delegation-BJtAUTVg.cjs} +4 -3
  10. package/dist/delegation-BJtAUTVg.cjs.map +1 -0
  11. package/dist/delegationManager.cjs +1 -1
  12. package/dist/delegationManager.d.mts +1 -1
  13. package/dist/delegationManager.mjs +1 -1
  14. package/dist/extensions/mcp.cjs +60 -61
  15. package/dist/extensions/mcp.cjs.map +1 -1
  16. package/dist/extensions/mcp.mjs +60 -61
  17. package/dist/extensions/mcp.mjs.map +1 -1
  18. package/dist/extensions/native.mjs +420 -315
  19. package/dist/extensions/native.mjs.map +1 -1
  20. package/dist/extensions/server.cjs +398 -136
  21. package/dist/extensions/server.cjs.map +1 -1
  22. package/dist/extensions/server.d.mts +2 -2
  23. package/dist/extensions/server.d.mts.map +1 -1
  24. package/dist/extensions/server.mjs +397 -135
  25. package/dist/extensions/server.mjs.map +1 -1
  26. package/dist/extensions/web.mjs +254 -206
  27. package/dist/extensions/web.mjs.map +1 -1
  28. package/dist/{index-DlmXKyhQ.d.mts → index-CdJx5tdI.d.mts} +2 -2
  29. package/dist/{index-DlmXKyhQ.d.mts.map → index-CdJx5tdI.d.mts.map} +1 -1
  30. package/dist/{index-B1JPJdpZ.d.mts → index-DrE00rrP.d.mts} +3 -3
  31. package/dist/{index-B1JPJdpZ.d.mts.map → index-DrE00rrP.d.mts.map} +1 -1
  32. package/dist/{index-qQGWsPum.d.mts → index-DuT-Lbxy.d.mts} +2 -3
  33. package/dist/index-DuT-Lbxy.d.mts.map +1 -0
  34. package/dist/{index-CUWCvh-E.d.mts → index-nx0ueNkm.d.mts} +2 -2
  35. package/dist/{index-CUWCvh-E.d.mts.map → index-nx0ueNkm.d.mts.map} +1 -1
  36. package/dist/{index-B9QNwUBr.d.mts → index-sahNy7Hg.d.mts} +3 -3
  37. package/dist/{index-B9QNwUBr.d.mts.map → index-sahNy7Hg.d.mts.map} +1 -1
  38. package/dist/{index-CA4Opp4r.d.mts → index-tAu1TIyi.d.mts} +4 -6
  39. package/dist/index-tAu1TIyi.d.mts.map +1 -0
  40. package/dist/index.cjs +3 -5
  41. package/dist/index.d.mts +10 -10
  42. package/dist/index.mjs +4 -4
  43. package/dist/{logSinkTelemetry-BhbKdn-x.mjs → logSinkTelemetry-3GMazFYa.mjs} +2 -2
  44. package/dist/logSinkTelemetry-3GMazFYa.mjs.map +1 -0
  45. package/dist/{logSinkTelemetry-BGb8WQBz.cjs → logSinkTelemetry-DhzIQMsV.cjs} +3 -3
  46. package/dist/logSinkTelemetry-DhzIQMsV.cjs.map +1 -0
  47. package/dist/logSinkTelemetry.cjs +1 -1
  48. package/dist/logSinkTelemetry.d.mts +1 -1
  49. package/dist/logSinkTelemetry.mjs +1 -1
  50. package/dist/{paths-P-XvOUuH.cjs → paths-CWVDY8Yd.cjs} +12 -78
  51. package/dist/paths-CWVDY8Yd.cjs.map +1 -0
  52. package/dist/{paths-DajceJig.mjs → paths-CjATVpi8.mjs} +12 -66
  53. package/dist/paths-CjATVpi8.mjs.map +1 -0
  54. package/dist/storeInvariants.d.mts +1 -1
  55. package/dist/storePaths.cjs +1 -3
  56. package/dist/storePaths.d.mts +2 -2
  57. package/dist/storePaths.mjs +1 -1
  58. package/dist/storeReconcile.d.mts +1 -1
  59. package/dist/storeReducer.d.mts +1 -1
  60. package/dist/storeTaskGraph.d.mts +1 -1
  61. package/dist/storeTaskStore.cjs +1 -1
  62. package/dist/storeTaskStore.d.mts +1 -1
  63. package/dist/storeTaskStore.mjs +1 -1
  64. package/dist/storeTypes.d.mts +1 -1
  65. package/dist/{task-4HeGAS8o.d.mts → task--hlnpS7L.d.mts} +2 -2
  66. package/dist/{task-4HeGAS8o.d.mts.map → task--hlnpS7L.d.mts.map} +1 -1
  67. package/dist/task-CXF9VULl.cjs.map +1 -1
  68. package/dist/{task-DJpTteeJ.d.mts → task-DdTKZNtU.d.mts} +3 -1
  69. package/dist/task-DdTKZNtU.d.mts.map +1 -0
  70. package/dist/task-giCbpKzV.mjs.map +1 -1
  71. package/dist/{taskGraph-D0zFHF2p.d.mts → taskGraph-CB8ffMCz.d.mts} +2 -2
  72. package/dist/{taskGraph-D0zFHF2p.d.mts.map → taskGraph-CB8ffMCz.d.mts.map} +1 -1
  73. package/dist/{taskStore-C4vcUOzA.cjs → taskStore-B-BbY2Ci.cjs} +30 -36
  74. package/dist/taskStore-B-BbY2Ci.cjs.map +1 -0
  75. package/dist/{taskStore-BAi54FKL.mjs → taskStore-wuXXFCZT.mjs} +29 -35
  76. package/dist/taskStore-wuXXFCZT.mjs.map +1 -0
  77. package/dist/toolResponseEnvelope.d.mts +1 -1
  78. package/dist/toolSchema.d.mts +1 -1
  79. package/llms.txt +11 -0
  80. package/package.json +18 -17
  81. package/src/prompts/codemode-how-to-task/SKILL.md +40 -0
  82. package/src/types/webTasks.ts +1 -0
  83. package/dist/delegation-Dsqf7fUM.mjs.map +0 -1
  84. package/dist/delegation-frvEXhIz.cjs.map +0 -1
  85. package/dist/index-CA4Opp4r.d.mts.map +0 -1
  86. package/dist/index-qQGWsPum.d.mts.map +0 -1
  87. package/dist/logSinkTelemetry-BGb8WQBz.cjs.map +0 -1
  88. package/dist/logSinkTelemetry-BhbKdn-x.mjs.map +0 -1
  89. package/dist/paths-DajceJig.mjs.map +0 -1
  90. package/dist/paths-P-XvOUuH.cjs.map +0 -1
  91. package/dist/task-DJpTteeJ.d.mts.map +0 -1
  92. package/dist/taskStore-BAi54FKL.mjs.map +0 -1
  93. package/dist/taskStore-C4vcUOzA.cjs.map +0 -1
@@ -27,8 +27,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  let _agimon_ai_po_core_mcpFacet = require("@agimon-ai/po-core/mcpFacet");
28
28
  let _agimon_ai_po_core_delegation = require("@agimon-ai/po-core/delegation");
29
29
  let typebox = require("typebox");
30
- let node_fs = require("node:fs");
31
- node_fs = __toESM(node_fs, 1);
30
+ let node_fs_promises = require("node:fs/promises");
31
+ node_fs_promises = __toESM(node_fs_promises, 1);
32
32
  let node_path = require("node:path");
33
33
  node_path = __toESM(node_path, 1);
34
34
  let _agimon_ai_po_core_childProcess = require("@agimon-ai/po-core/childProcess");
@@ -345,16 +345,6 @@ var TaskStore = class {
345
345
  get snapshot() {
346
346
  return this.cached;
347
347
  }
348
- read() {
349
- try {
350
- const raw = node_fs.default.readFileSync(this.storePath, UTF8_ENCODING);
351
- this.cached = normalizeDocument(JSON.parse(raw));
352
- } catch (error) {
353
- if (error.code !== MISSING_FILE_CODE) this.report?.error(TASK_EVENT.storeReadFailed, error, { [STORE_PATH_ATTRIBUTE]: this.storePath });
354
- this.cached = emptyDocument();
355
- }
356
- return this.cached;
357
- }
358
348
  async readAsync(shouldApply = () => true, onReadError) {
359
349
  const storePath = this.storePath;
360
350
  const document = await this.readDocumentAsync(storePath, onReadError);
@@ -364,7 +354,7 @@ var TaskStore = class {
364
354
  }
365
355
  async readDocumentAsync(storePath = this.storePath, onReadError) {
366
356
  try {
367
- const raw = await node_fs.default.promises.readFile(storePath, UTF8_ENCODING);
357
+ const raw = await node_fs_promises.default.readFile(storePath, UTF8_ENCODING);
368
358
  return normalizeDocument(JSON.parse(raw));
369
359
  } catch (error) {
370
360
  if (error.code !== MISSING_FILE_CODE) {
@@ -385,15 +375,16 @@ var TaskStore = class {
385
375
  */
386
376
  async mutate(mutate) {
387
377
  const release = await this.acquireLock();
388
- const outcome = (() => {
378
+ const outcome = await (async () => {
389
379
  try {
390
- const current = this.read();
380
+ const current = await this.readDocumentAsync();
381
+ this.cached = current;
391
382
  const mutation = mutate(current);
392
383
  if (!mutation.document) return { result: {
393
384
  document: current,
394
385
  value: mutation.value
395
386
  } };
396
- const committed = this.write(mutation.document);
387
+ const committed = await this.write(mutation.document);
397
388
  return {
398
389
  result: {
399
390
  document: committed,
@@ -402,7 +393,7 @@ var TaskStore = class {
402
393
  notification: committed
403
394
  };
404
395
  } finally {
405
- release();
396
+ await release();
406
397
  }
407
398
  })();
408
399
  if (outcome.notification) this.notifyCommitted(outcome.notification);
@@ -415,49 +406,52 @@ var TaskStore = class {
415
406
  this.report?.error(TASK_EVENT.storeListenerFailed, error, { [STORE_PATH_ATTRIBUTE]: this.storePath });
416
407
  }
417
408
  }
418
- write(document) {
409
+ async write(document) {
419
410
  const next = {
420
411
  ...document,
421
412
  version: 1,
422
413
  rev: document.rev + 1
423
414
  };
424
- node_fs.default.mkdirSync(node_path.default.dirname(this.storePath), { recursive: true });
415
+ await node_fs_promises.default.mkdir(node_path.default.dirname(this.storePath), { recursive: true });
425
416
  const temp = tempPathFor(this.storePath);
426
- node_fs.default.writeFileSync(temp, `${JSON.stringify(next, void 0, 2)}\n`, UTF8_ENCODING);
427
- node_fs.default.renameSync(temp, this.storePath);
417
+ await node_fs_promises.default.writeFile(temp, `${JSON.stringify(next, void 0, 2)}\n`, UTF8_ENCODING);
418
+ await node_fs_promises.default.rename(temp, this.storePath);
428
419
  this.cached = next;
429
420
  return next;
430
421
  }
431
422
  async acquireLock() {
432
423
  const lockPath = lockPathFor(this.storePath);
433
- node_fs.default.mkdirSync(node_path.default.dirname(this.storePath), { recursive: true });
424
+ await node_fs_promises.default.mkdir(node_path.default.dirname(this.storePath), { recursive: true });
434
425
  const deadline = Date.now() + this.lockTimeoutMs;
435
426
  for (;;) try {
436
- const handle = node_fs.default.openSync(lockPath, "wx");
437
- node_fs.default.writeSync(handle, JSON.stringify({
438
- pid: process.pid,
439
- time: Date.now()
440
- }));
441
- node_fs.default.closeSync(handle);
442
- return () => node_fs.default.rmSync(lockPath, { force: true });
427
+ const handle = await node_fs_promises.default.open(lockPath, "wx");
428
+ try {
429
+ await handle.writeFile(JSON.stringify({
430
+ pid: process.pid,
431
+ time: Date.now()
432
+ }));
433
+ } finally {
434
+ await handle.close();
435
+ }
436
+ return () => node_fs_promises.default.rm(lockPath, { force: true });
443
437
  } catch (error) {
444
438
  if (error.code !== LOCK_EXISTS_CODE) throw error;
445
439
  if (Date.now() >= deadline) {
446
440
  this.report?.warn(TASK_EVENT.storeLockTimeout, /* @__PURE__ */ new Error(`Task store lock still held after ${this.lockTimeoutMs}ms; proceeding without it`), { [STORE_PATH_ATTRIBUTE]: this.storePath });
447
- return () => {};
441
+ return async () => {};
448
442
  }
449
- this.breakStaleLock(lockPath);
443
+ await this.breakStaleLock(lockPath);
450
444
  await sleep(LOCK_RETRY_BASE_MS + Math.random() * LOCK_RETRY_MAX_MS);
451
445
  }
452
446
  }
453
447
  /** Remove a lock left behind by a dead process or one held implausibly long. */
454
- breakStaleLock(lockPath) {
448
+ async breakStaleLock(lockPath) {
455
449
  try {
456
- const holder = JSON.parse(node_fs.default.readFileSync(lockPath, UTF8_ENCODING));
450
+ const holder = JSON.parse(await node_fs_promises.default.readFile(lockPath, UTF8_ENCODING));
457
451
  const expired = typeof holder.time === "number" && Date.now() - holder.time > LOCK_STALE_MS;
458
452
  const dead = typeof holder.pid === "number" && !isProcessAlive(holder.pid);
459
453
  if (!expired && !dead) return false;
460
- node_fs.default.unlinkSync(lockPath);
454
+ await node_fs_promises.default.unlink(lockPath);
461
455
  return true;
462
456
  } catch (error) {
463
457
  if (error.code !== MISSING_FILE_CODE) this.report?.warn(TASK_EVENT.storeLockBreakFailed, error, { [STORE_PATH_ATTRIBUTE]: lockPath });
@@ -1059,6 +1053,37 @@ async function assignmentBatch(manager, assignments, signal) {
1059
1053
  }
1060
1054
  return result;
1061
1055
  }
1056
+ /** One task action against the session store, shared by the `task` tool and the `tasks` code-mode namespace. */
1057
+ async function runTaskAction(store, manager, maxTasks, rawParams, signal, onUpdate) {
1058
+ if (!(0, typebox_value.Check)(TaskParamsSchema, rawParams)) {
1059
+ const [first] = (0, typebox_value.Errors)(TaskParamsSchema, rawParams);
1060
+ return failure(`Invalid task parameters${first ? `: ${first.instancePath || "/"} ${first.message}` : ""}.`);
1061
+ }
1062
+ const params = rawParams;
1063
+ try {
1064
+ if ((params.action === "assign" || params.action === "cancel") && !manager) throw new Error("Delegation is not available on this connection.");
1065
+ if (params.action === "assign") {
1066
+ if (!params.assignments?.length) throw new Error("assign requires a non-empty assignments[] array");
1067
+ onUpdate?.(output(`Delegating ${params.assignments.length} task${params.assignments.length === 1 ? "" : "s"}...`));
1068
+ const items = await assignmentBatch(manager, params.assignments, signal);
1069
+ const assigned = items.filter((item) => item.ok).map((item) => item.id);
1070
+ const text = formatAssignmentResults(items);
1071
+ if (assigned.length === 0) throw new Error(text);
1072
+ return buildAssignmentResult(params, store.snapshot, text, {
1073
+ assigned,
1074
+ failed: items.length - assigned.length
1075
+ });
1076
+ }
1077
+ if (params.action === "cancel") {
1078
+ const outcome = await manager.cancel(params.id ?? NaN);
1079
+ if (!outcome.ok) throw new Error(outcome.message);
1080
+ return buildTextResult("cancel", params, store.snapshot, outcome.message);
1081
+ }
1082
+ return reducerAction(store, params.action, params, maxTasks);
1083
+ } catch (error) {
1084
+ return failure(error);
1085
+ }
1086
+ }
1062
1087
  function createHeadlessTaskTool(store, manager, maxTasks) {
1063
1088
  return {
1064
1089
  name: "task",
@@ -1067,33 +1092,7 @@ function createHeadlessTaskTool(store, manager, maxTasks) {
1067
1092
  parameters: TaskParamsSchema,
1068
1093
  promptSnippet: "Track complex work persistently and delegate ready tasks",
1069
1094
  executionMode: "serial",
1070
- async execute(_toolCallId, rawParams, signal, onUpdate) {
1071
- if (!(0, typebox_value.Check)(TaskParamsSchema, rawParams)) return failure("Invalid task parameters.");
1072
- const params = rawParams;
1073
- try {
1074
- if ((params.action === "assign" || params.action === "cancel") && !manager) throw new Error("Delegation is not available on this connection.");
1075
- if (params.action === "assign") {
1076
- if (!params.assignments?.length) throw new Error("assign requires a non-empty assignments[] array");
1077
- onUpdate?.(output(`Delegating ${params.assignments.length} task${params.assignments.length === 1 ? "" : "s"}...`));
1078
- const items = await assignmentBatch(manager, params.assignments, signal);
1079
- const assigned = items.filter((item) => item.ok).map((item) => item.id);
1080
- const text = formatAssignmentResults(items);
1081
- if (assigned.length === 0) throw new Error(text);
1082
- return buildAssignmentResult(params, store.snapshot, text, {
1083
- assigned,
1084
- failed: items.length - assigned.length
1085
- });
1086
- }
1087
- if (params.action === "cancel") {
1088
- const outcome = await manager.cancel(params.id ?? NaN);
1089
- if (!outcome.ok) throw new Error(outcome.message);
1090
- return buildTextResult("cancel", params, store.snapshot, outcome.message);
1091
- }
1092
- return reducerAction(store, params.action, params, maxTasks);
1093
- } catch (error) {
1094
- return failure(error);
1095
- }
1096
- }
1095
+ execute: (_toolCallId, rawParams, signal, onUpdate) => runTaskAction(store, manager, maxTasks, rawParams, signal, onUpdate)
1097
1096
  };
1098
1097
  }
1099
1098
  //#endregion