@agimon-ai/po-task 0.0.0-alpha.7 → 0.0.0-alpha.71
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/LICENSE +149 -21
- package/README.md +12 -2
- package/dist/apiContracts.cjs +1 -0
- package/dist/apiContracts.cjs.map +1 -1
- package/dist/apiContracts.mjs +1 -0
- package/dist/apiContracts.mjs.map +1 -1
- package/dist/{delegation-Dsqf7fUM.mjs → delegation-5TOl_dEq.mjs} +4 -3
- package/dist/delegation-5TOl_dEq.mjs.map +1 -0
- package/dist/{delegation-frvEXhIz.cjs → delegation-BJtAUTVg.cjs} +4 -3
- package/dist/delegation-BJtAUTVg.cjs.map +1 -0
- package/dist/delegationManager.cjs +1 -1
- package/dist/delegationManager.d.mts +1 -1
- package/dist/delegationManager.mjs +1 -1
- package/dist/extensions/mcp.cjs +60 -61
- package/dist/extensions/mcp.cjs.map +1 -1
- package/dist/extensions/mcp.mjs +60 -61
- package/dist/extensions/mcp.mjs.map +1 -1
- package/dist/extensions/native.mjs +420 -315
- package/dist/extensions/native.mjs.map +1 -1
- package/dist/extensions/server.cjs +398 -136
- package/dist/extensions/server.cjs.map +1 -1
- package/dist/extensions/server.d.mts +2 -2
- package/dist/extensions/server.d.mts.map +1 -1
- package/dist/extensions/server.mjs +397 -135
- package/dist/extensions/server.mjs.map +1 -1
- package/dist/extensions/web.mjs +254 -206
- package/dist/extensions/web.mjs.map +1 -1
- package/dist/{index-DlmXKyhQ.d.mts → index-CdJx5tdI.d.mts} +2 -2
- package/dist/{index-DlmXKyhQ.d.mts.map → index-CdJx5tdI.d.mts.map} +1 -1
- package/dist/{index-B1JPJdpZ.d.mts → index-DrE00rrP.d.mts} +3 -3
- package/dist/{index-B1JPJdpZ.d.mts.map → index-DrE00rrP.d.mts.map} +1 -1
- package/dist/{index-qQGWsPum.d.mts → index-DuT-Lbxy.d.mts} +2 -3
- package/dist/index-DuT-Lbxy.d.mts.map +1 -0
- package/dist/{index-CUWCvh-E.d.mts → index-nx0ueNkm.d.mts} +2 -2
- package/dist/{index-CUWCvh-E.d.mts.map → index-nx0ueNkm.d.mts.map} +1 -1
- package/dist/{index-B9QNwUBr.d.mts → index-sahNy7Hg.d.mts} +3 -3
- package/dist/{index-B9QNwUBr.d.mts.map → index-sahNy7Hg.d.mts.map} +1 -1
- package/dist/{index-CA4Opp4r.d.mts → index-tAu1TIyi.d.mts} +4 -6
- package/dist/index-tAu1TIyi.d.mts.map +1 -0
- package/dist/index.cjs +3 -5
- package/dist/index.d.mts +10 -10
- package/dist/index.mjs +4 -4
- package/dist/{logSinkTelemetry-BhbKdn-x.mjs → logSinkTelemetry-3GMazFYa.mjs} +2 -2
- package/dist/logSinkTelemetry-3GMazFYa.mjs.map +1 -0
- package/dist/{logSinkTelemetry-BGb8WQBz.cjs → logSinkTelemetry-DhzIQMsV.cjs} +3 -3
- package/dist/logSinkTelemetry-DhzIQMsV.cjs.map +1 -0
- package/dist/logSinkTelemetry.cjs +1 -1
- package/dist/logSinkTelemetry.d.mts +1 -1
- package/dist/logSinkTelemetry.mjs +1 -1
- package/dist/{paths-P-XvOUuH.cjs → paths-CWVDY8Yd.cjs} +12 -78
- package/dist/paths-CWVDY8Yd.cjs.map +1 -0
- package/dist/{paths-DajceJig.mjs → paths-CjATVpi8.mjs} +12 -66
- package/dist/paths-CjATVpi8.mjs.map +1 -0
- package/dist/storeInvariants.d.mts +1 -1
- package/dist/storePaths.cjs +1 -3
- package/dist/storePaths.d.mts +2 -2
- package/dist/storePaths.mjs +1 -1
- package/dist/storeReconcile.d.mts +1 -1
- package/dist/storeReducer.d.mts +1 -1
- package/dist/storeTaskGraph.d.mts +1 -1
- package/dist/storeTaskStore.cjs +1 -1
- package/dist/storeTaskStore.d.mts +1 -1
- package/dist/storeTaskStore.mjs +1 -1
- package/dist/storeTypes.d.mts +1 -1
- package/dist/{task-4HeGAS8o.d.mts → task--hlnpS7L.d.mts} +2 -2
- package/dist/{task-4HeGAS8o.d.mts.map → task--hlnpS7L.d.mts.map} +1 -1
- package/dist/task-CXF9VULl.cjs.map +1 -1
- package/dist/{task-DJpTteeJ.d.mts → task-DdTKZNtU.d.mts} +3 -1
- package/dist/task-DdTKZNtU.d.mts.map +1 -0
- package/dist/task-giCbpKzV.mjs.map +1 -1
- package/dist/{taskGraph-D0zFHF2p.d.mts → taskGraph-CB8ffMCz.d.mts} +2 -2
- package/dist/{taskGraph-D0zFHF2p.d.mts.map → taskGraph-CB8ffMCz.d.mts.map} +1 -1
- package/dist/{taskStore-C4vcUOzA.cjs → taskStore-B-BbY2Ci.cjs} +30 -36
- package/dist/taskStore-B-BbY2Ci.cjs.map +1 -0
- package/dist/{taskStore-BAi54FKL.mjs → taskStore-wuXXFCZT.mjs} +29 -35
- package/dist/taskStore-wuXXFCZT.mjs.map +1 -0
- package/dist/toolResponseEnvelope.d.mts +1 -1
- package/dist/toolSchema.d.mts +1 -1
- package/llms.txt +11 -0
- package/package.json +18 -17
- package/src/prompts/codemode-how-to-task/SKILL.md +40 -0
- package/src/types/webTasks.ts +1 -0
- package/dist/delegation-Dsqf7fUM.mjs.map +0 -1
- package/dist/delegation-frvEXhIz.cjs.map +0 -1
- package/dist/index-CA4Opp4r.d.mts.map +0 -1
- package/dist/index-qQGWsPum.d.mts.map +0 -1
- package/dist/logSinkTelemetry-BGb8WQBz.cjs.map +0 -1
- package/dist/logSinkTelemetry-BhbKdn-x.mjs.map +0 -1
- package/dist/paths-DajceJig.mjs.map +0 -1
- package/dist/paths-P-XvOUuH.cjs.map +0 -1
- package/dist/task-DJpTteeJ.d.mts.map +0 -1
- package/dist/taskStore-BAi54FKL.mjs.map +0 -1
- package/dist/taskStore-C4vcUOzA.cjs.map +0 -1
package/dist/extensions/mcp.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { defineMcpPlugin, defineMcpTool } from "@agimon-ai/po-core/mcpFacet";
|
|
2
2
|
import { InlineAgentSchema } from "@agimon-ai/po-core/delegation";
|
|
3
3
|
import { Type } from "typebox";
|
|
4
|
-
import fs from "node:fs";
|
|
4
|
+
import fs from "node:fs/promises";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { SUBAGENT_CHILD_ENV, SUBAGENT_PARENT_SESSION_ENV } from "@agimon-ai/po-core/childProcess";
|
|
7
7
|
import { piAgentDirectory } from "@agimon-ai/po-core/piSettings";
|
|
8
|
-
import { Check } from "typebox/value";
|
|
8
|
+
import { Check, Errors } from "typebox/value";
|
|
9
9
|
//#region src/schemas/task.ts
|
|
10
10
|
const TASK_ACTIONS = [
|
|
11
11
|
"upsert",
|
|
@@ -317,16 +317,6 @@ var TaskStore = class {
|
|
|
317
317
|
get snapshot() {
|
|
318
318
|
return this.cached;
|
|
319
319
|
}
|
|
320
|
-
read() {
|
|
321
|
-
try {
|
|
322
|
-
const raw = fs.readFileSync(this.storePath, UTF8_ENCODING);
|
|
323
|
-
this.cached = normalizeDocument(JSON.parse(raw));
|
|
324
|
-
} catch (error) {
|
|
325
|
-
if (error.code !== MISSING_FILE_CODE) this.report?.error(TASK_EVENT.storeReadFailed, error, { [STORE_PATH_ATTRIBUTE]: this.storePath });
|
|
326
|
-
this.cached = emptyDocument();
|
|
327
|
-
}
|
|
328
|
-
return this.cached;
|
|
329
|
-
}
|
|
330
320
|
async readAsync(shouldApply = () => true, onReadError) {
|
|
331
321
|
const storePath = this.storePath;
|
|
332
322
|
const document = await this.readDocumentAsync(storePath, onReadError);
|
|
@@ -336,7 +326,7 @@ var TaskStore = class {
|
|
|
336
326
|
}
|
|
337
327
|
async readDocumentAsync(storePath = this.storePath, onReadError) {
|
|
338
328
|
try {
|
|
339
|
-
const raw = await fs.
|
|
329
|
+
const raw = await fs.readFile(storePath, UTF8_ENCODING);
|
|
340
330
|
return normalizeDocument(JSON.parse(raw));
|
|
341
331
|
} catch (error) {
|
|
342
332
|
if (error.code !== MISSING_FILE_CODE) {
|
|
@@ -357,15 +347,16 @@ var TaskStore = class {
|
|
|
357
347
|
*/
|
|
358
348
|
async mutate(mutate) {
|
|
359
349
|
const release = await this.acquireLock();
|
|
360
|
-
const outcome = (() => {
|
|
350
|
+
const outcome = await (async () => {
|
|
361
351
|
try {
|
|
362
|
-
const current = this.
|
|
352
|
+
const current = await this.readDocumentAsync();
|
|
353
|
+
this.cached = current;
|
|
363
354
|
const mutation = mutate(current);
|
|
364
355
|
if (!mutation.document) return { result: {
|
|
365
356
|
document: current,
|
|
366
357
|
value: mutation.value
|
|
367
358
|
} };
|
|
368
|
-
const committed = this.write(mutation.document);
|
|
359
|
+
const committed = await this.write(mutation.document);
|
|
369
360
|
return {
|
|
370
361
|
result: {
|
|
371
362
|
document: committed,
|
|
@@ -374,7 +365,7 @@ var TaskStore = class {
|
|
|
374
365
|
notification: committed
|
|
375
366
|
};
|
|
376
367
|
} finally {
|
|
377
|
-
release();
|
|
368
|
+
await release();
|
|
378
369
|
}
|
|
379
370
|
})();
|
|
380
371
|
if (outcome.notification) this.notifyCommitted(outcome.notification);
|
|
@@ -387,49 +378,52 @@ var TaskStore = class {
|
|
|
387
378
|
this.report?.error(TASK_EVENT.storeListenerFailed, error, { [STORE_PATH_ATTRIBUTE]: this.storePath });
|
|
388
379
|
}
|
|
389
380
|
}
|
|
390
|
-
write(document) {
|
|
381
|
+
async write(document) {
|
|
391
382
|
const next = {
|
|
392
383
|
...document,
|
|
393
384
|
version: 1,
|
|
394
385
|
rev: document.rev + 1
|
|
395
386
|
};
|
|
396
|
-
fs.
|
|
387
|
+
await fs.mkdir(path.dirname(this.storePath), { recursive: true });
|
|
397
388
|
const temp = tempPathFor(this.storePath);
|
|
398
|
-
fs.
|
|
399
|
-
fs.
|
|
389
|
+
await fs.writeFile(temp, `${JSON.stringify(next, void 0, 2)}\n`, UTF8_ENCODING);
|
|
390
|
+
await fs.rename(temp, this.storePath);
|
|
400
391
|
this.cached = next;
|
|
401
392
|
return next;
|
|
402
393
|
}
|
|
403
394
|
async acquireLock() {
|
|
404
395
|
const lockPath = lockPathFor(this.storePath);
|
|
405
|
-
fs.
|
|
396
|
+
await fs.mkdir(path.dirname(this.storePath), { recursive: true });
|
|
406
397
|
const deadline = Date.now() + this.lockTimeoutMs;
|
|
407
398
|
for (;;) try {
|
|
408
|
-
const handle = fs.
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
399
|
+
const handle = await fs.open(lockPath, "wx");
|
|
400
|
+
try {
|
|
401
|
+
await handle.writeFile(JSON.stringify({
|
|
402
|
+
pid: process.pid,
|
|
403
|
+
time: Date.now()
|
|
404
|
+
}));
|
|
405
|
+
} finally {
|
|
406
|
+
await handle.close();
|
|
407
|
+
}
|
|
408
|
+
return () => fs.rm(lockPath, { force: true });
|
|
415
409
|
} catch (error) {
|
|
416
410
|
if (error.code !== LOCK_EXISTS_CODE) throw error;
|
|
417
411
|
if (Date.now() >= deadline) {
|
|
418
412
|
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 });
|
|
419
|
-
return () => {};
|
|
413
|
+
return async () => {};
|
|
420
414
|
}
|
|
421
|
-
this.breakStaleLock(lockPath);
|
|
415
|
+
await this.breakStaleLock(lockPath);
|
|
422
416
|
await sleep(LOCK_RETRY_BASE_MS + Math.random() * LOCK_RETRY_MAX_MS);
|
|
423
417
|
}
|
|
424
418
|
}
|
|
425
419
|
/** Remove a lock left behind by a dead process or one held implausibly long. */
|
|
426
|
-
breakStaleLock(lockPath) {
|
|
420
|
+
async breakStaleLock(lockPath) {
|
|
427
421
|
try {
|
|
428
|
-
const holder = JSON.parse(fs.
|
|
422
|
+
const holder = JSON.parse(await fs.readFile(lockPath, UTF8_ENCODING));
|
|
429
423
|
const expired = typeof holder.time === "number" && Date.now() - holder.time > LOCK_STALE_MS;
|
|
430
424
|
const dead = typeof holder.pid === "number" && !isProcessAlive(holder.pid);
|
|
431
425
|
if (!expired && !dead) return false;
|
|
432
|
-
fs.
|
|
426
|
+
await fs.unlink(lockPath);
|
|
433
427
|
return true;
|
|
434
428
|
} catch (error) {
|
|
435
429
|
if (error.code !== MISSING_FILE_CODE) this.report?.warn(TASK_EVENT.storeLockBreakFailed, error, { [STORE_PATH_ATTRIBUTE]: lockPath });
|
|
@@ -1031,6 +1025,37 @@ async function assignmentBatch(manager, assignments, signal) {
|
|
|
1031
1025
|
}
|
|
1032
1026
|
return result;
|
|
1033
1027
|
}
|
|
1028
|
+
/** One task action against the session store, shared by the `task` tool and the `tasks` code-mode namespace. */
|
|
1029
|
+
async function runTaskAction(store, manager, maxTasks, rawParams, signal, onUpdate) {
|
|
1030
|
+
if (!Check(TaskParamsSchema, rawParams)) {
|
|
1031
|
+
const [first] = Errors(TaskParamsSchema, rawParams);
|
|
1032
|
+
return failure(`Invalid task parameters${first ? `: ${first.instancePath || "/"} ${first.message}` : ""}.`);
|
|
1033
|
+
}
|
|
1034
|
+
const params = rawParams;
|
|
1035
|
+
try {
|
|
1036
|
+
if ((params.action === "assign" || params.action === "cancel") && !manager) throw new Error("Delegation is not available on this connection.");
|
|
1037
|
+
if (params.action === "assign") {
|
|
1038
|
+
if (!params.assignments?.length) throw new Error("assign requires a non-empty assignments[] array");
|
|
1039
|
+
onUpdate?.(output(`Delegating ${params.assignments.length} task${params.assignments.length === 1 ? "" : "s"}...`));
|
|
1040
|
+
const items = await assignmentBatch(manager, params.assignments, signal);
|
|
1041
|
+
const assigned = items.filter((item) => item.ok).map((item) => item.id);
|
|
1042
|
+
const text = formatAssignmentResults(items);
|
|
1043
|
+
if (assigned.length === 0) throw new Error(text);
|
|
1044
|
+
return buildAssignmentResult(params, store.snapshot, text, {
|
|
1045
|
+
assigned,
|
|
1046
|
+
failed: items.length - assigned.length
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1049
|
+
if (params.action === "cancel") {
|
|
1050
|
+
const outcome = await manager.cancel(params.id ?? NaN);
|
|
1051
|
+
if (!outcome.ok) throw new Error(outcome.message);
|
|
1052
|
+
return buildTextResult("cancel", params, store.snapshot, outcome.message);
|
|
1053
|
+
}
|
|
1054
|
+
return reducerAction(store, params.action, params, maxTasks);
|
|
1055
|
+
} catch (error) {
|
|
1056
|
+
return failure(error);
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1034
1059
|
function createHeadlessTaskTool(store, manager, maxTasks) {
|
|
1035
1060
|
return {
|
|
1036
1061
|
name: "task",
|
|
@@ -1039,33 +1064,7 @@ function createHeadlessTaskTool(store, manager, maxTasks) {
|
|
|
1039
1064
|
parameters: TaskParamsSchema,
|
|
1040
1065
|
promptSnippet: "Track complex work persistently and delegate ready tasks",
|
|
1041
1066
|
executionMode: "serial",
|
|
1042
|
-
|
|
1043
|
-
if (!Check(TaskParamsSchema, rawParams)) return failure("Invalid task parameters.");
|
|
1044
|
-
const params = rawParams;
|
|
1045
|
-
try {
|
|
1046
|
-
if ((params.action === "assign" || params.action === "cancel") && !manager) throw new Error("Delegation is not available on this connection.");
|
|
1047
|
-
if (params.action === "assign") {
|
|
1048
|
-
if (!params.assignments?.length) throw new Error("assign requires a non-empty assignments[] array");
|
|
1049
|
-
onUpdate?.(output(`Delegating ${params.assignments.length} task${params.assignments.length === 1 ? "" : "s"}...`));
|
|
1050
|
-
const items = await assignmentBatch(manager, params.assignments, signal);
|
|
1051
|
-
const assigned = items.filter((item) => item.ok).map((item) => item.id);
|
|
1052
|
-
const text = formatAssignmentResults(items);
|
|
1053
|
-
if (assigned.length === 0) throw new Error(text);
|
|
1054
|
-
return buildAssignmentResult(params, store.snapshot, text, {
|
|
1055
|
-
assigned,
|
|
1056
|
-
failed: items.length - assigned.length
|
|
1057
|
-
});
|
|
1058
|
-
}
|
|
1059
|
-
if (params.action === "cancel") {
|
|
1060
|
-
const outcome = await manager.cancel(params.id ?? NaN);
|
|
1061
|
-
if (!outcome.ok) throw new Error(outcome.message);
|
|
1062
|
-
return buildTextResult("cancel", params, store.snapshot, outcome.message);
|
|
1063
|
-
}
|
|
1064
|
-
return reducerAction(store, params.action, params, maxTasks);
|
|
1065
|
-
} catch (error) {
|
|
1066
|
-
return failure(error);
|
|
1067
|
-
}
|
|
1068
|
-
}
|
|
1067
|
+
execute: (_toolCallId, rawParams, signal, onUpdate) => runTaskAction(store, manager, maxTasks, rawParams, signal, onUpdate)
|
|
1069
1068
|
};
|
|
1070
1069
|
}
|
|
1071
1070
|
//#endregion
|