@oneie/cli 5.7.6 → 5.8.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.
- package/README.md +19 -1
- package/dist/package.json +7 -8
- package/dist/src/age-yefbe8pe.js +1 -0
- package/dist/src/evm-tx-ee2q0e3w.js +1 -0
- package/dist/src/hl-run-tgrkrk69.js +1 -0
- package/dist/src/index-0rj9wdk9.js +4 -0
- package/dist/src/index-91y484c2.js +2052 -0
- package/dist/src/index-940y3rnv.js +12 -0
- package/dist/src/index.js +1047 -121
- package/dist/src/message-key-db1xjdkw.js +1 -0
- package/dist/src/message-lock-5vr8079x.js +5 -0
- package/dist/src/sweep-order-c2p6rk8c.js +1 -0
- package/dist/src/sweep-runner-t68xe7vx.js +1 -0
- package/package.json +7 -8
- package/dist/src/agent.d.ts +0 -75
- package/dist/src/agent.js +0 -1334
- package/dist/src/agentverse.d.ts +0 -26
- package/dist/src/agentverse.js +0 -171
- package/dist/src/args.d.ts +0 -9
- package/dist/src/args.js +0 -61
- package/dist/src/auth.d.ts +0 -6
- package/dist/src/auth.js +0 -121
- package/dist/src/balances.d.ts +0 -89
- package/dist/src/balances.js +0 -202
- package/dist/src/banner.d.ts +0 -1
- package/dist/src/banner.js +0 -17
- package/dist/src/broadcast.d.ts +0 -8
- package/dist/src/broadcast.js +0 -175
- package/dist/src/catalog.d.ts +0 -12
- package/dist/src/catalog.js +0 -76
- package/dist/src/chat.d.ts +0 -2
- package/dist/src/chat.js +0 -92
- package/dist/src/client.d.ts +0 -5
- package/dist/src/client.js +0 -157
- package/dist/src/compiler.d.ts +0 -36
- package/dist/src/compiler.js +0 -366
- package/dist/src/config.d.ts +0 -24
- package/dist/src/config.js +0 -70
- package/dist/src/connect.d.ts +0 -2
- package/dist/src/connect.js +0 -64
- package/dist/src/coordinate.d.ts +0 -3
- package/dist/src/coordinate.js +0 -58
- package/dist/src/create.d.ts +0 -2
- package/dist/src/create.js +0 -113
- package/dist/src/deploy.d.ts +0 -2
- package/dist/src/deploy.js +0 -19
- package/dist/src/dev.d.ts +0 -2
- package/dist/src/dev.js +0 -75
- package/dist/src/device-flow.d.ts +0 -57
- package/dist/src/device-flow.js +0 -173
- package/dist/src/doctor.d.ts +0 -26
- package/dist/src/doctor.js +0 -146
- package/dist/src/draw.d.ts +0 -18
- package/dist/src/draw.js +0 -156
- package/dist/src/endpoint.d.ts +0 -2
- package/dist/src/endpoint.js +0 -250
- package/dist/src/env.d.ts +0 -3
- package/dist/src/env.js +0 -37
- package/dist/src/eval.d.ts +0 -2
- package/dist/src/eval.js +0 -43
- package/dist/src/fn.d.ts +0 -2
- package/dist/src/fn.js +0 -70
- package/dist/src/group.d.ts +0 -2
- package/dist/src/group.js +0 -117
- package/dist/src/hl-run.d.ts +0 -119
- package/dist/src/hl-run.js +0 -480
- package/dist/src/hl.d.ts +0 -17
- package/dist/src/hl.js +0 -148
- package/dist/src/index.d.ts +0 -2
- package/dist/src/init.d.ts +0 -76
- package/dist/src/init.js +0 -278
- package/dist/src/join.d.ts +0 -11
- package/dist/src/join.js +0 -293
- package/dist/src/key-publish.d.ts +0 -40
- package/dist/src/key-publish.js +0 -232
- package/dist/src/key-seal.d.ts +0 -21
- package/dist/src/key-seal.js +0 -142
- package/dist/src/key-sweep.d.ts +0 -93
- package/dist/src/key-sweep.js +0 -263
- package/dist/src/key.d.ts +0 -26
- package/dist/src/key.js +0 -338
- package/dist/src/lib/age-plugin.d.ts +0 -51
- package/dist/src/lib/age-plugin.js +0 -130
- package/dist/src/lib/agent-env.d.ts +0 -12
- package/dist/src/lib/agent-env.js +0 -48
- package/dist/src/lib/api-path.d.ts +0 -2
- package/dist/src/lib/api-path.js +0 -40
- package/dist/src/lib/asker.d.ts +0 -34
- package/dist/src/lib/asker.js +0 -126
- package/dist/src/lib/client.d.ts +0 -20
- package/dist/src/lib/client.js +0 -71
- package/dist/src/lib/env-sealed.d.ts +0 -53
- package/dist/src/lib/env-sealed.js +0 -184
- package/dist/src/lib/flow-tag.d.ts +0 -86
- package/dist/src/lib/flow-tag.js +0 -230
- package/dist/src/lib/hl-core/actions.d.ts +0 -99
- package/dist/src/lib/hl-core/actions.js +0 -69
- package/dist/src/lib/hl-core/eip712.d.ts +0 -33
- package/dist/src/lib/hl-core/eip712.js +0 -107
- package/dist/src/lib/hl-core/errors.d.ts +0 -10
- package/dist/src/lib/hl-core/errors.js +0 -15
- package/dist/src/lib/hl-core/exchange.d.ts +0 -24
- package/dist/src/lib/hl-core/exchange.js +0 -47
- package/dist/src/lib/hl-core/index.d.ts +0 -13
- package/dist/src/lib/hl-core/index.js +0 -14
- package/dist/src/lib/hl-core/meta.d.ts +0 -57
- package/dist/src/lib/hl-core/meta.js +0 -110
- package/dist/src/lib/hl-core/msgpack.d.ts +0 -18
- package/dist/src/lib/hl-core/msgpack.js +0 -136
- package/dist/src/lib/hl-core/net.d.ts +0 -2
- package/dist/src/lib/hl-core/net.js +0 -7
- package/dist/src/lib/hl-core/signing.d.ts +0 -103
- package/dist/src/lib/hl-core/signing.js +0 -295
- package/dist/src/lib/hl-core/wire.d.ts +0 -34
- package/dist/src/lib/hl-core/wire.js +0 -81
- package/dist/src/lib/invoked-as.d.ts +0 -2
- package/dist/src/lib/invoked-as.js +0 -24
- package/dist/src/lib/journey-words.d.ts +0 -84
- package/dist/src/lib/journey-words.js +0 -360
- package/dist/src/lib/journey.d.ts +0 -148
- package/dist/src/lib/journey.js +0 -245
- package/dist/src/lib/key-receipt.d.ts +0 -48
- package/dist/src/lib/key-receipt.js +0 -116
- package/dist/src/lib/key-source.d.ts +0 -9
- package/dist/src/lib/key-source.js +0 -33
- package/dist/src/lib/keyfile.d.ts +0 -136
- package/dist/src/lib/keyfile.js +0 -397
- package/dist/src/lib/launch-claude.d.ts +0 -5
- package/dist/src/lib/launch-claude.js +0 -45
- package/dist/src/lib/lock-lookup.d.ts +0 -40
- package/dist/src/lib/lock-lookup.js +0 -92
- package/dist/src/lib/message-seal.d.ts +0 -63
- package/dist/src/lib/message-seal.js +0 -150
- package/dist/src/lib/network.d.ts +0 -15
- package/dist/src/lib/network.js +0 -41
- package/dist/src/lib/paths.d.ts +0 -41
- package/dist/src/lib/paths.js +0 -91
- package/dist/src/lib/plan-draw.d.ts +0 -56
- package/dist/src/lib/plan-draw.js +0 -219
- package/dist/src/lib/plan-live.d.ts +0 -20
- package/dist/src/lib/plan-live.js +0 -192
- package/dist/src/lib/qr.d.ts +0 -21
- package/dist/src/lib/qr.js +0 -402
- package/dist/src/lib/roster.d.ts +0 -20
- package/dist/src/lib/roster.js +0 -79
- package/dist/src/lib/sale-card.d.ts +0 -117
- package/dist/src/lib/sale-card.js +0 -261
- package/dist/src/lib/shop-init.d.ts +0 -62
- package/dist/src/lib/shop-init.js +0 -63
- package/dist/src/lib/sui-grpc-send.d.ts +0 -50
- package/dist/src/lib/sui-grpc-send.js +0 -89
- package/dist/src/lib/swap-core.d.ts +0 -163
- package/dist/src/lib/swap-core.js +0 -405
- package/dist/src/lib/tasks-digest.d.ts +0 -66
- package/dist/src/lib/tasks-digest.js +0 -200
- package/dist/src/lib/tasks-graph.d.ts +0 -79
- package/dist/src/lib/tasks-graph.js +0 -463
- package/dist/src/lib/tasks-lens.d.ts +0 -31
- package/dist/src/lib/tasks-lens.js +0 -47
- package/dist/src/lib/tasks-next.d.ts +0 -25
- package/dist/src/lib/tasks-next.js +0 -103
- package/dist/src/lib/tasks-prove.d.ts +0 -15
- package/dist/src/lib/tasks-prove.js +0 -68
- package/dist/src/lib/tasks-route.d.ts +0 -29
- package/dist/src/lib/tasks-route.js +0 -151
- package/dist/src/lib/tasks-score.d.ts +0 -36
- package/dist/src/lib/tasks-score.js +0 -152
- package/dist/src/lib/tasks-workspace.d.ts +0 -18
- package/dist/src/lib/tasks-workspace.js +0 -73
- package/dist/src/lib/vault-read.d.ts +0 -24
- package/dist/src/lib/vault-read.js +0 -77
- package/dist/src/lib/vaultfile.d.ts +0 -88
- package/dist/src/lib/vaultfile.js +0 -222
- package/dist/src/lib/wallet-money.d.ts +0 -222
- package/dist/src/lib/wallet-money.js +0 -578
- package/dist/src/lib/wallet-request.d.ts +0 -50
- package/dist/src/lib/wallet-request.js +0 -86
- package/dist/src/links.d.ts +0 -5
- package/dist/src/links.js +0 -45
- package/dist/src/media.d.ts +0 -29
- package/dist/src/media.js +0 -487
- package/dist/src/message-receipt.d.ts +0 -25
- package/dist/src/message-receipt.js +0 -71
- package/dist/src/message.d.ts +0 -13
- package/dist/src/message.js +0 -92
- package/dist/src/onboard.d.ts +0 -16
- package/dist/src/onboard.js +0 -149
- package/dist/src/plugin.d.ts +0 -2
- package/dist/src/plugin.js +0 -193
- package/dist/src/push.d.ts +0 -2
- package/dist/src/push.js +0 -115
- package/dist/src/render.d.ts +0 -21
- package/dist/src/render.js +0 -32
- package/dist/src/secrets-device.d.ts +0 -32
- package/dist/src/secrets-device.js +0 -127
- package/dist/src/secrets-give.d.ts +0 -125
- package/dist/src/secrets-give.js +0 -236
- package/dist/src/secrets-list.d.ts +0 -27
- package/dist/src/secrets-list.js +0 -84
- package/dist/src/secrets-run.d.ts +0 -31
- package/dist/src/secrets-run.js +0 -182
- package/dist/src/secrets.d.ts +0 -33
- package/dist/src/secrets.js +0 -200
- package/dist/src/setup.d.ts +0 -6
- package/dist/src/setup.js +0 -127
- package/dist/src/ship.d.ts +0 -2
- package/dist/src/ship.js +0 -18
- package/dist/src/shop.d.ts +0 -10
- package/dist/src/shop.js +0 -110
- package/dist/src/skill-parser.d.ts +0 -14
- package/dist/src/skill-parser.js +0 -113
- package/dist/src/skill.d.ts +0 -2
- package/dist/src/skill.js +0 -493
- package/dist/src/slug.d.ts +0 -2
- package/dist/src/slug.js +0 -6
- package/dist/src/social.d.ts +0 -2
- package/dist/src/social.js +0 -106
- package/dist/src/staff.d.ts +0 -2
- package/dist/src/staff.js +0 -104
- package/dist/src/start.d.ts +0 -15
- package/dist/src/start.js +0 -203
- package/dist/src/status.d.ts +0 -2
- package/dist/src/status.js +0 -52
- package/dist/src/substrate.d.ts +0 -2
- package/dist/src/substrate.js +0 -258
- package/dist/src/swap.d.ts +0 -93
- package/dist/src/swap.js +0 -622
- package/dist/src/tasks.d.ts +0 -2
- package/dist/src/tasks.js +0 -743
- package/dist/src/templates.d.ts +0 -1
- package/dist/src/templates.js +0 -213
- package/dist/src/trade.d.ts +0 -2
- package/dist/src/trade.js +0 -91
- package/dist/src/trail.d.ts +0 -2
- package/dist/src/trail.js +0 -41
- package/dist/src/validate.d.ts +0 -13
- package/dist/src/validate.js +0 -35
- package/dist/src/wallet-money.d.ts +0 -152
- package/dist/src/wallet-money.js +0 -564
- package/dist/src/wallet.d.ts +0 -167
- package/dist/src/wallet.js +0 -855
- package/dist/src/workflow.d.ts +0 -2
- package/dist/src/workflow.js +0 -166
- package/dist/src/write.d.ts +0 -43
- package/dist/src/write.js +0 -180
package/dist/src/tasks.js
DELETED
|
@@ -1,743 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
-
import { boardAllWith, bulkAllWith, } from '@oneie/sdk/tasks-bulk';
|
|
4
|
-
import { authHeaders, jsonMode, resolveBase } from './lib/client.js';
|
|
5
|
-
import { exitCodeFor, failureFor, makeAsker, RETRYABLE_EXIT } from './lib/asker.js';
|
|
6
|
-
import { digest, filterKind, kindOf, renderDigest } from './lib/tasks-digest.js';
|
|
7
|
-
import { planWaves, renderPlan, sequenceEdits, subtree, toDispatch } from './lib/tasks-graph.js';
|
|
8
|
-
import { drawPlan, planHeader, toLazydraw } from './lib/plan-draw.js';
|
|
9
|
-
import { runLivePlan } from './lib/plan-live.js';
|
|
10
|
-
import { runFlow, FLOWS as FLOW_IDS } from './lib/flow-tag.js';
|
|
11
|
-
import { buildLens, lensRows } from './lib/tasks-lens.js';
|
|
12
|
-
import { loadRoster } from './lib/roster.js';
|
|
13
|
-
import { proveBoard } from './lib/tasks-prove.js';
|
|
14
|
-
import { proposeOwners, routeEdits } from './lib/tasks-route.js';
|
|
15
|
-
import { claimNext, nextCandidates } from './lib/tasks-next.js';
|
|
16
|
-
import { resolveBulkWorkspaces, spreadWarning, workspaceSpread } from './lib/tasks-workspace.js';
|
|
17
|
-
import { renderScore, scoreboard } from './lib/tasks-score.js';
|
|
18
|
-
import { CONFIG_DIR } from './lib/paths.js';
|
|
19
|
-
import { homedir } from 'node:os';
|
|
20
|
-
import { dirname, join } from 'node:path';
|
|
21
|
-
import { mkdirSync } from 'node:fs';
|
|
22
|
-
// `one tasks` — the whole board and the whole edit in one command. Both ride
|
|
23
|
-
// existing receivers (tasks:board, tasks:bulk) through the ask door; the page walk
|
|
24
|
-
// and the 25-row chunking live in @oneie/sdk/tasks-bulk so the SDK and the CLI
|
|
25
|
-
// run the same loop over their own transports.
|
|
26
|
-
const DEFAULT_API = 'https://api.one.ie';
|
|
27
|
-
// The last transport failure any asker saw. The SDK's page walk and chunker catch a
|
|
28
|
-
// throw and keep only its message, so the retryable verdict is carried here and read
|
|
29
|
-
// back by fail() — the exit code is how a script tells "retry" from "fix the call".
|
|
30
|
-
let lastAskFailure;
|
|
31
|
-
function asker(api) {
|
|
32
|
-
return makeAsker(resolveBase({ api }, DEFAULT_API), { headers: authHeaders(), onFailure: (f) => { lastAskFailure = f; } });
|
|
33
|
-
}
|
|
34
|
-
const collect = (v, prev = []) => [...prev, v];
|
|
35
|
-
function fail(msg) {
|
|
36
|
-
const f = failureFor(msg, lastAskFailure);
|
|
37
|
-
process.stderr.write(`error ${msg}${f ? ` (${f.retryable ? 'retryable' : 'not retryable'}, httpStatus ${f.httpStatus}${f.retryable ? `, exit ${RETRYABLE_EXIT}` : ''})` : ''}\n`);
|
|
38
|
-
process.exitCode = exitCodeFor(f);
|
|
39
|
-
}
|
|
40
|
-
function top(rec, n) {
|
|
41
|
-
if (!rec)
|
|
42
|
-
return '-';
|
|
43
|
-
const rows = Object.entries(rec).sort((a, b) => b[1] - a[1]).slice(0, n);
|
|
44
|
-
return rows.length ? rows.map(([k, v]) => `${k === '' ? '(unassigned)' : k}=${v}`).join(' ') : '-';
|
|
45
|
-
}
|
|
46
|
-
function renderBoard(res) {
|
|
47
|
-
const tasks = res.tasks ?? [];
|
|
48
|
-
const w = process.stdout;
|
|
49
|
-
w.write(`${tasks.length} of ${res.total ?? '?'} (asOf ${res.asOf ?? '?'})${res.pages ? ` pages=${res.pages}` : ''}\n`);
|
|
50
|
-
if (res.truncated) {
|
|
51
|
-
const t = res.truncated;
|
|
52
|
-
const parts = [
|
|
53
|
-
t.rows !== undefined ? `rows=${t.rows} (total is a floor or rows are missing)` : '',
|
|
54
|
-
t.edges ? 'edges capped (blocked/orphan counts may be wrong)' : '',
|
|
55
|
-
t.tags !== undefined ? `tags missing on ${t.tags} rows` : '',
|
|
56
|
-
].filter(Boolean);
|
|
57
|
-
w.write(`TRUNCATED: ${parts.join('; ') || JSON.stringify(t)}\n`);
|
|
58
|
-
}
|
|
59
|
-
if (res.nextCursor)
|
|
60
|
-
w.write(`MORE: nextCursor=${res.nextCursor} — rerun with --all to walk every page\n`);
|
|
61
|
-
const s = res.summary;
|
|
62
|
-
if (s) {
|
|
63
|
-
w.write('\nsummary\n');
|
|
64
|
-
w.write(` status ${top(s.byStatus, 20)}\n`);
|
|
65
|
-
w.write(` tags ${top(s.byTag, 15)}\n`);
|
|
66
|
-
w.write(` assignee ${top(s.byAssignee, 20)}\n`);
|
|
67
|
-
if (Object.keys(s.byWorkspace ?? {}).length > 1)
|
|
68
|
-
w.write(` workspace ${top(s.byWorkspace, 20)}\n`);
|
|
69
|
-
w.write(` ready=${s.ready} blocked=${s.blocked} overdue=${s.overdue} unassigned=${s.unassigned} orphans=${s.orphans} noNotes=${s.noNotes}\n`);
|
|
70
|
-
}
|
|
71
|
-
if (tasks.length)
|
|
72
|
-
w.write('\n');
|
|
73
|
-
for (const t of tasks) {
|
|
74
|
-
const tags = t.tags.length ? ` [${t.tags.join(',')}]` : '';
|
|
75
|
-
w.write(`${t.tid} ${t.status} p${t.priority} @${t.assignee || '-'} ${t.name}${tags}\n`);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
function renderBulk(res, preview) {
|
|
79
|
-
const w = process.stdout;
|
|
80
|
-
if (preview && res.ok === false) {
|
|
81
|
-
// A preview that never reached the server has no match count to report — don't print "matched 0".
|
|
82
|
-
}
|
|
83
|
-
else if (preview) {
|
|
84
|
-
w.write(`DRY RUN — nothing moved. matched ${res.matched ?? res.matchedIds?.length ?? 0}\n`);
|
|
85
|
-
for (const id of res.matchedIds ?? [])
|
|
86
|
-
w.write(` ${id}\n`);
|
|
87
|
-
if (res.nextCursor)
|
|
88
|
-
w.write(` … more matches beyond this page (applies continue across pages with --apply)\n`);
|
|
89
|
-
w.write('rerun with --apply to apply\n');
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
w.write(`total=${res.total ?? 0} attempted=${res.attempted ?? 0} applied=${res.applied ?? 0} failed=${res.failed ?? 0} notAttempted=${res.notAttempted ?? 0}` +
|
|
93
|
-
(res.matched !== undefined ? ` matched=${res.matched}` : '') +
|
|
94
|
-
'\n');
|
|
95
|
-
for (const [ref, tid] of Object.entries(res.created ?? {}))
|
|
96
|
-
w.write(` created ${ref} → ${tid}\n`);
|
|
97
|
-
if (res.nextCursor)
|
|
98
|
-
w.write(`STOPPED EARLY: nextCursor=${res.nextCursor} — rows remain unapplied\n`);
|
|
99
|
-
}
|
|
100
|
-
for (const r of res.results ?? []) {
|
|
101
|
-
if (r.ok)
|
|
102
|
-
continue;
|
|
103
|
-
const fields = (r.fields ?? []).filter((f) => !f.ok).map((f) => `${f.field}:${f.reason ?? 'failed'}`);
|
|
104
|
-
process.stderr.write(`FAILED ${r.tid || '-'}${r.ref ? ` (ref ${r.ref})` : ''} ${r.reason ?? ''}${fields.length ? ` ${fields.join(' ')}` : ''}${r.retryable ? ' retryable' : ''}\n`);
|
|
105
|
-
}
|
|
106
|
-
if (res.ok === false)
|
|
107
|
-
process.stderr.write(`error ${res.error ?? 'tasks:bulk failed'}${res.detail ? ` — ${res.detail}` : ''}\n`);
|
|
108
|
-
}
|
|
109
|
-
// ── planning helpers (brief · plan · sequence · depend) ────────────────────
|
|
110
|
-
// Reads walk every page of tasks:board (2000 rows a page) — never one request per
|
|
111
|
-
// row. The digest and the waves are computed HERE from the rows, so approvals can
|
|
112
|
-
// be left out of the counts without a receiver change (text/tasks-cli.md § the cheap cut).
|
|
113
|
-
const KINDS = ['work', 'approval', 'all'];
|
|
114
|
-
function parseKind(v) {
|
|
115
|
-
const k = (v ?? 'work');
|
|
116
|
-
return KINDS.includes(k) ? k : undefined;
|
|
117
|
-
}
|
|
118
|
-
// Said once per process, on the first read that spans several groups.
|
|
119
|
-
let spreadWarned = false;
|
|
120
|
-
function warnSpread(rows) {
|
|
121
|
-
if (spreadWarned || !rows?.length)
|
|
122
|
-
return;
|
|
123
|
-
const w = spreadWarning(workspaceSpread(rows));
|
|
124
|
-
if (!w)
|
|
125
|
-
return;
|
|
126
|
-
spreadWarned = true;
|
|
127
|
-
process.stderr.write(w + '\n');
|
|
128
|
-
}
|
|
129
|
-
async function readAll(api, req) {
|
|
130
|
-
const res = await boardAllWith(asker(api), { limit: 2000, ...req });
|
|
131
|
-
warnSpread(res.tasks);
|
|
132
|
-
return res;
|
|
133
|
-
}
|
|
134
|
-
function saveDrawing(name, lines) {
|
|
135
|
-
const dir = join(process.env.XDG_DATA_HOME || join(homedir(), '.local', 'share'), 'lazydraw', 'drawings');
|
|
136
|
-
mkdirSync(dir, { recursive: true });
|
|
137
|
-
const file = join(dir, `${name.replace(/[^a-z0-9-]+/gi, '-').toLowerCase()}.ld.json`);
|
|
138
|
-
writeFileSync(file, toLazydraw(lines, name));
|
|
139
|
-
process.stderr.write(`saved — open it with: one draw ${name}\n`);
|
|
140
|
-
}
|
|
141
|
-
function writeOut(file, data) {
|
|
142
|
-
if (!file)
|
|
143
|
-
return;
|
|
144
|
-
writeFileSync(file, JSON.stringify(data, null, 2) + '\n');
|
|
145
|
-
process.stderr.write(`wrote ${file}\n`);
|
|
146
|
-
}
|
|
147
|
-
function boardMeta(res) {
|
|
148
|
-
return {
|
|
149
|
-
...(res.total !== undefined ? { total: res.total } : {}),
|
|
150
|
-
...(res.asOf ? { asOf: res.asOf } : {}),
|
|
151
|
-
...(res.pages !== undefined ? { pages: res.pages } : {}),
|
|
152
|
-
...(res.truncated ? { truncated: res.truncated } : {}),
|
|
153
|
-
...(res.nextCursor ? { nextCursor: res.nextCursor } : {}),
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
async function runEdits(sub, api, workspace, edits) {
|
|
157
|
-
await runBulk(sub, api, { ...(workspace ? { workspace } : {}), edits }, false);
|
|
158
|
-
if (!process.exitCode && !jsonMode(sub)) {
|
|
159
|
-
process.stdout.write('waves change on the next board snapshot (≤60s memo) — then: one tasks plan <goal>\n');
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
async function runBulk(cmd, api, req, apply) {
|
|
163
|
-
const hasWhere = !!req.where;
|
|
164
|
-
if (hasWhere)
|
|
165
|
-
req = { ...req, dryRun: !apply };
|
|
166
|
-
const res = await bulkAllWith(asker(api), req);
|
|
167
|
-
if (jsonMode(cmd))
|
|
168
|
-
process.stdout.write(JSON.stringify(res, null, 2) + '\n');
|
|
169
|
-
else
|
|
170
|
-
renderBulk(res, hasWhere && !apply && !(req.creates?.length || req.edits?.length));
|
|
171
|
-
const unapplied = hasWhere && !apply ? 0 : (res.notAttempted ?? 0);
|
|
172
|
-
if (res.ok === false || (res.failed ?? 0) > 0 || unapplied > 0 || (!!res.nextCursor && apply))
|
|
173
|
-
process.exitCode = res.ok === false ? exitCodeFor(failureFor(res.error ?? '', lastAskFailure)) : 1;
|
|
174
|
-
}
|
|
175
|
-
// `one tasks flow` — the human report (flow-tag.ts holds the plan and the apply guards).
|
|
176
|
-
function renderFlowPlan(r, scope, classifiedFrom) {
|
|
177
|
-
const firstLine = r.dryRun ? 'DRY RUN — nothing written' : 'APPLIED';
|
|
178
|
-
console.log(firstLine);
|
|
179
|
-
if (r.plan === undefined) {
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
console.log(`board total=${r.total} rows read (status ${scope}) asOf=${r.asOf}`);
|
|
183
|
-
if (r.truncated !== undefined && typeof r.truncated === 'object') {
|
|
184
|
-
console.log('TRUNCATED: ' + JSON.stringify(r.truncated) + ' — tag signals are unknown on rows whose tags were cut');
|
|
185
|
-
}
|
|
186
|
-
console.log('signals from: ' + classifiedFrom);
|
|
187
|
-
for (const flow of FLOW_IDS) {
|
|
188
|
-
const count = r.plan.counts[flow];
|
|
189
|
-
console.log(` ${flow.padEnd(8)} ${count}`);
|
|
190
|
-
}
|
|
191
|
-
console.log(`placed=${r.plan.placed} unplaced=${r.plan.unplaced.length} (left for a person) alreadyTagged=${r.plan.alreadyTagged.length} mismatches=${r.plan.mismatches.length} edits=${r.plan.edits.length}`);
|
|
192
|
-
console.log(`by source notes=${r.plan.bySource.notes} tags=${r.plan.bySource.tags} classified=${r.plan.bySource.classified}`);
|
|
193
|
-
for (const m of r.plan.mismatches) {
|
|
194
|
-
console.log(` MISMATCH ${m.tid} computed=${m.computed} file=${m.file} — the rule wins (flow-route.test.ts)`);
|
|
195
|
-
}
|
|
196
|
-
if (r.dryRun && r.plan.edits.length > 0) {
|
|
197
|
-
console.log(`rerun with --apply to write ${r.plan.edits.length} rows (needs a live read fresher than --max-age)`);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
// A seat's lens — its staked tags + itself and every seat that reports up to it.
|
|
201
|
-
// `--tags` builds one without the roster (the documented escape when no key can read it).
|
|
202
|
-
async function resolveLens(api, workspace, seat, opts) {
|
|
203
|
-
if (opts.tags) {
|
|
204
|
-
const tags = [...new Set(opts.tags.split(',').map((t) => t.trim()).filter(Boolean))].sort();
|
|
205
|
-
if (!tags.length)
|
|
206
|
-
return { ok: false, error: '--tags is empty' };
|
|
207
|
-
return { ok: true, lens: { seat, tags, seats: [seat], all: false }, source: '--tags (roster not read: reports are not in this lens)' };
|
|
208
|
-
}
|
|
209
|
-
const r = await loadRoster({ base: resolveBase({ api }, DEFAULT_API), workspace, file: opts.roster, headers: authHeaders() });
|
|
210
|
-
if (!r.ok)
|
|
211
|
-
return r;
|
|
212
|
-
const l = buildLens(r.seats, seat);
|
|
213
|
-
return l.ok ? { ok: true, lens: l.lens, source: r.source } : l;
|
|
214
|
-
}
|
|
215
|
-
function lensLine(lens, source, kept, of) {
|
|
216
|
-
const seats = lens.seats.filter((s) => s !== lens.seat);
|
|
217
|
-
const shown = seats.slice(0, 8).join(',') + (seats.length > 8 ? `,+${seats.length - 8}` : '');
|
|
218
|
-
return `lens ${lens.seat}: ${lens.all ? 'every row (staked *)' : `tags [${lens.tags.join(',')}]`} · reports ${seats.length}${seats.length ? ` (${shown})` : ''} · roster ${source} — ${kept} of ${of} rows`;
|
|
219
|
-
}
|
|
220
|
-
// The CEO scoreboard remembers the last brief so the next one prints deltas. Closed
|
|
221
|
-
// rows are read only when there is a last brief to compare with (status:'all' costs a
|
|
222
|
-
// second walk), and a PARTIAL read is never saved — it would fake a drop next time.
|
|
223
|
-
async function ceoScore(api, group, tree, active, res, file) {
|
|
224
|
-
const path = file ?? join(CONFIG_DIR, 'briefs', `${(group ?? 'own').replace(/[^a-z0-9-]+/gi, '-')}${tree ? '-tree' : ''}.json`);
|
|
225
|
-
let prev;
|
|
226
|
-
if (existsSync(path)) {
|
|
227
|
-
try {
|
|
228
|
-
prev = JSON.parse(readFileSync(path, 'utf8'));
|
|
229
|
-
}
|
|
230
|
-
catch {
|
|
231
|
-
process.stderr.write(`warning ${path} is not a scoreboard — starting over\n`);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
let rows = active;
|
|
235
|
-
if (prev) {
|
|
236
|
-
const closed = await readAll(api, { ...(group ? { workspace: group } : {}), ...(tree ? { scope: 'tree' } : {}), status: ['done', 'verified', 'dissolved', 'failed'] });
|
|
237
|
-
if (closed.ok === false)
|
|
238
|
-
process.stderr.write(`warning closed rows unread (${closed.error ?? 'tasks:board failed'}) — closed-per-seat reads 0\n`);
|
|
239
|
-
else
|
|
240
|
-
rows = [...active, ...(closed.tasks ?? [])];
|
|
241
|
-
}
|
|
242
|
-
const score = scoreboard(rows, prev, { ...(res.asOf ? { asOf: res.asOf } : {}) });
|
|
243
|
-
if (res.nextCursor || res.truncated?.rows !== undefined) {
|
|
244
|
-
process.stderr.write('warning partial board read — scoreboard shown, NOT saved\n');
|
|
245
|
-
return score;
|
|
246
|
-
}
|
|
247
|
-
mkdirSync(dirname(path), { recursive: true });
|
|
248
|
-
writeFileSync(path, JSON.stringify(score.snap) + '\n');
|
|
249
|
-
return score;
|
|
250
|
-
}
|
|
251
|
-
export function tasksCmd() {
|
|
252
|
-
const cmd = new Command('tasks').description('The whole task board in one read, and many task edits in one write');
|
|
253
|
-
cmd
|
|
254
|
-
.command('board')
|
|
255
|
-
.description('Read the task board (tasks:board) — total, summary over all matched rows, and the rows')
|
|
256
|
-
.option('--workspace <slug>', 'Group slug (default: your own)')
|
|
257
|
-
.option('--tree', 'This group and every descendant group')
|
|
258
|
-
.option('--status <s>', "open|blocked|picked|done|verified|failed|dissolved, 'active' (default) or 'all'; comma for many")
|
|
259
|
-
.option('--tag <t>', 'Row must carry this tag (repeatable, AND)', collect)
|
|
260
|
-
.option('--any-tag <t>', 'Row must carry at least one of these (repeatable, OR)', collect)
|
|
261
|
-
.option('--assignee <a>', "Actor slug; '' = unassigned")
|
|
262
|
-
.option('--search <q>', 'Substring on the task name')
|
|
263
|
-
.option('--ready', 'Only rows claimable now')
|
|
264
|
-
.option('--include <list>', 'Comma list: notes,graph,dates,thread')
|
|
265
|
-
.option('--summary', 'Counts and sets only, no rows')
|
|
266
|
-
.option('--all', 'Follow nextCursor until every page is read (ceiling 20 pages)')
|
|
267
|
-
.option('--prove', "Run each open row's Accept in a clean worktree at origin/dev and mark the ones already green")
|
|
268
|
-
.option('--limit <n>', 'Rows per page (max 2000)')
|
|
269
|
-
.option('--fresh', 'Rebuild the snapshot instead of reading the memo')
|
|
270
|
-
.option('--kind <k>', "work (default) | approval | all — approvals are parked workflow runs; filtered from ROWS here, the server summary still counts them", 'work')
|
|
271
|
-
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
272
|
-
.option('--json', 'Print the raw response')
|
|
273
|
-
.action(async (opts, sub) => {
|
|
274
|
-
const kind = parseKind(opts.kind);
|
|
275
|
-
if (!kind)
|
|
276
|
-
return fail('--kind must be work, approval or all');
|
|
277
|
-
const status = opts.status?.includes(',') ? opts.status.split(',').map((s) => s.trim()).filter(Boolean) : opts.status;
|
|
278
|
-
const req = {
|
|
279
|
-
...(opts.workspace ? { workspace: opts.workspace } : {}),
|
|
280
|
-
...(opts.tree ? { scope: 'tree' } : {}),
|
|
281
|
-
...(status ? { status } : {}),
|
|
282
|
-
...(opts.tag?.length ? { tags: opts.tag } : {}),
|
|
283
|
-
...(opts.anyTag?.length ? { anyTags: opts.anyTag } : {}),
|
|
284
|
-
...(opts.assignee !== undefined ? { assignee: opts.assignee } : {}),
|
|
285
|
-
...(opts.search ? { search: opts.search } : {}),
|
|
286
|
-
...(opts.ready ? { ready: true } : {}),
|
|
287
|
-
...(opts.include ? { include: opts.include.split(',').map((s) => s.trim()).filter(Boolean) } : {}),
|
|
288
|
-
...(opts.summary ? { view: 'summary' } : {}),
|
|
289
|
-
...(opts.limit ? { limit: Number(opts.limit) } : {}),
|
|
290
|
-
...(opts.fresh ? { fresh: true } : {}),
|
|
291
|
-
};
|
|
292
|
-
const ask = asker(opts.api);
|
|
293
|
-
let res;
|
|
294
|
-
try {
|
|
295
|
-
res = opts.all ? await boardAllWith(ask, req) : (await ask('tasks:board', req));
|
|
296
|
-
}
|
|
297
|
-
catch (e) {
|
|
298
|
-
return fail(e instanceof Error ? e.message : String(e));
|
|
299
|
-
}
|
|
300
|
-
warnSpread(res.tasks);
|
|
301
|
-
let excluded = 0;
|
|
302
|
-
if (res.tasks && kind !== 'all') {
|
|
303
|
-
const f = filterKind(res.tasks, kind);
|
|
304
|
-
excluded = kind === 'work' ? f.excluded.approval : f.excluded.work;
|
|
305
|
-
res = { ...res, tasks: f.rows, kindExcluded: excluded };
|
|
306
|
-
}
|
|
307
|
-
if (jsonMode(sub))
|
|
308
|
-
process.stdout.write(JSON.stringify(res, null, 2) + '\n');
|
|
309
|
-
else if (res.ok !== false) {
|
|
310
|
-
renderBoard(res);
|
|
311
|
-
if (excluded) {
|
|
312
|
-
process.stdout.write(`\n--kind ${kind}: ${excluded} ${kind === 'work' ? 'approval' : 'work'} rows left out of the rows above (the summary is server-side and still counts them). --kind all to include.\n`);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
if (res.ok !== false && sub.opts().prove)
|
|
316
|
-
await proveBoard((res.tasks ?? []));
|
|
317
|
-
if (res.ok === false)
|
|
318
|
-
fail(res.error ?? 'tasks:board failed');
|
|
319
|
-
});
|
|
320
|
-
cmd
|
|
321
|
-
.command('bulk')
|
|
322
|
-
.description('Apply a tasks:bulk request from a file — creates/edits chunked at 25, where+set previewed unless --apply')
|
|
323
|
-
.requiredOption('--file <path>', 'JSON file holding a tasks:bulk request')
|
|
324
|
-
.option('--apply', 'For where+set: apply (dryRun:false). Without it, preview the matches only')
|
|
325
|
-
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
326
|
-
.option('--json', 'Print the merged receipt as JSON')
|
|
327
|
-
.action(async (opts, sub) => {
|
|
328
|
-
let req;
|
|
329
|
-
try {
|
|
330
|
-
req = JSON.parse(readFileSync(opts.file, 'utf8'));
|
|
331
|
-
}
|
|
332
|
-
catch (e) {
|
|
333
|
-
return fail(`--file: ${e instanceof Error ? e.message : String(e)}`);
|
|
334
|
-
}
|
|
335
|
-
if (!req || typeof req !== 'object')
|
|
336
|
-
return fail('--file must hold a JSON object');
|
|
337
|
-
if (!req.creates?.length && !req.edits?.length && !(req.where && req.set))
|
|
338
|
-
return fail('send edits, creates, or where+set');
|
|
339
|
-
if (!req.where !== !req.set)
|
|
340
|
-
return fail('where and set go together');
|
|
341
|
-
// A tid carries no workspace: an edit without one is resolved from its board row,
|
|
342
|
-
// so a file mixing groups does not answer not_found for every row outside --workspace.
|
|
343
|
-
const r = await resolveBulkWorkspaces(asker(opts.api), req);
|
|
344
|
-
// An unreadable board is not a reason to refuse a write that worked before this
|
|
345
|
-
// existed: say so, and send with the file's workspace as it always was.
|
|
346
|
-
if (!r.ok)
|
|
347
|
-
process.stderr.write(`warning ${r.error.replace(' — nothing sent', '')} — sending with the file's workspace\n`);
|
|
348
|
-
const resolved = r.ok ? r : { req, filled: 0, unknown: [] };
|
|
349
|
-
if (resolved.filled)
|
|
350
|
-
process.stderr.write(`resolved the workspace of ${resolved.filled} edit(s) from their board rows\n`);
|
|
351
|
-
if (resolved.unknown.length)
|
|
352
|
-
process.stderr.write(`warning ${resolved.unknown.length} edit(s) not on the board read (${resolved.unknown.slice(0, 5).join(', ')}${resolved.unknown.length > 5 ? ', …' : ''}) — sent with the file's workspace\n`);
|
|
353
|
-
await runBulk(sub, opts.api, resolved.req, !!opts.apply);
|
|
354
|
-
});
|
|
355
|
-
cmd
|
|
356
|
-
.command('set')
|
|
357
|
-
.description('One edit to every task a filter matches (tasks:bulk where+set). Preview unless --apply')
|
|
358
|
-
.option('--workspace <slug>', 'Group slug (default: your own)')
|
|
359
|
-
.option('--where-status <s>', 'Match status (comma for many)')
|
|
360
|
-
.option('--where-tag <t>', 'Match rows carrying this tag (repeatable, AND)', collect)
|
|
361
|
-
.option('--where-any-tag <t>', 'Match rows carrying any of these (repeatable, OR)', collect)
|
|
362
|
-
.option('--where-assignee <a>', "Match assignee; '' = unassigned")
|
|
363
|
-
.option('--set-assignee <a>', "New assignee; '' unassigns")
|
|
364
|
-
.option('--set-status <s>', 'New status')
|
|
365
|
-
.option('--set-priority <n>', 'New priority (1-100)')
|
|
366
|
-
.option('--set-add-tag <t>', 'Add a tag (repeatable)', collect)
|
|
367
|
-
.option('--set-remove-tag <t>', 'Remove a tag (repeatable)', collect)
|
|
368
|
-
.option('--comment <text>', "Post to each task's thread — say why")
|
|
369
|
-
.option('--apply', 'Apply (dryRun:false). Without it, preview the matches only')
|
|
370
|
-
.option('--kind <k>', "all = allow the edit to touch approval rows (refused by default on --apply)")
|
|
371
|
-
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
372
|
-
.option('--json', 'Print the merged receipt as JSON')
|
|
373
|
-
.action(async (opts, sub) => {
|
|
374
|
-
const status = opts.whereStatus?.includes(',') ? opts.whereStatus.split(',').map((s) => s.trim()).filter(Boolean) : opts.whereStatus;
|
|
375
|
-
const where = {
|
|
376
|
-
...(status ? { status } : {}),
|
|
377
|
-
...(opts.whereTag?.length ? { tags: opts.whereTag } : {}),
|
|
378
|
-
...(opts.whereAnyTag?.length ? { anyTags: opts.whereAnyTag } : {}),
|
|
379
|
-
...(opts.whereAssignee !== undefined ? { assignee: opts.whereAssignee } : {}),
|
|
380
|
-
};
|
|
381
|
-
const set = {
|
|
382
|
-
...(opts.setAssignee !== undefined ? { assignee: opts.setAssignee } : {}),
|
|
383
|
-
...(opts.setStatus ? { status: opts.setStatus } : {}),
|
|
384
|
-
...(opts.setPriority ? { priority: Number(opts.setPriority) } : {}),
|
|
385
|
-
...(opts.setAddTag?.length ? { addTags: opts.setAddTag } : {}),
|
|
386
|
-
...(opts.setRemoveTag?.length ? { removeTags: opts.setRemoveTag } : {}),
|
|
387
|
-
...(opts.comment ? { comment: opts.comment } : {}),
|
|
388
|
-
};
|
|
389
|
-
if (!Object.keys(where).length)
|
|
390
|
-
return fail('name at least one --where-* filter (an empty filter would match the whole board)');
|
|
391
|
-
if (!Object.keys(set).length)
|
|
392
|
-
return fail('name at least one --set-* field or --comment');
|
|
393
|
-
if (set.priority !== undefined && !Number.isFinite(set.priority))
|
|
394
|
-
return fail('--set-priority must be a number');
|
|
395
|
-
// An approval row is a parked workflow run: a status edit strands it. Before an
|
|
396
|
-
// apply, read what the filter matches and refuse if any approval is in it.
|
|
397
|
-
if (opts.apply && opts.kind !== 'all') {
|
|
398
|
-
const seen = await readAll(opts.api, { ...(opts.workspace ? { workspace: opts.workspace } : {}), ...(where.status ? { status: where.status } : {}), ...(where.tags ? { tags: where.tags } : {}), ...(where.anyTags ? { anyTags: where.anyTags } : {}), ...(where.assignee !== undefined ? { assignee: where.assignee } : {}) });
|
|
399
|
-
if (seen.ok === false)
|
|
400
|
-
return fail(`approval guard could not read the board: ${seen.error ?? 'tasks:board failed'} — nothing applied`);
|
|
401
|
-
const approvals = (seen.tasks ?? []).filter((t) => kindOf(t) === 'approval').length;
|
|
402
|
-
if (approvals)
|
|
403
|
-
return fail(`${approvals} matched row(s) are approvals (parked workflow runs) — resolve them with tasks_approve / workflow:stop, narrow the filter, or pass --kind all. Nothing applied`);
|
|
404
|
-
if (seen.nextCursor || seen.truncated?.rows !== undefined)
|
|
405
|
-
process.stderr.write('warning approval guard read a partial board — at least the rows it saw hold no approvals\n');
|
|
406
|
-
}
|
|
407
|
-
await runBulk(sub, opts.api, { ...(opts.workspace ? { workspace: opts.workspace } : {}), where, set }, !!opts.apply);
|
|
408
|
-
});
|
|
409
|
-
cmd
|
|
410
|
-
.command('brief')
|
|
411
|
-
.description('One screen: counts, ready, blocked (by which open row), overdue, unowned, orphans, stale DONE, next five moves')
|
|
412
|
-
.option('--workspace <slug>', 'Group slug (default: your own)')
|
|
413
|
-
.option('--group <slug>', 'Alias of --workspace')
|
|
414
|
-
.option('--tree', 'This group and every descendant group')
|
|
415
|
-
.option('--kind <k>', 'work (default) | approval | all', 'work')
|
|
416
|
-
.option('--as <seat>', "ceo (whole board) | <seat> (its staked tags + rows held by it or anyone reporting to it) | director:<assignee> (that one assignee's rows only)")
|
|
417
|
-
.option('--tags <list>', 'With --as <seat>: use these comma tags as the lens instead of reading the roster')
|
|
418
|
-
.option('--roster <file>', 'With --as <seat>: read seats from a saved /api/agents/roster response')
|
|
419
|
-
.option('--score-file <path>', 'With --as ceo: where the scoreboard remembers the last brief (default ~/.config/one/briefs/<group>.json)')
|
|
420
|
-
.option('--top <n>', 'Rows per section (default 5)')
|
|
421
|
-
.option('--fresh', 'Rebuild the snapshot instead of reading the memo')
|
|
422
|
-
.option('--out <file>', 'Also write the full digest as JSON to this file')
|
|
423
|
-
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
424
|
-
.option('--json', 'Print the digest as JSON')
|
|
425
|
-
.action(async (opts, sub) => {
|
|
426
|
-
const kind = parseKind(opts.kind);
|
|
427
|
-
if (!kind)
|
|
428
|
-
return fail('--kind must be work, approval or all');
|
|
429
|
-
const group = opts.group ?? opts.workspace;
|
|
430
|
-
const director = opts.as?.startsWith('director:') ? opts.as.slice('director:'.length) : undefined;
|
|
431
|
-
let lens;
|
|
432
|
-
if (opts.as && opts.as !== 'ceo' && !director) {
|
|
433
|
-
const r = await resolveLens(opts.api, group, opts.as, opts);
|
|
434
|
-
if (!r.ok)
|
|
435
|
-
return fail(r.error);
|
|
436
|
-
lens = r;
|
|
437
|
-
}
|
|
438
|
-
const res = await readAll(opts.api, {
|
|
439
|
-
...(group ? { workspace: group } : {}),
|
|
440
|
-
...(opts.tree ? { scope: 'tree' } : {}),
|
|
441
|
-
...(director ? { assignee: director } : {}),
|
|
442
|
-
include: ['notes'],
|
|
443
|
-
...(opts.fresh ? { fresh: true } : {}),
|
|
444
|
-
});
|
|
445
|
-
if (res.ok === false)
|
|
446
|
-
return fail(res.error ?? 'tasks:board failed');
|
|
447
|
-
const all = (res.tasks ?? []);
|
|
448
|
-
const rows = lens ? lensRows(all, lens.lens) : all;
|
|
449
|
-
const d = digest(rows, { kind });
|
|
450
|
-
const meta = { ...boardMeta(res), ...(lens ? { lens: { ...lens.lens, source: lens.source, rows: rows.length, of: all.length } } : {}) };
|
|
451
|
-
const score = opts.as === 'ceo' ? await ceoScore(opts.api, group, opts.tree, all, res, opts.scoreFile) : undefined;
|
|
452
|
-
writeOut(opts.out, { meta, digest: d, ...(score ? { score } : {}) });
|
|
453
|
-
if (jsonMode(sub))
|
|
454
|
-
process.stdout.write(JSON.stringify({ meta, digest: d, ...(score ? { score } : {}) }, null, 2) + '\n');
|
|
455
|
-
else {
|
|
456
|
-
if (lens)
|
|
457
|
-
process.stdout.write(lensLine(lens.lens, lens.source, rows.length, all.length) + '\n');
|
|
458
|
-
process.stdout.write(renderDigest(d, meta, { top: opts.top ? Number(opts.top) : 5 }) + '\n');
|
|
459
|
-
if (score)
|
|
460
|
-
process.stdout.write(renderScore(score, { color: !!process.stdout.isTTY }) + '\n');
|
|
461
|
-
}
|
|
462
|
-
});
|
|
463
|
-
cmd
|
|
464
|
-
.command('route')
|
|
465
|
-
.description("Propose an owner for every unassigned row from the seats' staked tags (dry run unless --apply). Zero overlap stays unassigned and is listed by tag")
|
|
466
|
-
.option('--workspace <slug>', 'Group slug (default: your own) — also whose roster is read')
|
|
467
|
-
.option('--group <slug>', 'Alias of --workspace')
|
|
468
|
-
.option('--tree', 'This group and every descendant group (each edit carries its own row\'s workspace)')
|
|
469
|
-
.option('--roster <file>', 'Read seats from a saved /api/agents/roster response instead of the live route')
|
|
470
|
-
.option('--apply', 'Send the edits (tasks:bulk, 25 a call), each with a comment naming the matched tags')
|
|
471
|
-
.option('--out <file>', 'Write the edits as a tasks:bulk request file (review it, then: one tasks bulk --file <it>)')
|
|
472
|
-
.option('--top <n>', 'Rows per list (default 10)')
|
|
473
|
-
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
474
|
-
.option('--json', 'Print the plan as JSON')
|
|
475
|
-
.action(async (opts, sub) => {
|
|
476
|
-
const group = opts.group ?? opts.workspace;
|
|
477
|
-
const roster = await loadRoster({ base: resolveBase({ api: opts.api }, DEFAULT_API), workspace: group, file: opts.roster, headers: authHeaders() });
|
|
478
|
-
if (!roster.ok)
|
|
479
|
-
return fail(roster.error);
|
|
480
|
-
const res = await readAll(opts.api, { ...(group ? { workspace: group } : {}), ...(opts.tree ? { scope: 'tree' } : {}) });
|
|
481
|
-
if (res.ok === false)
|
|
482
|
-
return fail(res.error ?? 'tasks:board failed');
|
|
483
|
-
const plan = proposeOwners((res.tasks ?? []), roster.seats);
|
|
484
|
-
const edits = routeEdits(plan);
|
|
485
|
-
const partial = !!res.nextCursor || res.truncated?.rows !== undefined;
|
|
486
|
-
writeOut(opts.out, { ...(group ? { workspace: group } : {}), edits });
|
|
487
|
-
if (jsonMode(sub)) {
|
|
488
|
-
process.stdout.write(JSON.stringify({ meta: { ...boardMeta(res), roster: roster.source }, ...plan, edits }, null, 2) + '\n');
|
|
489
|
-
}
|
|
490
|
-
else {
|
|
491
|
-
const topN = opts.top ? Number(opts.top) : 10;
|
|
492
|
-
const ties = plan.unrouted.filter((u) => u.reason === 'tie');
|
|
493
|
-
const w = process.stdout;
|
|
494
|
-
w.write(`route: ${plan.unassigned} unassigned · proposed ${plan.proposals.length} · unrouted ${plan.unrouted.length} (no-stake ${plan.unrouted.length - ties.length} · tie ${ties.length}) · ${plan.proposals.length} + ${plan.unrouted.length} = ${plan.proposals.length + plan.unrouted.length}\n`);
|
|
495
|
-
w.write(`roster ${roster.source} · board asOf ${res.asOf ?? '?'}\n`);
|
|
496
|
-
if (partial)
|
|
497
|
-
w.write('PARTIAL: the board read was short (nextCursor/truncated) — these counts cover the rows read, not the group\n');
|
|
498
|
-
const bySeat = {};
|
|
499
|
-
for (const p of plan.proposals)
|
|
500
|
-
bySeat[p.assignee] = (bySeat[p.assignee] ?? 0) + 1;
|
|
501
|
-
w.write(` by seat ${top(bySeat, 20)}\n`);
|
|
502
|
-
w.write(` unrouted tags ${top(plan.unroutedByTag, 25)} (no seat stakes these — rows stay unassigned)\n`);
|
|
503
|
-
for (const u of ties.slice(0, topN))
|
|
504
|
-
w.write(` tie ${u.tid} [${u.tags.join(',')}] → ${u.candidates?.join(' | ')}\n`);
|
|
505
|
-
for (const p of plan.proposals.slice(0, topN))
|
|
506
|
-
w.write(` ${p.tid} → @${p.assignee} [${p.matched.join(',')}] ${p.why}\n`);
|
|
507
|
-
if (!opts.apply)
|
|
508
|
-
w.write(`DRY RUN — nothing moved. --apply sends ${edits.length} edits; --out <file> writes them for review\n`);
|
|
509
|
-
}
|
|
510
|
-
if (opts.apply && edits.length)
|
|
511
|
-
await runBulk(sub, opts.api, { ...(group ? { workspace: group } : {}), edits }, true);
|
|
512
|
-
});
|
|
513
|
-
cmd
|
|
514
|
-
.command('next')
|
|
515
|
-
.description("Take the highest-priority READY row in a seat's lens and claim it — one call instead of board → filter → pick → claim. --peek claims nothing")
|
|
516
|
-
.requiredOption('--as <seat>', 'The seat whose lens to read (its staked tags + rows held by it or its reports)')
|
|
517
|
-
.option('--peek', 'Show the row that would be claimed; claim nothing')
|
|
518
|
-
.option('--workspace <slug>', 'Group slug (default: your own) — also whose roster is read')
|
|
519
|
-
.option('--group <slug>', 'Alias of --workspace')
|
|
520
|
-
.option('--tree', 'This group and every descendant group')
|
|
521
|
-
.option('--tags <list>', 'Use these comma tags as the lens instead of reading the roster')
|
|
522
|
-
.option('--roster <file>', 'Read seats from a saved /api/agents/roster response')
|
|
523
|
-
.option('--tries <n>', 'Claim at most this many candidates before giving up (default 5)')
|
|
524
|
-
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
525
|
-
.option('--json', 'Print the result as JSON')
|
|
526
|
-
.action(async (opts, sub) => {
|
|
527
|
-
const group = opts.group ?? opts.workspace;
|
|
528
|
-
const l = await resolveLens(opts.api, group, opts.as, opts);
|
|
529
|
-
if (!l.ok)
|
|
530
|
-
return fail(l.error);
|
|
531
|
-
const res = await readAll(opts.api, { ...(group ? { workspace: group } : {}), ...(opts.tree ? { scope: 'tree' } : {}), include: ['notes'] });
|
|
532
|
-
if (res.ok === false)
|
|
533
|
-
return fail(res.error ?? 'tasks:board failed');
|
|
534
|
-
const { candidates, refusal } = nextCandidates((res.tasks ?? []), l.lens);
|
|
535
|
-
if (!candidates.length)
|
|
536
|
-
return fail(refusal ?? `nothing ready in ${opts.as}'s lens`);
|
|
537
|
-
const r = await claimNext(asker(opts.api), candidates, opts.as, { peek: !!opts.peek, ...(opts.tries ? { tries: Number(opts.tries) } : {}) });
|
|
538
|
-
if (!r.ok)
|
|
539
|
-
return fail(r.error);
|
|
540
|
-
const row = r.row;
|
|
541
|
-
if (jsonMode(sub)) {
|
|
542
|
-
process.stdout.write(JSON.stringify({ ok: true, claimed: r.claimed, claimant: r.claimant, reassigned: r.reassigned, row, candidates: candidates.length, lens: { ...l.lens, source: l.source }, asOf: res.asOf }, null, 2) + '\n');
|
|
543
|
-
return;
|
|
544
|
-
}
|
|
545
|
-
const w = process.stdout;
|
|
546
|
-
w.write(`${r.claimed ? 'claimed' : 'PEEK — nothing claimed'} ${row.tid} p${row.priority} ${row.workspace} ${row.name}\n`);
|
|
547
|
-
if (r.reassigned)
|
|
548
|
-
w.write(` claim landed as @${r.claimant} (shared key) — handed to @${opts.as} with tasks:reassign\n`);
|
|
549
|
-
w.write(` ${candidates.length} ready in ${opts.as}'s lens · tags [${row.tags.join(',')}] · roster ${l.source}\n`);
|
|
550
|
-
w.write(` notes from the board snapshot asOf ${res.asOf ?? '?'} (no live tasks:get exists yet — task:01a0b93c761aa8a4e257f65e)\n\n`);
|
|
551
|
-
w.write((row.notes ?? '(no notes)') + '\n');
|
|
552
|
-
});
|
|
553
|
-
cmd
|
|
554
|
-
.command('plan <goal>')
|
|
555
|
-
.description('Order the rows under a goal task (or carrying a tag) into waves, with the critical path in hops')
|
|
556
|
-
.option('--workspace <slug>', 'Group slug (default: your own)')
|
|
557
|
-
.option('--group <slug>', 'Alias of --workspace')
|
|
558
|
-
.option('--tree', 'This group and every descendant group')
|
|
559
|
-
.option('--kind <k>', 'work (default) | approval | all', 'work')
|
|
560
|
-
.option('--emit <what>', "dispatch = write the hand-off JSON (waves of tid/assignee/model/effort/touches/accept)")
|
|
561
|
-
.option('--out <file>', 'Write the JSON (plan, or dispatch with --emit) to this file')
|
|
562
|
-
.option('--draw', 'Draw the plan: waves as columns, the critical path as arrows. In a terminal it is LIVE — select a row, act on it (claim · done · reopen · comment), and see what became ready')
|
|
563
|
-
.option('--print', 'With --draw: print the drawing once, never interactive (the default with no TTY, e.g. an agent or a pipe)')
|
|
564
|
-
.option('--save <name>', 'With --draw: also save the drawing for `one draw <name>`')
|
|
565
|
-
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
566
|
-
.option('--json', 'Print the plan as JSON')
|
|
567
|
-
.action(async (goal, opts, sub) => {
|
|
568
|
-
const kind = parseKind(opts.kind);
|
|
569
|
-
if (!kind)
|
|
570
|
-
return fail('--kind must be work, approval or all');
|
|
571
|
-
if (opts.emit && opts.emit !== 'dispatch')
|
|
572
|
-
return fail('--emit takes: dispatch');
|
|
573
|
-
const group = opts.group ?? opts.workspace;
|
|
574
|
-
const res = await readAll(opts.api, {
|
|
575
|
-
...(group ? { workspace: group } : {}),
|
|
576
|
-
...(opts.tree ? { scope: 'tree' } : {}),
|
|
577
|
-
include: ['notes'],
|
|
578
|
-
});
|
|
579
|
-
if (res.ok === false)
|
|
580
|
-
return fail(res.error ?? 'tasks:board failed');
|
|
581
|
-
const all = (res.tasks ?? []);
|
|
582
|
-
const byGoal = all.some((r) => r.tid === goal);
|
|
583
|
-
const picked = byGoal ? subtree(all, goal) : all.filter((r) => r.tags.includes(goal));
|
|
584
|
-
const rows = filterKind(picked, kind).rows;
|
|
585
|
-
if (!rows.length)
|
|
586
|
-
return fail(`no active rows under '${goal}' — not a task id in this group, and no row carries it as a tag`);
|
|
587
|
-
if (!byGoal && res.truncated?.tags !== undefined) {
|
|
588
|
-
process.stderr.write(`warning planning from tag '${goal}' while ${res.truncated.tags} rows may be missing tags — this plan may miss rows\n`);
|
|
589
|
-
}
|
|
590
|
-
if (res.nextCursor || res.truncated?.rows !== undefined)
|
|
591
|
-
process.stderr.write('warning the board read was partial — at least these rows; the plan may be missing some\n');
|
|
592
|
-
if (opts.draw) {
|
|
593
|
-
const world = new Map(all.map((r) => [r.tid, r]));
|
|
594
|
-
const title = byGoal ? (all.find((r) => r.tid === goal)?.name ?? goal) : `tag: ${goal}`;
|
|
595
|
-
const live = !opts.print && !jsonMode(sub) && process.stdin.isTTY && process.stdout.isTTY;
|
|
596
|
-
if (!live) {
|
|
597
|
-
const d = drawPlan(rows, { world });
|
|
598
|
-
const text = [...planHeader(rows, d.plan, { title, asOf: res.asOf, world }), '', ...d.lines].join('\n');
|
|
599
|
-
if (opts.save)
|
|
600
|
-
saveDrawing(opts.save, d.lines);
|
|
601
|
-
process.stdout.write(text + '\n');
|
|
602
|
-
return;
|
|
603
|
-
}
|
|
604
|
-
const ask = asker(opts.api);
|
|
605
|
-
let first = true;
|
|
606
|
-
const load = async () => {
|
|
607
|
-
if (first) {
|
|
608
|
-
first = false;
|
|
609
|
-
return { rows, world, asOf: res.asOf };
|
|
610
|
-
}
|
|
611
|
-
const r2 = await readAll(opts.api, { ...(group ? { workspace: group } : {}), ...(opts.tree ? { scope: 'tree' } : {}), include: ['notes'] });
|
|
612
|
-
if (r2.ok === false)
|
|
613
|
-
throw new Error(r2.error ?? 'tasks:board failed');
|
|
614
|
-
const all2 = (r2.tasks ?? []);
|
|
615
|
-
const picked2 = byGoal ? subtree(all2, goal) : all2.filter((r) => r.tags.includes(goal));
|
|
616
|
-
return { rows: filterKind(picked2, kind).rows, world: new Map(all2.map((r) => [r.tid, r])), asOf: r2.asOf };
|
|
617
|
-
};
|
|
618
|
-
await runLivePlan({
|
|
619
|
-
title,
|
|
620
|
-
workspace: group,
|
|
621
|
-
load,
|
|
622
|
-
act: async (receiver, data) => {
|
|
623
|
-
const out = (await ask(receiver, data));
|
|
624
|
-
return { ok: out?.ok !== false && !out?.error, error: out?.error, detail: out?.detail };
|
|
625
|
-
},
|
|
626
|
-
});
|
|
627
|
-
return;
|
|
628
|
-
}
|
|
629
|
-
const plan = planWaves(rows);
|
|
630
|
-
const meta = { goal, ...(res.asOf ? { asOf: res.asOf } : {}), ...(res.truncated ? { truncated: res.truncated } : {}) };
|
|
631
|
-
const payload = opts.emit === 'dispatch' ? toDispatch(plan, rows, meta) : { ...meta, ...plan };
|
|
632
|
-
writeOut(opts.out, payload);
|
|
633
|
-
if (jsonMode(sub))
|
|
634
|
-
process.stdout.write(JSON.stringify(payload, null, 2) + '\n');
|
|
635
|
-
else
|
|
636
|
-
process.stdout.write(renderPlan(plan, rows, { goal }) + '\n');
|
|
637
|
-
});
|
|
638
|
-
cmd
|
|
639
|
-
.command('sequence <tids...>')
|
|
640
|
-
.description('Chain tasks in order — each waits for the one before it (one tasks:bulk call). Preview unless --apply')
|
|
641
|
-
.option('--workspace <slug>', 'Group slug (default: your own)')
|
|
642
|
-
.option('--apply', 'Write the edges. Without it, print them')
|
|
643
|
-
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
644
|
-
.option('--json', 'Print the receipt as JSON')
|
|
645
|
-
.action(async (tids, opts, sub) => {
|
|
646
|
-
const seq = sequenceEdits(tids);
|
|
647
|
-
if (!seq.ok)
|
|
648
|
-
return fail(seq.error);
|
|
649
|
-
if (!opts.apply) {
|
|
650
|
-
process.stdout.write('PREVIEW — nothing written\n');
|
|
651
|
-
for (const e of seq.edits)
|
|
652
|
-
process.stdout.write(` ${e.tid} waits for ${e.addBlockedBy?.join(',')}\n`);
|
|
653
|
-
process.stdout.write('rerun with --apply to write\n');
|
|
654
|
-
return;
|
|
655
|
-
}
|
|
656
|
-
await runEdits(sub, opts.api, opts.workspace, seq.edits);
|
|
657
|
-
});
|
|
658
|
-
cmd
|
|
659
|
-
.command('depend <tid> <blockedBy>')
|
|
660
|
-
.description('Record that <tid> waits for <blockedBy> (the server refuses reverse edges)')
|
|
661
|
-
.option('--workspace <slug>', 'Group slug (default: your own)')
|
|
662
|
-
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
663
|
-
.option('--json', 'Print the receipt as JSON')
|
|
664
|
-
.action(async (tid, blockedBy, opts, sub) => {
|
|
665
|
-
if (tid === blockedBy)
|
|
666
|
-
return fail('a task cannot wait for itself');
|
|
667
|
-
await runEdits(sub, opts.api, opts.workspace, [{ tid, addBlockedBy: [blockedBy] }]);
|
|
668
|
-
});
|
|
669
|
-
cmd
|
|
670
|
-
.command('undepend <tid> <blockedBy>')
|
|
671
|
-
.description('Remove the edge: <tid> no longer waits for <blockedBy>')
|
|
672
|
-
.option('--workspace <slug>', 'Group slug (default: your own)')
|
|
673
|
-
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
674
|
-
.option('--json', 'Print the receipt as JSON')
|
|
675
|
-
.action(async (tid, blockedBy, opts, sub) => {
|
|
676
|
-
if (tid === blockedBy)
|
|
677
|
-
return fail('a task cannot wait for itself');
|
|
678
|
-
await runEdits(sub, opts.api, opts.workspace, [{ tid, removeBlockedBy: [blockedBy] }]);
|
|
679
|
-
});
|
|
680
|
-
cmd.command('flow')
|
|
681
|
-
.description('Name each row\'s flow: plan a `Flow: <flow>` notes line + `flow-<flow>` tag for every row that has none (dry run unless --apply)')
|
|
682
|
-
.option('--workspace <slug>', 'Group slug (default: your own)')
|
|
683
|
-
.option('--tree', 'This group and every descendant group')
|
|
684
|
-
.option('--status <s>', "Board status filter ('active', 'all', or a list)", 'active')
|
|
685
|
-
.option('--classified <path>', 'classified rows JSON ({rows:[{tid,role,family,rung,flow}]}); default .claude/bake/top100-classified.json when present')
|
|
686
|
-
.option('--board <file>', 'plan from a saved tasks board --json file instead of a live read; never applies')
|
|
687
|
-
.option('--apply', 'write the edits via tasks:bulk')
|
|
688
|
-
.option('--max-age <sec>', 'Refuse --apply when the board snapshot is older than this', '120')
|
|
689
|
-
.option('--fresh', 'Rebuild the board snapshot before planning (honoured at most once per memo window)')
|
|
690
|
-
.option('--out <file>', 'Write the whole result (plan + edits) as JSON')
|
|
691
|
-
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
692
|
-
.option('--json', 'Print the result as JSON')
|
|
693
|
-
.action((opts, sub) => {
|
|
694
|
-
let classifiedPath = opts.classified;
|
|
695
|
-
if (!classifiedPath) {
|
|
696
|
-
if (existsSync('.claude/bake/top100-classified.json')) {
|
|
697
|
-
classifiedPath = '.claude/bake/top100-classified.json';
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
let rows = [];
|
|
701
|
-
if (classifiedPath) {
|
|
702
|
-
try {
|
|
703
|
-
const content = readFileSync(classifiedPath, 'utf8');
|
|
704
|
-
const j = JSON.parse(content);
|
|
705
|
-
rows = Array.isArray(j) ? j : (j.rows ?? []);
|
|
706
|
-
}
|
|
707
|
-
catch (e) {
|
|
708
|
-
return fail('--classified: ' + e.message);
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
let board = undefined;
|
|
712
|
-
if (opts.board) {
|
|
713
|
-
try {
|
|
714
|
-
board = JSON.parse(readFileSync(opts.board, 'utf8'));
|
|
715
|
-
}
|
|
716
|
-
catch (e) {
|
|
717
|
-
return fail('--board: ' + e.message);
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
runFlow(asker(opts.api), rows, {
|
|
721
|
-
workspace: opts.workspace,
|
|
722
|
-
tree: !!opts.tree,
|
|
723
|
-
status: opts.status ?? 'active',
|
|
724
|
-
apply: !!opts.apply,
|
|
725
|
-
maxAgeSec: Number(opts.maxAge ?? '120'),
|
|
726
|
-
fresh: !!opts.fresh,
|
|
727
|
-
board,
|
|
728
|
-
}).then(r => {
|
|
729
|
-
writeOut(opts.out, r);
|
|
730
|
-
if (jsonMode(sub)) {
|
|
731
|
-
console.log(JSON.stringify(r, null, 2));
|
|
732
|
-
}
|
|
733
|
-
else {
|
|
734
|
-
const sourceDesc = classifiedPath ? `notes + tags + ${classifiedPath}` : 'notes + tags only (no --classified file)';
|
|
735
|
-
renderFlowPlan(r, opts.status ?? 'active', sourceDesc);
|
|
736
|
-
}
|
|
737
|
-
if (!r.ok) {
|
|
738
|
-
fail(r.error ?? 'tasks flow failed');
|
|
739
|
-
}
|
|
740
|
-
}).catch((e) => fail(e.message));
|
|
741
|
-
});
|
|
742
|
-
return cmd;
|
|
743
|
-
}
|