@operad-io/dev 0.1.1 → 0.2.0
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/README.md +1 -1
- package/dev.schema.json +41 -28
- package/package.json +9 -6
- package/skills/setup/SKILL.md +57 -0
- package/src/access-grants.ts +59 -0
- package/src/actions.ts +70 -16
- package/src/announce.ts +128 -16
- package/src/chat.ts +512 -36
- package/src/check-host.ts +111 -0
- package/src/check-load.ts +67 -0
- package/src/check.ts +17 -12
- package/src/clock.ts +29 -0
- package/src/commands.ts +103 -34
- package/src/create-actions.ts +210 -0
- package/src/flaky.ts +45 -29
- package/src/flow-compiler.ts +155 -68
- package/src/followups.ts +20 -22
- package/src/gate.ts +192 -73
- package/src/git.ts +47 -0
- package/src/index.ts +46 -6
- package/src/integrate.ts +82 -42
- package/src/integration-queue.ts +23 -10
- package/src/lock.ts +101 -5
- package/src/mainclone.ts +3 -3
- package/src/model-error.ts +70 -0
- package/src/model.ts +48 -35
- package/src/notcode.ts +51 -15
- package/src/places.ts +2 -2
- package/src/prepare.ts +7 -2
- package/src/project-flows.ts +135 -4
- package/src/project-settings.ts +81 -0
- package/src/register-requests.ts +87 -0
- package/src/repository-key.ts +4 -0
- package/src/rerun.ts +23 -7
- package/src/retry.ts +2 -12
- package/src/rework.ts +8 -0
- package/src/schedule.ts +317 -86
- package/src/service.ts +116 -152
- package/src/settings.ts +305 -60
- package/src/standing.ts +23 -6
- package/src/step-edge.ts +22 -0
- package/src/steps.ts +469 -123
- package/src/throughput.ts +4 -21
- package/src/timeouts.ts +10 -2
- package/src/views.ts +147 -81
- package/src/waits.ts +59 -0
package/src/service.ts
CHANGED
|
@@ -10,17 +10,16 @@ import {
|
|
|
10
10
|
writeFileSync,
|
|
11
11
|
} from "node:fs";
|
|
12
12
|
import { homedir } from "node:os";
|
|
13
|
-
import { basename,
|
|
14
|
-
import {
|
|
13
|
+
import { basename, isAbsolute, join, relative, resolve } from "node:path";
|
|
14
|
+
import { ViewError } from "@operad-io/engine";
|
|
15
15
|
import { isBusy } from "@operad-io/engine/platform";
|
|
16
|
-
import type { FlowDefinition, ObjectStore,
|
|
16
|
+
import type { FlowDefinition, ObjectStore, StoredObject } from "@operad-io/engine";
|
|
17
17
|
import { git } from "./git.ts";
|
|
18
18
|
import { withdrawIntegration } from "./integration-queue.ts";
|
|
19
19
|
import { withRepositoryLock } from "./lock.ts";
|
|
20
20
|
import {
|
|
21
21
|
appendChange,
|
|
22
|
-
|
|
23
|
-
bareId,
|
|
22
|
+
idOfKey,
|
|
24
23
|
dependencyKey,
|
|
25
24
|
dependencyLabel,
|
|
26
25
|
DevError,
|
|
@@ -67,7 +66,7 @@ import { DEFAULT_DEV_SETTINGS, DEV_SETTINGS_SCHEMA } from "./settings.ts";
|
|
|
67
66
|
/** An optional way for the dev plugin to ask the kernel to cancel a run. */
|
|
68
67
|
export interface DevRunControl {
|
|
69
68
|
/** `flow` is the run's own graph, when the task stores one the loaded plugins lack. */
|
|
70
|
-
cancel(runId: string, flow?: FlowDefinition): Promise<void> | void;
|
|
69
|
+
cancel(runId: string, flow?: FlowDefinition): Promise<boolean | void> | boolean | void;
|
|
71
70
|
}
|
|
72
71
|
|
|
73
72
|
export interface ResolveRepositoryOptions {
|
|
@@ -483,7 +482,6 @@ function writeSettings(repositoryPath: string, name: string): void {
|
|
|
483
482
|
mainBranch: DEFAULT_DEV_SETTINGS.mainBranch,
|
|
484
483
|
worktreeRoot: DEFAULT_DEV_SETTINGS.worktreeRoot,
|
|
485
484
|
concurrency: DEFAULT_DEV_SETTINGS.concurrency,
|
|
486
|
-
worker: DEFAULT_DEV_SETTINGS.worker,
|
|
487
485
|
workerBrief: DEFAULT_DEV_SETTINGS.workerBrief,
|
|
488
486
|
},
|
|
489
487
|
null,
|
|
@@ -493,6 +491,28 @@ function writeSettings(repositoryPath: string, name: string): void {
|
|
|
493
491
|
);
|
|
494
492
|
}
|
|
495
493
|
|
|
494
|
+
/**
|
|
495
|
+
* Whether a repository has a remote. `git remote` prints nothing both for a
|
|
496
|
+
* repository with no remote and, under heavy load, sometimes for one that has
|
|
497
|
+
* one: git exits 0 with empty output. An empty answer is therefore confirmed by
|
|
498
|
+
* a query whose exit status is the answer: `git config --get-regexp` exits 1
|
|
499
|
+
* when no remote is configured. Its output is not read. The pattern needs the
|
|
500
|
+
* second dot that makes the key a remote's own key (`remote.<name>.<key>`):
|
|
501
|
+
* `remote.pushDefault` is a key of the `remote` section, not a remote.
|
|
502
|
+
*/
|
|
503
|
+
function repositoryHasRemote(
|
|
504
|
+
path: string,
|
|
505
|
+
): { readonly present: boolean; readonly err: string } {
|
|
506
|
+
const remotes = git(path, ["remote"]);
|
|
507
|
+
if (remotes.out.length > 0) return { present: true, err: "" };
|
|
508
|
+
const configured = git(path, ["config", "--local", "--get-regexp", "^remote\\..*\\."]);
|
|
509
|
+
if (configured.ok) return { present: true, err: "" };
|
|
510
|
+
return {
|
|
511
|
+
present: false,
|
|
512
|
+
err: remotes.err.length > 0 ? remotes.err : configured.err,
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
|
|
496
516
|
/** Registers a git work tree that has a remote. */
|
|
497
517
|
export async function addRepository(
|
|
498
518
|
store: ObjectStore,
|
|
@@ -520,20 +540,22 @@ export async function addRepository(
|
|
|
520
540
|
if (bare.ok && bare.out === "true") {
|
|
521
541
|
throw new DevError("path", `"${path}" is a bare repository`);
|
|
522
542
|
}
|
|
523
|
-
const
|
|
524
|
-
if (!
|
|
543
|
+
const remote = repositoryHasRemote(path);
|
|
544
|
+
if (!remote.present) {
|
|
525
545
|
throw new DevError(
|
|
526
546
|
"path",
|
|
527
|
-
`"${path}" has no remote${
|
|
547
|
+
`"${path}" has no remote${remote.err.length > 0 ? `: ${remote.err}` : ""}`,
|
|
528
548
|
);
|
|
529
549
|
}
|
|
530
550
|
|
|
531
551
|
const name = validateRepositoryName(options.name ?? basename(path));
|
|
532
|
-
const existing = await findRepository(store, name);
|
|
533
|
-
|
|
552
|
+
const existing = await findRepository(store, name, { includeRemoved: true });
|
|
553
|
+
const previous =
|
|
554
|
+
existing === undefined ? undefined : repositoryData(existing.data);
|
|
555
|
+
if (previous !== undefined && !previous.removed) {
|
|
534
556
|
throw new DevError(
|
|
535
557
|
"name",
|
|
536
|
-
`repository "${name}" is already registered at "${
|
|
558
|
+
`repository "${name}" is already registered at "${previous.path}"`,
|
|
537
559
|
);
|
|
538
560
|
}
|
|
539
561
|
const samePath = (await listRepositories(store)).find(
|
|
@@ -546,14 +568,19 @@ export async function addRepository(
|
|
|
546
568
|
);
|
|
547
569
|
}
|
|
548
570
|
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
571
|
+
// A removed repository is registered again under its name: its counters and
|
|
572
|
+
// every plan and task under that name stay, and only its path changes.
|
|
573
|
+
const data: RepositoryData =
|
|
574
|
+
previous === undefined
|
|
575
|
+
? {
|
|
576
|
+
name,
|
|
577
|
+
path,
|
|
578
|
+
removed: false,
|
|
579
|
+
openPlans: 0,
|
|
580
|
+
openTasks: 0,
|
|
581
|
+
activeTasks: 0,
|
|
582
|
+
}
|
|
583
|
+
: { ...previous, name, path, removed: false };
|
|
557
584
|
await store.put(REPOSITORY_TYPE, name, data, "dev:repo-add");
|
|
558
585
|
writeSettings(path, name);
|
|
559
586
|
ensureExcludes(path);
|
|
@@ -628,7 +655,7 @@ async function tasksOfPlan(
|
|
|
628
655
|
planKey: string,
|
|
629
656
|
): Promise<readonly StoredObject[]> {
|
|
630
657
|
const repository = keyRepository(planKey);
|
|
631
|
-
const plan =
|
|
658
|
+
const plan = idOfKey(planKey);
|
|
632
659
|
return (await allTasks(store)).filter((object) => {
|
|
633
660
|
const task = taskData(object.data);
|
|
634
661
|
return task.repository === repository && task.plan === plan;
|
|
@@ -649,14 +676,14 @@ function refuseTask(
|
|
|
649
676
|
if (action === "confirm" && task.phase === "proposed" && plan?.state === "confirmed") {
|
|
650
677
|
return false;
|
|
651
678
|
}
|
|
652
|
-
const said = taskLine(action, task, { id:
|
|
679
|
+
const said = taskLine(action, task, { id: idOfKey(key), plan });
|
|
653
680
|
if (said?.kind === "refuse") throw new DevRefusal(said.text);
|
|
654
681
|
return said !== undefined;
|
|
655
682
|
}
|
|
656
683
|
|
|
657
684
|
/** As `refuseTask`, for a plan action. */
|
|
658
685
|
function refusePlan(action: PlanActionName, plan: PlanData, key: string): boolean {
|
|
659
|
-
const said = planLine(action, plan, { id:
|
|
686
|
+
const said = planLine(action, plan, { id: idOfKey(key) });
|
|
660
687
|
if (said?.kind === "refuse") throw new DevRefusal(said.text);
|
|
661
688
|
return said !== undefined;
|
|
662
689
|
}
|
|
@@ -667,7 +694,7 @@ export async function getPlan(
|
|
|
667
694
|
): Promise<StoredObject> {
|
|
668
695
|
const object = await store.get(PLAN_TYPE, key);
|
|
669
696
|
if (object === undefined) {
|
|
670
|
-
throw new DevError("plan", `no plan "${
|
|
697
|
+
throw new DevError("plan", `no plan "${idOfKey(key)}"`);
|
|
671
698
|
}
|
|
672
699
|
return object;
|
|
673
700
|
}
|
|
@@ -678,7 +705,7 @@ export async function getTask(
|
|
|
678
705
|
): Promise<StoredObject> {
|
|
679
706
|
const object = await store.get(TASK_TYPE, key);
|
|
680
707
|
if (object === undefined) {
|
|
681
|
-
throw new DevError("task", `no task "${
|
|
708
|
+
throw new DevError("task", `no task "${idOfKey(key)}"`);
|
|
682
709
|
}
|
|
683
710
|
return object;
|
|
684
711
|
}
|
|
@@ -773,9 +800,10 @@ function sameCostTotals(a: PlanCostTotals | undefined, b: PlanCostTotals): boole
|
|
|
773
800
|
export async function refreshPlanCounts(
|
|
774
801
|
store: ObjectStore,
|
|
775
802
|
plan: StoredObject,
|
|
803
|
+
tasks?: readonly StoredObject[] | undefined,
|
|
776
804
|
): Promise<StoredObject> {
|
|
777
805
|
try {
|
|
778
|
-
return await recountPlan(store, plan);
|
|
806
|
+
return await recountPlan(store, plan, tasks);
|
|
779
807
|
} catch (error) {
|
|
780
808
|
if (isBusy(error)) return plan;
|
|
781
809
|
throw error;
|
|
@@ -794,9 +822,10 @@ async function refreshPlanCountsOf(store: ObjectStore, key: string): Promise<voi
|
|
|
794
822
|
async function recountPlan(
|
|
795
823
|
store: ObjectStore,
|
|
796
824
|
plan: StoredObject,
|
|
825
|
+
knownTasks?: readonly StoredObject[] | undefined,
|
|
797
826
|
): Promise<StoredObject> {
|
|
798
827
|
const data = planData(plan.data);
|
|
799
|
-
const tasks = await tasksOfPlan(store, plan.id);
|
|
828
|
+
const tasks = knownTasks ?? (await tasksOfPlan(store, plan.id));
|
|
800
829
|
const taskCount = tasks.length;
|
|
801
830
|
const mergedCount = tasks.filter(
|
|
802
831
|
(object) => taskData(object.data).phase === "merged",
|
|
@@ -1027,7 +1056,7 @@ export async function addTask(
|
|
|
1027
1056
|
const plan = await getPlan(store, options.plan);
|
|
1028
1057
|
const planObject = planData(plan.data);
|
|
1029
1058
|
if (planObject.status === "cancelled") {
|
|
1030
|
-
throw new DevError("plan", `plan "${
|
|
1059
|
+
throw new DevError("plan", `plan "${idOfKey(plan.id)}" is cancelled`);
|
|
1031
1060
|
}
|
|
1032
1061
|
await devTestHooks.beforeLock?.("task-add");
|
|
1033
1062
|
const names = await afterLockNames(
|
|
@@ -1053,13 +1082,13 @@ export async function addTaskLocked(
|
|
|
1053
1082
|
if (current.status === "cancelled") {
|
|
1054
1083
|
throw new DevError(
|
|
1055
1084
|
"plan",
|
|
1056
|
-
`plan "${
|
|
1085
|
+
`plan "${idOfKey(currentPlan.id)}" is cancelled`,
|
|
1057
1086
|
);
|
|
1058
1087
|
}
|
|
1059
1088
|
if (current.repository !== repository.name) {
|
|
1060
1089
|
throw new DevError(
|
|
1061
1090
|
"plan",
|
|
1062
|
-
`plan "${
|
|
1091
|
+
`plan "${idOfKey(currentPlan.id)}" is not in repository "${repository.name}"`,
|
|
1063
1092
|
);
|
|
1064
1093
|
}
|
|
1065
1094
|
const id = await nextId(store, "task", repository.name, slug);
|
|
@@ -1076,7 +1105,7 @@ export async function addTaskLocked(
|
|
|
1076
1105
|
options.area === undefined ? undefined : validateArea(options.area);
|
|
1077
1106
|
const data: TaskData = {
|
|
1078
1107
|
repository: repository.name,
|
|
1079
|
-
plan:
|
|
1108
|
+
plan: idOfKey(currentPlan.id),
|
|
1080
1109
|
title,
|
|
1081
1110
|
brief,
|
|
1082
1111
|
after,
|
|
@@ -1274,18 +1303,6 @@ export async function updateTask(
|
|
|
1274
1303
|
return updated.object;
|
|
1275
1304
|
}
|
|
1276
1305
|
|
|
1277
|
-
/** The task after a run changed its phase. Used by later tasks and by tests. */
|
|
1278
|
-
export async function setTaskPhase(
|
|
1279
|
-
store: ObjectStore,
|
|
1280
|
-
id: string,
|
|
1281
|
-
phase: TaskPhase,
|
|
1282
|
-
options: { readonly run?: string | null | undefined } = {},
|
|
1283
|
-
): Promise<StoredObject> {
|
|
1284
|
-
const written = await changeTaskPhase(store, id, undefined, phase, options);
|
|
1285
|
-
if (written === undefined) throw new DevError("task", `no task "${bareId(id)}"`);
|
|
1286
|
-
return written;
|
|
1287
|
-
}
|
|
1288
|
-
|
|
1289
1306
|
/**
|
|
1290
1307
|
* Moves a task to `to` only while it is still in phase `from`, checked under
|
|
1291
1308
|
* the repository lock; undefined when another pass already moved it, so only
|
|
@@ -1301,7 +1318,7 @@ export async function moveTaskPhase(
|
|
|
1301
1318
|
return changeTaskPhase(store, id, from, to, options);
|
|
1302
1319
|
}
|
|
1303
1320
|
|
|
1304
|
-
async function changeTaskPhase(
|
|
1321
|
+
export async function changeTaskPhase(
|
|
1305
1322
|
store: ObjectStore,
|
|
1306
1323
|
id: string,
|
|
1307
1324
|
from: TaskPhase | undefined,
|
|
@@ -1374,12 +1391,11 @@ export async function claimTaskStart(
|
|
|
1374
1391
|
const next: TaskData = {
|
|
1375
1392
|
...rest,
|
|
1376
1393
|
...(options.oldestPlanSlot === true ? { oldestPlanSlot: true } : {}),
|
|
1394
|
+
// The recorded graph follows the flow the start uses: a built-in flow
|
|
1395
|
+
// records none, so a refused graph an older dev wrote is not kept.
|
|
1377
1396
|
...(options.flow === undefined
|
|
1378
1397
|
? {}
|
|
1379
|
-
: {
|
|
1380
|
-
flowName: options.flow.name,
|
|
1381
|
-
...(options.flow.graph === undefined ? {} : { flowGraph: options.flow.graph }),
|
|
1382
|
-
}),
|
|
1398
|
+
: { flowName: options.flow.name, flowGraph: options.flow.graph }),
|
|
1383
1399
|
phase: "running",
|
|
1384
1400
|
run: null,
|
|
1385
1401
|
brief: appendChange(latest.brief, "running"),
|
|
@@ -1402,7 +1418,7 @@ export async function areaHolder(
|
|
|
1402
1418
|
const task = taskData(object.data);
|
|
1403
1419
|
if (task.repository !== repository || task.area !== area) continue;
|
|
1404
1420
|
if (task.phase === "running" || task.phase === "review") {
|
|
1405
|
-
return
|
|
1421
|
+
return idOfKey(object.id);
|
|
1406
1422
|
}
|
|
1407
1423
|
}
|
|
1408
1424
|
return undefined;
|
|
@@ -1417,17 +1433,17 @@ export async function setAreaHold(
|
|
|
1417
1433
|
id: string,
|
|
1418
1434
|
holder: string | undefined,
|
|
1419
1435
|
ahead = 0,
|
|
1420
|
-
|
|
1436
|
+
known?: TaskData | undefined,
|
|
1437
|
+
): Promise<boolean> {
|
|
1421
1438
|
const same = (task: TaskData): boolean =>
|
|
1422
1439
|
task.areaHeldBy === holder &&
|
|
1423
1440
|
(holder === undefined || (task.areaAhead ?? 0) === ahead);
|
|
1424
|
-
const initial = await getTask(store, id);
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
await withRepoLock(store, data.repository, async () => {
|
|
1441
|
+
const initial = known ?? taskData((await getTask(store, id)).data);
|
|
1442
|
+
if (same(initial)) return false;
|
|
1443
|
+
return withRepoLock(store, initial.repository, async () => {
|
|
1428
1444
|
const current = await getTask(store, id);
|
|
1429
1445
|
const latest = taskData(current.data);
|
|
1430
|
-
if (latest.phase !== "ready" || same(latest)) return;
|
|
1446
|
+
if (latest.phase !== "ready" || same(latest)) return false;
|
|
1431
1447
|
const { areaHeldBy: _held, areaAhead: _ahead, ...rest } = latest;
|
|
1432
1448
|
await writeTask(
|
|
1433
1449
|
store,
|
|
@@ -1439,6 +1455,7 @@ export async function setAreaHold(
|
|
|
1439
1455
|
},
|
|
1440
1456
|
"dev:task-area-hold",
|
|
1441
1457
|
);
|
|
1458
|
+
return true;
|
|
1442
1459
|
});
|
|
1443
1460
|
}
|
|
1444
1461
|
|
|
@@ -1451,15 +1468,18 @@ export async function setDependencyHold(
|
|
|
1451
1468
|
id: string,
|
|
1452
1469
|
held: boolean,
|
|
1453
1470
|
waitingFor: readonly string[] = [],
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
const
|
|
1471
|
+
known?: TaskData | undefined,
|
|
1472
|
+
): Promise<boolean> {
|
|
1473
|
+
const initial = known ?? taskData((await getTask(store, id)).data);
|
|
1457
1474
|
const same = (left: readonly string[] | undefined) =>
|
|
1458
1475
|
(left ?? []).join("\n") === waitingFor.join("\n");
|
|
1459
|
-
if (
|
|
1460
|
-
|
|
1476
|
+
if (
|
|
1477
|
+
(initial.dependencyHeld === true) === held &&
|
|
1478
|
+
(!held || same(initial.dependencyHeldFor))
|
|
1479
|
+
) {
|
|
1480
|
+
return false;
|
|
1461
1481
|
}
|
|
1462
|
-
|
|
1482
|
+
return withRepoLock(store, initial.repository, async () => {
|
|
1463
1483
|
const current = await getTask(store, id);
|
|
1464
1484
|
const latest = taskData(current.data);
|
|
1465
1485
|
if (
|
|
@@ -1467,7 +1487,7 @@ export async function setDependencyHold(
|
|
|
1467
1487
|
((latest.dependencyHeld === true) === held &&
|
|
1468
1488
|
(!held || same(latest.dependencyHeldFor)))
|
|
1469
1489
|
) {
|
|
1470
|
-
return;
|
|
1490
|
+
return false;
|
|
1471
1491
|
}
|
|
1472
1492
|
const { dependencyHeld: _waits, dependencyHeldFor: _for, ...rest } = latest;
|
|
1473
1493
|
await writeTask(
|
|
@@ -1481,6 +1501,7 @@ export async function setDependencyHold(
|
|
|
1481
1501
|
},
|
|
1482
1502
|
"dev:task-dependency-hold",
|
|
1483
1503
|
);
|
|
1504
|
+
return true;
|
|
1484
1505
|
});
|
|
1485
1506
|
}
|
|
1486
1507
|
|
|
@@ -1493,14 +1514,14 @@ export async function setSlotHold(
|
|
|
1493
1514
|
store: ObjectStore,
|
|
1494
1515
|
id: string,
|
|
1495
1516
|
note: string | undefined,
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
const
|
|
1499
|
-
if (
|
|
1500
|
-
|
|
1517
|
+
known?: TaskData | undefined,
|
|
1518
|
+
): Promise<boolean> {
|
|
1519
|
+
const initial = known ?? taskData((await getTask(store, id)).data);
|
|
1520
|
+
if (initial.slotHeld === note) return false;
|
|
1521
|
+
return withRepoLock(store, initial.repository, async () => {
|
|
1501
1522
|
const current = await getTask(store, id);
|
|
1502
1523
|
const latest = taskData(current.data);
|
|
1503
|
-
if (latest.phase !== "ready" || latest.slotHeld === note) return;
|
|
1524
|
+
if (latest.phase !== "ready" || latest.slotHeld === note) return false;
|
|
1504
1525
|
const { slotHeld: _slot, ...rest } = latest;
|
|
1505
1526
|
await writeTask(
|
|
1506
1527
|
store,
|
|
@@ -1508,6 +1529,7 @@ export async function setSlotHold(
|
|
|
1508
1529
|
{ ...rest, ...(note === undefined ? {} : { slotHeld: note }) },
|
|
1509
1530
|
"dev:task-slot-hold",
|
|
1510
1531
|
);
|
|
1532
|
+
return true;
|
|
1511
1533
|
});
|
|
1512
1534
|
}
|
|
1513
1535
|
|
|
@@ -1519,15 +1541,16 @@ export async function setFlowNote(
|
|
|
1519
1541
|
store: ObjectStore,
|
|
1520
1542
|
id: string,
|
|
1521
1543
|
note: { readonly shown?: string | undefined; readonly held?: string | undefined },
|
|
1522
|
-
|
|
1523
|
-
|
|
1544
|
+
known?: TaskData | undefined,
|
|
1545
|
+
): Promise<boolean> {
|
|
1546
|
+
const initial = known ?? taskData((await getTask(store, id)).data);
|
|
1524
1547
|
const same = (data: TaskData) =>
|
|
1525
1548
|
data.flowShown === note.shown && data.flowHeld === note.held;
|
|
1526
|
-
if (same(
|
|
1527
|
-
|
|
1549
|
+
if (same(initial)) return false;
|
|
1550
|
+
return withRepoLock(store, initial.repository, async () => {
|
|
1528
1551
|
const current = await getTask(store, id);
|
|
1529
1552
|
const latest = taskData(current.data);
|
|
1530
|
-
if (same(latest)) return;
|
|
1553
|
+
if (same(latest)) return false;
|
|
1531
1554
|
const { flowShown: _shown, flowHeld: _held, ...rest } = latest;
|
|
1532
1555
|
await writeTask(
|
|
1533
1556
|
store,
|
|
@@ -1539,6 +1562,7 @@ export async function setFlowNote(
|
|
|
1539
1562
|
},
|
|
1540
1563
|
"dev:task-flow-note",
|
|
1541
1564
|
);
|
|
1565
|
+
return true;
|
|
1542
1566
|
});
|
|
1543
1567
|
}
|
|
1544
1568
|
|
|
@@ -1568,17 +1592,18 @@ export async function recordPlanStart(
|
|
|
1568
1592
|
export async function clearOldestPlanSlot(
|
|
1569
1593
|
store: ObjectStore,
|
|
1570
1594
|
id: string,
|
|
1571
|
-
): Promise<
|
|
1595
|
+
): Promise<boolean> {
|
|
1572
1596
|
const initial = await getTask(store, id);
|
|
1573
1597
|
const data = taskData(initial.data);
|
|
1574
|
-
if (data.oldestPlanSlot !== true) return;
|
|
1575
|
-
|
|
1598
|
+
if (data.oldestPlanSlot !== true) return false;
|
|
1599
|
+
return withRepoLock(store, data.repository, async () => {
|
|
1576
1600
|
const current = await getTask(store, id);
|
|
1577
1601
|
const latest = taskData(current.data);
|
|
1578
|
-
if (latest.oldestPlanSlot !== true) return;
|
|
1579
|
-
if (latest.phase === "running" || latest.phase === "review") return;
|
|
1602
|
+
if (latest.oldestPlanSlot !== true) return false;
|
|
1603
|
+
if (latest.phase === "running" || latest.phase === "review") return false;
|
|
1580
1604
|
const { oldestPlanSlot: _slot, ...rest } = latest;
|
|
1581
1605
|
await writeTask(store, id, rest, "dev:task-slot-release");
|
|
1606
|
+
return true;
|
|
1582
1607
|
});
|
|
1583
1608
|
}
|
|
1584
1609
|
|
|
@@ -1700,7 +1725,7 @@ export async function requestTaskStart(
|
|
|
1700
1725
|
): Promise<StoredObject> {
|
|
1701
1726
|
const initial = await getTask(store, id);
|
|
1702
1727
|
const data = taskData(initial.data);
|
|
1703
|
-
const at = `task "${
|
|
1728
|
+
const at = `task "${idOfKey(id)}"`;
|
|
1704
1729
|
if (data.phase !== "ready") {
|
|
1705
1730
|
throw new DevError(
|
|
1706
1731
|
"phase",
|
|
@@ -1771,12 +1796,12 @@ export async function claimWaitingTask(
|
|
|
1771
1796
|
const latest = taskData(current.data);
|
|
1772
1797
|
// Where the task is now: the table's line for this action. A result that
|
|
1773
1798
|
// is already true (another merge won) succeeds with its line.
|
|
1774
|
-
const said = taskLine(action, latest, { id:
|
|
1799
|
+
const said = taskLine(action, latest, { id: idOfKey(id) });
|
|
1775
1800
|
if (said?.kind === "done") return { settled: said.text };
|
|
1776
1801
|
refuseTask(action, latest, id);
|
|
1777
1802
|
if (current.version !== seen) {
|
|
1778
1803
|
throw new DevRefusal(
|
|
1779
|
-
`${
|
|
1804
|
+
`${idOfKey(id)} changed since you looked; look again, then dev:${action}`,
|
|
1780
1805
|
);
|
|
1781
1806
|
}
|
|
1782
1807
|
const claimed = await writeTask(
|
|
@@ -1804,27 +1829,6 @@ export async function releaseWaitingClaim(
|
|
|
1804
1829
|
});
|
|
1805
1830
|
}
|
|
1806
1831
|
|
|
1807
|
-
/** Appends a rework section and records it. */
|
|
1808
|
-
export async function addRework(
|
|
1809
|
-
store: ObjectStore,
|
|
1810
|
-
id: string,
|
|
1811
|
-
source: string,
|
|
1812
|
-
text: string,
|
|
1813
|
-
): Promise<StoredObject> {
|
|
1814
|
-
const initial = await getTask(store, id);
|
|
1815
|
-
const data = taskData(initial.data);
|
|
1816
|
-
return withRepoLock(store, data.repository, async () => {
|
|
1817
|
-
const current = await getTask(store, id);
|
|
1818
|
-
const latest = taskData(current.data);
|
|
1819
|
-
return writeTask(
|
|
1820
|
-
store,
|
|
1821
|
-
id,
|
|
1822
|
-
{ ...latest, brief: appendRework(latest.brief, source, text) },
|
|
1823
|
-
"dev:task-rework",
|
|
1824
|
-
);
|
|
1825
|
-
});
|
|
1826
|
-
}
|
|
1827
|
-
|
|
1828
1832
|
export async function confirmPlan(
|
|
1829
1833
|
store: ObjectStore,
|
|
1830
1834
|
id: string,
|
|
@@ -1909,17 +1913,6 @@ interface CancelledTasks {
|
|
|
1909
1913
|
readonly merged: readonly string[];
|
|
1910
1914
|
}
|
|
1911
1915
|
|
|
1912
|
-
/** Where a cancel finds the integration queue: the home the action runs in. */
|
|
1913
|
-
function cancelHome(
|
|
1914
|
-
store: ObjectStore,
|
|
1915
|
-
options: CancelOptions,
|
|
1916
|
-
): string | undefined {
|
|
1917
|
-
if (options.home !== undefined) return options.home;
|
|
1918
|
-
// Before this option, a cancel called the service directly: the default
|
|
1919
|
-
// store sits at `<home>/store`, so that home still finds the queue.
|
|
1920
|
-
return basename(store.root) === "store" ? dirname(store.root) : undefined;
|
|
1921
|
-
}
|
|
1922
|
-
|
|
1923
1916
|
async function cancelTasks(
|
|
1924
1917
|
store: ObjectStore,
|
|
1925
1918
|
tasks: readonly StoredObject[],
|
|
@@ -1935,7 +1928,7 @@ async function cancelTasks(
|
|
|
1935
1928
|
const withdrawal = await withdrawIntegration(
|
|
1936
1929
|
home,
|
|
1937
1930
|
{ name: data.repository, path: repositoryPath },
|
|
1938
|
-
|
|
1931
|
+
idOfKey(object.id),
|
|
1939
1932
|
);
|
|
1940
1933
|
if (withdrawal.kind === "merged") {
|
|
1941
1934
|
merged.push(object.id);
|
|
@@ -1961,7 +1954,10 @@ async function cancelTasks(
|
|
|
1961
1954
|
|
|
1962
1955
|
export interface CancelOptions {
|
|
1963
1956
|
readonly runs?: DevRunControl | undefined;
|
|
1964
|
-
/**
|
|
1957
|
+
/**
|
|
1958
|
+
* The operad home, where the integration queue lives. Without it a cancel
|
|
1959
|
+
* does not look at the queue: only the action, which knows the home, passes it.
|
|
1960
|
+
*/
|
|
1965
1961
|
readonly home?: string | undefined;
|
|
1966
1962
|
}
|
|
1967
1963
|
|
|
@@ -1983,7 +1979,7 @@ export async function cancelPlan(
|
|
|
1983
1979
|
}> {
|
|
1984
1980
|
const initial = await getPlan(store, id);
|
|
1985
1981
|
const initialData = planData(initial.data);
|
|
1986
|
-
const home =
|
|
1982
|
+
const { home } = options;
|
|
1987
1983
|
const cancelled = await withRepoLock(
|
|
1988
1984
|
store,
|
|
1989
1985
|
initialData.repository,
|
|
@@ -2010,7 +2006,7 @@ export async function cancelTask(
|
|
|
2010
2006
|
): Promise<CancelledTask> {
|
|
2011
2007
|
const initial = await getTask(store, id);
|
|
2012
2008
|
const initialData = taskData(initial.data);
|
|
2013
|
-
const home =
|
|
2009
|
+
const { home } = options;
|
|
2014
2010
|
const cancelled = await withRepoLock(
|
|
2015
2011
|
store,
|
|
2016
2012
|
initialData.repository,
|
|
@@ -2024,7 +2020,7 @@ export async function cancelTask(
|
|
|
2024
2020
|
const withdrawal = await withdrawIntegration(
|
|
2025
2021
|
home,
|
|
2026
2022
|
{ name: data.repository, path: fresh.path },
|
|
2027
|
-
|
|
2023
|
+
idOfKey(id),
|
|
2028
2024
|
);
|
|
2029
2025
|
if (withdrawal.kind === "merged") {
|
|
2030
2026
|
return { task, runs: [], merged: true };
|
|
@@ -2053,7 +2049,7 @@ export async function cancelTask(
|
|
|
2053
2049
|
task: cancelled.task,
|
|
2054
2050
|
runs: cancelled.runs,
|
|
2055
2051
|
...(cancelled.merged
|
|
2056
|
-
? { alreadyMerged: `${
|
|
2052
|
+
? { alreadyMerged: `${idOfKey(id)} was merged; nothing can be cancelled` }
|
|
2057
2053
|
: {}),
|
|
2058
2054
|
};
|
|
2059
2055
|
}
|
|
@@ -2191,35 +2187,3 @@ export async function setConcurrency(
|
|
|
2191
2187
|
);
|
|
2192
2188
|
});
|
|
2193
2189
|
}
|
|
2194
|
-
|
|
2195
|
-
/* ---------------------------------------------------------------------------
|
|
2196
|
-
* History
|
|
2197
|
-
* ------------------------------------------------------------------------- */
|
|
2198
|
-
|
|
2199
|
-
/** Rebuilds the objects a store's facts describe, in append order. */
|
|
2200
|
-
export function rebuildObjects(
|
|
2201
|
-
facts: readonly PluginFact[],
|
|
2202
|
-
): Map<string, Record<string, unknown>> {
|
|
2203
|
-
const objects = new Map<string, Record<string, unknown>>();
|
|
2204
|
-
for (const fact of facts) {
|
|
2205
|
-
const object = fact.object;
|
|
2206
|
-
if (object === undefined) continue;
|
|
2207
|
-
const key = `${object.type}:${object.id}`;
|
|
2208
|
-
const value = objectValueAfter(fact, objects.get(key) ?? {});
|
|
2209
|
-
if (value !== undefined) objects.set(key, { ...value });
|
|
2210
|
-
}
|
|
2211
|
-
return objects;
|
|
2212
|
-
}
|
|
2213
|
-
|
|
2214
|
-
/** The live object data, keyed the way `rebuildObjects` keys it. */
|
|
2215
|
-
export async function liveObjects(
|
|
2216
|
-
store: ObjectStore,
|
|
2217
|
-
): Promise<Map<string, Record<string, unknown>>> {
|
|
2218
|
-
const objects = new Map<string, Record<string, unknown>>();
|
|
2219
|
-
for (const type of [REPOSITORY_TYPE, PLAN_TYPE, TASK_TYPE]) {
|
|
2220
|
-
for (const object of await listAll(store, type)) {
|
|
2221
|
-
objects.set(`${type}:${object.id}`, { ...object.data });
|
|
2222
|
-
}
|
|
2223
|
-
}
|
|
2224
|
-
return objects;
|
|
2225
|
-
}
|