@xiangyixie/dsh-superagent 0.14.3 → 0.14.5
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/CHANGELOG.md +59 -0
- package/README.en.md +22 -10
- package/README.md +21 -9
- package/README.zh.md +26 -14
- package/bin/doctor.js +1 -1
- package/docs/LONG-GOAL.md +223 -0
- package/lib/doctor.js +2 -0
- package/lib/index.js +456 -194
- package/lib/long-goal.js +1705 -0
- package/lib/orchestrator.js +79 -16
- package/package.json +5 -3
package/lib/orchestrator.js
CHANGED
|
@@ -49,6 +49,15 @@ const HEARTBEAT_MS = 30 * 1000
|
|
|
49
49
|
const PLANNER_POLL_MS = 250
|
|
50
50
|
/** A run with no heartbeat for this long is treated as orphaned. */
|
|
51
51
|
const ORPHAN_MS = 3 * HEARTBEAT_MS
|
|
52
|
+
/**
|
|
53
|
+
* How long a declared deliverable is re-checked after a `ENOENT` before the
|
|
54
|
+
* check calls it missing. A worker's write can reach its own shell a moment
|
|
55
|
+
* before another process sees it on disk; this window covers that flush race.
|
|
56
|
+
* It is bounded on purpose — a file that never appears is still missing.
|
|
57
|
+
*/
|
|
58
|
+
const DELIVERABLE_GRACE_MS = 150
|
|
59
|
+
/** Gap between re-checks inside the deliverable grace window. */
|
|
60
|
+
const DELIVERABLE_RECHECK_MS = 50
|
|
52
61
|
/** A child that ignores abort must not hold a cancel call open forever. */
|
|
53
62
|
const DISPOSE_MS = 1500
|
|
54
63
|
/** Waking the owning session must not hold a finished run open forever. */
|
|
@@ -1378,14 +1387,30 @@ export function createOrchestrator(deps) {
|
|
|
1378
1387
|
let workspaceManagerRef = workspace
|
|
1379
1388
|
const workspaceManagers = new Map()
|
|
1380
1389
|
|
|
1390
|
+
/** Resolved, without a trailing separator, and case-folded on Windows. */
|
|
1391
|
+
function comparablePath(value) {
|
|
1392
|
+
const resolved = path.resolve(value)
|
|
1393
|
+
const trimmed = resolved.replace(/[\\/]+$/, '') || resolved
|
|
1394
|
+
return process.platform === 'win32' ? trimmed.toLowerCase() : trimmed
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1381
1397
|
/** Path comparison that ignores case and a trailing separator on Windows. */
|
|
1382
1398
|
function sameDirectory(left, right) {
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1399
|
+
return comparablePath(left) === comparablePath(right)
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
/**
|
|
1403
|
+
* Is `target` the directory `root`, or inside it?
|
|
1404
|
+
*
|
|
1405
|
+
* A declared path may arrive with either separator and, on Windows, in any
|
|
1406
|
+
* case. Comparing the resolved strings literally would reject a path that
|
|
1407
|
+
* names a file under the root, so both sides are compared the same way
|
|
1408
|
+
* `sameDirectory` compares directories.
|
|
1409
|
+
*/
|
|
1410
|
+
function insideDirectory(root, target) {
|
|
1411
|
+
const base = comparablePath(root)
|
|
1412
|
+
const resolved = comparablePath(target)
|
|
1413
|
+
return resolved === base || resolved.startsWith(base + path.sep)
|
|
1389
1414
|
}
|
|
1390
1415
|
|
|
1391
1416
|
/**
|
|
@@ -1546,10 +1571,49 @@ export function createOrchestrator(deps) {
|
|
|
1546
1571
|
|
|
1547
1572
|
/**
|
|
1548
1573
|
* Directory against which a subtask's declared deliverables are resolved:
|
|
1549
|
-
* its own checkout when isolated, the
|
|
1574
|
+
* its own checkout when isolated, otherwise the directory the workers were
|
|
1575
|
+
* actually told to work in.
|
|
1576
|
+
*
|
|
1577
|
+
* A goal-mode run carries that directory in `goalMode.cwd` — the same base
|
|
1578
|
+
* its machine checks and workspace fingerprints use — so the deliverable
|
|
1579
|
+
* check must honour it too. Falling straight through to this process's `cwd`
|
|
1580
|
+
* would read the host's launch directory instead, and a file the worker did
|
|
1581
|
+
* write would be reported as missing.
|
|
1550
1582
|
*/
|
|
1551
1583
|
function deliverableRoot(run, subtask) {
|
|
1552
|
-
return subtask.workspace?.dir
|
|
1584
|
+
return subtask.workspace?.dir
|
|
1585
|
+
?? run.workspace?.base
|
|
1586
|
+
?? run.goalMode?.cwd
|
|
1587
|
+
?? config.workspaceRoot
|
|
1588
|
+
?? cwd
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
/**
|
|
1592
|
+
* Stat a declared deliverable, re-reading it briefly before believing ENOENT.
|
|
1593
|
+
*
|
|
1594
|
+
* A file system can expose a write to the shell that made it slightly before
|
|
1595
|
+
* another process sees it, so a check that runs the instant a worker returns
|
|
1596
|
+
* can race the flush. The window is short and bounded: when the file never
|
|
1597
|
+
* appears the result is still ENOENT, which the caller reports as missing.
|
|
1598
|
+
*
|
|
1599
|
+
* @param {string} resolved - absolute path to check.
|
|
1600
|
+
* @returns {Promise<{ stats: object | null, error: NodeJS.ErrnoException | null }>}
|
|
1601
|
+
*/
|
|
1602
|
+
async function statDeliverable(resolved) {
|
|
1603
|
+
const deadline = now() + DELIVERABLE_GRACE_MS
|
|
1604
|
+
let error = null
|
|
1605
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
1606
|
+
try {
|
|
1607
|
+
return { stats: await fsp.stat(resolved), error: null }
|
|
1608
|
+
} catch (caught) {
|
|
1609
|
+
error = caught
|
|
1610
|
+
const missing = caught?.code === 'ENOENT' || caught?.code === 'ENOTDIR'
|
|
1611
|
+
const remaining = deadline - now()
|
|
1612
|
+
if (!missing || remaining <= 0 || attempt === 2) break
|
|
1613
|
+
await sleep(Math.min(DELIVERABLE_RECHECK_MS, remaining))
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
return { stats: null, error }
|
|
1553
1617
|
}
|
|
1554
1618
|
|
|
1555
1619
|
/**
|
|
@@ -1576,8 +1640,7 @@ export function createOrchestrator(deps) {
|
|
|
1576
1640
|
for (const entry of declared) {
|
|
1577
1641
|
const resolved = path.resolve(root, entry.path)
|
|
1578
1642
|
// A plan cannot widen its own reach by naming ../../ or an absolute path.
|
|
1579
|
-
|
|
1580
|
-
if (!inside) {
|
|
1643
|
+
if (!insideDirectory(root, resolved)) {
|
|
1581
1644
|
items.push({
|
|
1582
1645
|
...entry,
|
|
1583
1646
|
status: 'failed',
|
|
@@ -1585,10 +1648,10 @@ export function createOrchestrator(deps) {
|
|
|
1585
1648
|
})
|
|
1586
1649
|
continue
|
|
1587
1650
|
}
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1651
|
+
const probed = await statDeliverable(resolved)
|
|
1652
|
+
const stats = probed.stats
|
|
1653
|
+
if (!stats) {
|
|
1654
|
+
const error = probed.error
|
|
1592
1655
|
const missing = error?.code === 'ENOENT' || error?.code === 'ENOTDIR'
|
|
1593
1656
|
if (!missing) {
|
|
1594
1657
|
items.push({
|
|
@@ -1687,9 +1750,9 @@ export function createOrchestrator(deps) {
|
|
|
1687
1750
|
if (run.workspace?.mode !== 'git-worktree') return null
|
|
1688
1751
|
const base = run.workspace.base ? path.resolve(run.workspace.base) : null
|
|
1689
1752
|
const here = path.resolve(deliverableRoot(run, subtask))
|
|
1690
|
-
if (!base || base
|
|
1753
|
+
if (!base || sameDirectory(base, here)) return null
|
|
1691
1754
|
const candidate = path.resolve(base, entry.path)
|
|
1692
|
-
if (
|
|
1755
|
+
if (!insideDirectory(base, candidate)) return null
|
|
1693
1756
|
try {
|
|
1694
1757
|
const stats = await fsp.stat(candidate)
|
|
1695
1758
|
return stats.isFile() ? candidate : null
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xiangyixie/dsh-superagent",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.5",
|
|
4
4
|
"description": "长周期自主执行插件:一个目标拆成可并行的子任务,交付一份合并报告,重启后仍可继续。",
|
|
5
5
|
"author": "Admire (LittleChenLiya)",
|
|
6
6
|
"type": "module",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"files": [
|
|
38
38
|
"icon.svg",
|
|
39
39
|
"locale/*.json",
|
|
40
|
-
"lib/index.js",
|
|
40
|
+
"lib/index.js",
|
|
41
41
|
"lib/entry.js",
|
|
42
42
|
"lib/client.js",
|
|
43
43
|
"lib/orchestrator.js",
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"lib/goal.js",
|
|
54
54
|
"lib/cron.js",
|
|
55
55
|
"lib/schedule.js",
|
|
56
|
+
"lib/long-goal.js",
|
|
56
57
|
"lib/notify.js",
|
|
57
58
|
"lib/lock.js",
|
|
58
59
|
"lib/templates.js",
|
|
@@ -85,6 +86,7 @@
|
|
|
85
86
|
"docs/policy.example.json",
|
|
86
87
|
"docs/DETAIL.md",
|
|
87
88
|
"docs/DETAIL.zh.md",
|
|
89
|
+
"docs/LONG-GOAL.md",
|
|
88
90
|
"CHANGELOG.md",
|
|
89
91
|
"README.md",
|
|
90
92
|
"README.en.md",
|
|
@@ -96,7 +98,7 @@
|
|
|
96
98
|
"dsh": ">=0.2.2-rc.1 <0.3.0-0"
|
|
97
99
|
},
|
|
98
100
|
"scripts": {
|
|
99
|
-
"test": "node --test test/orchestrator.test.mjs test/direct-and-queue.test.mjs test/dialog.test.mjs test/workspace.test.mjs test/store.test.mjs test/errors.test.mjs test/plugin.test.mjs test/guard.test.mjs test/goal.test.mjs test/cron.test.mjs test/schedule.test.mjs test/audit.test.mjs test/inject.test.mjs test/sync.test.mjs test/workbench.test.mjs test/usage.test.mjs test/cost.test.mjs test/ledger.test.mjs test/control.test.mjs test/watch.test.mjs test/report.test.mjs test/memory.test.mjs test/user-memory.test.mjs test/notify.test.mjs test/templates.test.mjs test/archive.test.mjs test/doctor.test.mjs test/pack.test.mjs test/runtime-control.test.mjs test/console.test.mjs test/client-bundle.test.mjs test/wizard.test.mjs test/board.test.mjs",
|
|
101
|
+
"test": "node --test test/orchestrator.test.mjs test/direct-and-queue.test.mjs test/dialog.test.mjs test/workspace.test.mjs test/store.test.mjs test/errors.test.mjs test/plugin.test.mjs test/overhead.test.mjs test/guard.test.mjs test/goal.test.mjs test/cron.test.mjs test/schedule.test.mjs test/audit.test.mjs test/inject.test.mjs test/sync.test.mjs test/workbench.test.mjs test/usage.test.mjs test/cost.test.mjs test/ledger.test.mjs test/control.test.mjs test/watch.test.mjs test/report.test.mjs test/memory.test.mjs test/user-memory.test.mjs test/notify.test.mjs test/templates.test.mjs test/archive.test.mjs test/doctor.test.mjs test/pack.test.mjs test/runtime-control.test.mjs test/console.test.mjs test/client-bundle.test.mjs test/wizard.test.mjs test/board.test.mjs test/long-goal.test.mjs",
|
|
100
102
|
"check-pack": "node scripts/check-pack.mjs"
|
|
101
103
|
},
|
|
102
104
|
"keywords": [
|