cohorte 3.3.0 → 4.1.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/CHANGELOG.md +63 -0
- package/README.md +23 -3
- package/core/agents/cohorte-review.md +11 -3
- package/core/agents/implementer.template.md +19 -1
- package/core/commands/cohorte-acceptance.md +35 -0
- package/core/commands/cohorte-build.md +17 -0
- package/core/commands/cohorte-fix.md +6 -0
- package/core/commands/cohorte-foundation.md +90 -0
- package/core/commands/cohorte-lead.md +90 -0
- package/core/commands/cohorte-learn.md +67 -0
- package/core/commands/cohorte-po.md +76 -0
- package/core/commands/cohorte-product-map.md +53 -0
- package/core/commands/cohorte-retro.md +44 -13
- package/core/commands/cohorte-scaffold.md +59 -0
- package/core/commands/cohorte-vision.md +80 -0
- package/lib/install.js +2 -0
- package/lib/project.js +1 -1
- package/lib/registry.js +4 -3
- package/package.json +2 -2
- package/profile/PIPELINE.template.md +3 -1
- package/profile/schema/kanban.md +23 -0
- package/scripts/kanban-move.sh +45 -11
- package/ui/dist-server/server/agents.js +100 -0
- package/ui/dist-server/server/decider.js +241 -0
- package/ui/dist-server/server/features.js +128 -0
- package/ui/dist-server/server/flow.js +934 -0
- package/ui/dist-server/server/founding.js +706 -0
- package/ui/dist-server/server/gitinfo.js +22 -0
- package/ui/dist-server/server/history.js +10 -3
- package/ui/dist-server/server/legacy.js +3 -1
- package/ui/dist-server/server/next.js +91 -0
- package/ui/dist-server/server/runs.js +73 -11
- package/ui/dist-server/server/server.js +222 -6
- package/ui/dist-server/server/settings.js +81 -0
- package/ui/dist-server/server/tracker.js +438 -0
- package/ui/dist-server/shared/blocks.js +165 -0
- package/ui/dist-web/assets/index-BfN944Jm.js +165 -0
- package/ui/dist-web/assets/{style-0oNNMjwU.css → style-BMfadlCl.css} +1 -1
- package/ui/dist-web/index.html +2 -2
- package/ui/dist-web/assets/index-Clp1YW4S.js +0 -152
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Per-project settings of the company flow, kept by cohorte ui on this machine:
|
|
3
|
+
// <globalDir>/cohorte-ui/settings/<projectId>.json. They are the dials a person sets from the page — how much the
|
|
4
|
+
// decider may settle alone, which model each role runs on, how many fix rounds the autopilot tries before it asks.
|
|
5
|
+
// Nothing here is committed to the project: two teammates may run different models.
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.SettingsStore = exports.escalate = exports.AUTONOMY = exports.DEFAULTS = void 0;
|
|
11
|
+
exports.normalize = normalize;
|
|
12
|
+
const fs_1 = __importDefault(require("fs"));
|
|
13
|
+
const path_1 = __importDefault(require("path"));
|
|
14
|
+
const runs_1 = require("./runs");
|
|
15
|
+
/**
|
|
16
|
+
* Routing defaults. The strongest model where judgment is the product (talking to the business, framing with the
|
|
17
|
+
* developer); the mid one where a frozen spec already did the thinking (build, fix, review); the light one where
|
|
18
|
+
* the work is mechanical or is a vote (verify, the decider's first round). The decider escalates a split vote one
|
|
19
|
+
* step up before it bothers anyone; a fix round that makes no progress escalates its model the same way.
|
|
20
|
+
*/
|
|
21
|
+
exports.DEFAULTS = {
|
|
22
|
+
autonomy: 'balanced',
|
|
23
|
+
models: {
|
|
24
|
+
po: 'opus', lead: 'opus', build: 'sonnet', implementer: 'sonnet', review: 'sonnet', fix: 'sonnet', verify: 'haiku',
|
|
25
|
+
ship: 'sonnet', learn: 'sonnet', acceptance: 'sonnet', productMap: 'sonnet', scaffold: 'sonnet', setup: 'sonnet', decider: 'haiku', deciderEscalation: 'sonnet',
|
|
26
|
+
},
|
|
27
|
+
deciderVotes: 3, maxRounds: 3, mergeMethod: 'squash', autopilot: true, requester: '',
|
|
28
|
+
};
|
|
29
|
+
exports.AUTONOMY = ['prudent', 'balanced', 'autonomous'];
|
|
30
|
+
const ROLES = Object.keys(exports.DEFAULTS.models);
|
|
31
|
+
/** The escalation ladder, by family. A model outside it (a full id) escalates to itself. */
|
|
32
|
+
const LADDER = ['haiku', 'sonnet', 'opus', 'fable'];
|
|
33
|
+
const escalate = (model) => {
|
|
34
|
+
const i = LADDER.indexOf(model);
|
|
35
|
+
return i >= 0 && i < LADDER.length - 1 ? LADDER[i + 1] : model;
|
|
36
|
+
};
|
|
37
|
+
exports.escalate = escalate;
|
|
38
|
+
function normalize(v, base = exports.DEFAULTS) {
|
|
39
|
+
const o = (v && typeof v === 'object' ? v : {});
|
|
40
|
+
const models = { ...base.models };
|
|
41
|
+
for (const r of ROLES)
|
|
42
|
+
if (typeof o.models?.[r] === 'string' && runs_1.MODEL.test(o.models[r].trim()))
|
|
43
|
+
models[r] = o.models[r].trim();
|
|
44
|
+
const int = (x, lo, hi, d) => (typeof x === 'number' && Number.isInteger(x) && x >= lo && x <= hi ? x : d);
|
|
45
|
+
return {
|
|
46
|
+
autonomy: exports.AUTONOMY.includes(o.autonomy) ? o.autonomy : base.autonomy,
|
|
47
|
+
models,
|
|
48
|
+
deciderVotes: int(o.deciderVotes, 1, 7, base.deciderVotes),
|
|
49
|
+
maxRounds: int(o.maxRounds, 1, 8, base.maxRounds),
|
|
50
|
+
mergeMethod: ['squash', 'merge', 'rebase'].includes(o.mergeMethod) ? o.mergeMethod : base.mergeMethod,
|
|
51
|
+
autopilot: typeof o.autopilot === 'boolean' ? o.autopilot : base.autopilot,
|
|
52
|
+
requester: typeof o.requester === 'string' ? o.requester.trim().slice(0, 80) : base.requester,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
class SettingsStore {
|
|
56
|
+
dir;
|
|
57
|
+
constructor(dir) {
|
|
58
|
+
this.dir = dir;
|
|
59
|
+
}
|
|
60
|
+
file(projectId) { return path_1.default.join(this.dir, `${projectId.replace(/[^A-Za-z0-9._-]/g, '')}.json`); }
|
|
61
|
+
get(projectId) {
|
|
62
|
+
try {
|
|
63
|
+
return normalize(JSON.parse(fs_1.default.readFileSync(this.file(projectId), 'utf8')));
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return normalize({});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** Merges a partial update (models merged per role) and returns what was stored. */
|
|
70
|
+
set(projectId, patch) {
|
|
71
|
+
const cur = this.get(projectId);
|
|
72
|
+
const p = (patch && typeof patch === 'object' ? patch : {});
|
|
73
|
+
const next = normalize({ ...cur, ...p, models: { ...cur.models, ...(p.models && typeof p.models === 'object' ? p.models : {}) } }, cur);
|
|
74
|
+
fs_1.default.mkdirSync(this.dir, { recursive: true });
|
|
75
|
+
const f = this.file(projectId);
|
|
76
|
+
fs_1.default.writeFileSync(`${f}.tmp`, JSON.stringify(next, null, 2));
|
|
77
|
+
fs_1.default.renameSync(`${f}.tmp`, f);
|
|
78
|
+
return next;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.SettingsStore = SettingsStore;
|
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The ticket tracker of the company flow. Obsidian first: when the project has a kanban board in the user's
|
|
3
|
+
// cohorte.config.yaml, every ticket is a note in a `Tickets/` folder next to that board, and its card on the board
|
|
4
|
+
// links to it. Without a board, tickets live on this machine under <globalDir>/cohorte-ui/tickets/<projectId>/.
|
|
5
|
+
// Either way the format is the same markdown note, so a person can open and edit it by hand (Obsidian or not),
|
|
6
|
+
// and the agents only ever see its content inlined in their prompt — they never need to know where it lives.
|
|
7
|
+
//
|
|
8
|
+
// The board is moved through scripts/kanban-move.sh (its lock, its layout candidates) with the board path
|
|
9
|
+
// resolved here, so a ticket card and a spec card are the same card: the `#<id>` tag is the ticket id, which is
|
|
10
|
+
// also the feature id the pipeline commands move.
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.TrackerError = exports.Tracker = exports.isTicketId = exports.configPath = exports.COMPANY_COLUMNS = exports.STATUSES = void 0;
|
|
16
|
+
exports.trackerOf = trackerOf;
|
|
17
|
+
exports.serialize = serialize;
|
|
18
|
+
exports.parse = parse;
|
|
19
|
+
exports.ticketBrief = ticketBrief;
|
|
20
|
+
exports.trackerFor = trackerFor;
|
|
21
|
+
exports.withVault = withVault;
|
|
22
|
+
exports.withBoard = withBoard;
|
|
23
|
+
exports.companyBoard = companyBoard;
|
|
24
|
+
exports.connectObsidian = connectObsidian;
|
|
25
|
+
const fs_1 = __importDefault(require("fs"));
|
|
26
|
+
const path_1 = __importDefault(require("path"));
|
|
27
|
+
const child_process_1 = require("child_process");
|
|
28
|
+
const legacy_1 = require("./legacy");
|
|
29
|
+
const blocks_1 = require("../shared/blocks");
|
|
30
|
+
const ops_1 = require("./ops");
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
32
|
+
const yaml = require(path_1.default.join(legacy_1.repo, 'lib', 'yaml.js'));
|
|
33
|
+
exports.STATUSES = ['discussion', 'validate', 'backlog', 'framing', 'building', 'checkpoint', 'pr', 'acceptance', 'done', 'rejected'];
|
|
34
|
+
/** The company layout, in board order: stage key → heading. kanban-move.sh knows the same keys. */
|
|
35
|
+
exports.COMPANY_COLUMNS = [
|
|
36
|
+
['ideas', 'Ideas'], ['discussion', 'Discussion'], ['validate', 'To validate · business'], ['backlog', 'Backlog'], ['framing', 'Framing'],
|
|
37
|
+
['building', 'In progress'], ['checkpoint', 'To validate · dev'], ['pr', 'PR open'], ['acceptance', 'Acceptance'], ['done', 'Done'],
|
|
38
|
+
];
|
|
39
|
+
const QUEUE = new Map();
|
|
40
|
+
const STAGE_OF = {
|
|
41
|
+
discussion: 'discussion', validate: 'validate', backlog: 'backlog', framing: 'framing', building: 'building', checkpoint: 'checkpoint',
|
|
42
|
+
pr: 'pr', acceptance: 'acceptance', done: 'done', rejected: 'done',
|
|
43
|
+
};
|
|
44
|
+
const configPath = (globalDir) => process.env.COHORTE_CONFIG || path_1.default.join(globalDir, 'cohorte.config.yaml');
|
|
45
|
+
exports.configPath = configPath;
|
|
46
|
+
const ID = /^[a-z0-9][a-z0-9-]{0,62}$/;
|
|
47
|
+
const isTicketId = (s) => typeof s === 'string' && ID.test(s);
|
|
48
|
+
exports.isTicketId = isTicketId;
|
|
49
|
+
// ---------------------------------------------------------------------------------------------------------------
|
|
50
|
+
// Resolution
|
|
51
|
+
function trackerOf(globalDir, root, projectId) {
|
|
52
|
+
const projectName = (0, ops_1.readProfile)(root).name || null;
|
|
53
|
+
const local = (reason) => ({ kind: 'local', dir: path_1.default.join(globalDir, 'cohorte-ui', 'tickets', projectId), board: null, reason, projectName });
|
|
54
|
+
let cfg = null;
|
|
55
|
+
try {
|
|
56
|
+
cfg = yaml.parse(fs_1.default.readFileSync((0, exports.configPath)(globalDir), 'utf8'));
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return local('no cohorte.config.yaml — connect Obsidian in Settings to keep tickets in your vault');
|
|
60
|
+
}
|
|
61
|
+
if (cfg?.enabled === false)
|
|
62
|
+
return local('cohorte capabilities are disabled in cohorte.config.yaml (enabled: false)');
|
|
63
|
+
if (cfg?.kanban?.enabled !== true)
|
|
64
|
+
return local('the kanban mirror is off (kanban.enabled is not true)');
|
|
65
|
+
const vault = typeof cfg?.obsidian?.vault_path === 'string' ? cfg.obsidian.vault_path : '';
|
|
66
|
+
if (!vault)
|
|
67
|
+
return local('obsidian.vault_path is not set');
|
|
68
|
+
if (!projectName)
|
|
69
|
+
return local('this project has no `name` in its PIPELINE.md profile');
|
|
70
|
+
const rel = cfg?.kanban?.boards?.[projectName]?.board;
|
|
71
|
+
if (typeof rel !== 'string' || !rel)
|
|
72
|
+
return local(`no board for "${projectName}" in cohorte.config.yaml`);
|
|
73
|
+
const board = path_1.default.join(vault, rel);
|
|
74
|
+
if (!fs_1.default.existsSync(board))
|
|
75
|
+
return local(`the board file is missing: ${board}`);
|
|
76
|
+
return { kind: 'obsidian', dir: path_1.default.join(path_1.default.dirname(board), 'Tickets'), board, reason: '', projectName };
|
|
77
|
+
}
|
|
78
|
+
// ---------------------------------------------------------------------------------------------------------------
|
|
79
|
+
// The note format
|
|
80
|
+
const q = (s) => JSON.stringify(s);
|
|
81
|
+
const today = () => new Date().toISOString();
|
|
82
|
+
function serialize(t) {
|
|
83
|
+
const fm = [
|
|
84
|
+
'---', `id: ${t.id}`, `title: ${q(t.title)}`, `type: ${t.type}`, `status: ${t.status}`, `requester: ${q(t.requester)}`,
|
|
85
|
+
`priority: ${t.priority}`, `size: ${q(t.size)}`, `created: ${t.created}`, `updated: ${t.updated}`,
|
|
86
|
+
`parent: ${t.parent ? t.parent : 'null'}`, `pr: ${t.pr ? q(t.pr) : 'null'}`, `conversation: ${t.conversation ? t.conversation : 'null'}`,
|
|
87
|
+
'tags: [cohorte-ticket]', '---', '',
|
|
88
|
+
];
|
|
89
|
+
const sec = (h, body) => (body.trim() ? [`## ${h}`, '', body.trim(), ''] : []);
|
|
90
|
+
const bullets = (xs, num = false) => xs.map((x, i) => (num ? `- C${i + 1} — ${x}` : `- ${x}`)).join('\n');
|
|
91
|
+
const acc = t.acceptance
|
|
92
|
+
? [`_${t.acceptance.at.slice(0, 10)}_`, '', t.acceptance.summary, '',
|
|
93
|
+
...(t.acceptance.changes.length ? ['### What changed', '', bullets(t.acceptance.changes), ''] : []),
|
|
94
|
+
...(t.acceptance.howToTest.length ? ['### How to test', '', t.acceptance.howToTest.map((x, i) => `${i + 1}. ${x}`).join('\n'), ''] : []),
|
|
95
|
+
...(t.acceptance.outOfScope.length ? ['### Not in this delivery', '', bullets(t.acceptance.outOfScope), ''] : [])].join('\n')
|
|
96
|
+
: '';
|
|
97
|
+
return [
|
|
98
|
+
...fm, `# ${t.title}`, '',
|
|
99
|
+
...sec('Need', t.need), ...sec('Value', t.value), ...sec('Acceptance criteria', bullets(t.criteria, true)),
|
|
100
|
+
...sec('Out of scope', bullets(t.outOfScope)), ...sec('Notes', t.notes), ...sec('Acceptance note', acc), ...sec('Feedback', bullets(t.feedback)),
|
|
101
|
+
].join('\n').replace(/\n{3,}/g, '\n\n');
|
|
102
|
+
}
|
|
103
|
+
function scalar(v) {
|
|
104
|
+
if (v === undefined)
|
|
105
|
+
return '';
|
|
106
|
+
const s = v.trim();
|
|
107
|
+
if (s === 'null' || s === '~')
|
|
108
|
+
return '';
|
|
109
|
+
if (s.startsWith('"')) {
|
|
110
|
+
try {
|
|
111
|
+
return String(JSON.parse(s));
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
return s.slice(1, -1);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (s.startsWith("'") && s.endsWith("'"))
|
|
118
|
+
return s.slice(1, -1).replace(/''/g, "'");
|
|
119
|
+
return s;
|
|
120
|
+
}
|
|
121
|
+
const bulletsOf = (body) => body.split('\n').map((l) => l.match(/^\s*(?:[-*]|\d+\.)\s+(.*)$/)?.[1] ?? '').filter(Boolean);
|
|
122
|
+
/** Parses a ticket note. Tolerant of hand edits: unknown sections go to notes, unknown values to defaults. */
|
|
123
|
+
function parse(text, fallbackId) {
|
|
124
|
+
const m = text.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/);
|
|
125
|
+
if (!m)
|
|
126
|
+
return null;
|
|
127
|
+
const fm = {};
|
|
128
|
+
for (const line of m[1].split(/\r?\n/)) {
|
|
129
|
+
const kv = line.match(/^([A-Za-z_][\w-]*):\s?(.*)$/);
|
|
130
|
+
if (kv)
|
|
131
|
+
fm[kv[1]] = kv[2];
|
|
132
|
+
}
|
|
133
|
+
if (fm.tags !== undefined && !/cohorte-ticket/.test(fm.tags))
|
|
134
|
+
return null;
|
|
135
|
+
const sections = {};
|
|
136
|
+
let cur = '';
|
|
137
|
+
for (const line of m[2].split(/\r?\n/)) {
|
|
138
|
+
const h = line.match(/^## (.+?)\s*$/);
|
|
139
|
+
if (h) {
|
|
140
|
+
cur = h[1].toLowerCase();
|
|
141
|
+
sections[cur] = '';
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (cur)
|
|
145
|
+
sections[cur] += `${line}\n`;
|
|
146
|
+
}
|
|
147
|
+
const oneOf = (v, all, d) => (all.includes(v) ? v : d);
|
|
148
|
+
let acceptance = null;
|
|
149
|
+
const acc = sections['acceptance note'];
|
|
150
|
+
if (acc && acc.trim()) {
|
|
151
|
+
const parts = { '': '' };
|
|
152
|
+
let sub = '';
|
|
153
|
+
for (const line of acc.split('\n')) {
|
|
154
|
+
const h = line.match(/^### (.+?)\s*$/);
|
|
155
|
+
if (h) {
|
|
156
|
+
sub = h[1].toLowerCase();
|
|
157
|
+
parts[sub] = '';
|
|
158
|
+
}
|
|
159
|
+
else
|
|
160
|
+
parts[sub] += `${line}\n`;
|
|
161
|
+
}
|
|
162
|
+
const head = parts[''].trim();
|
|
163
|
+
const at = head.match(/^_(\d{4}-\d{2}-\d{2})[^_]*_/);
|
|
164
|
+
acceptance = { at: at ? at[1] : '', summary: head.replace(/^_[^_]*_\s*/, '').trim(), changes: bulletsOf(parts['what changed'] || ''),
|
|
165
|
+
howToTest: bulletsOf(parts['how to test'] || ''), outOfScope: bulletsOf(parts['not in this delivery'] || '') };
|
|
166
|
+
}
|
|
167
|
+
const id = scalar(fm.id) || fallbackId;
|
|
168
|
+
if (!(0, exports.isTicketId)(id))
|
|
169
|
+
return null;
|
|
170
|
+
const known = ['need', 'value', 'acceptance criteria', 'out of scope', 'notes', 'acceptance note', 'feedback'];
|
|
171
|
+
const extra = Object.entries(sections).filter(([k]) => !known.includes(k)).map(([k, v]) => `### ${k}\n${v.trim()}`).join('\n\n');
|
|
172
|
+
return {
|
|
173
|
+
id, title: scalar(fm.title) || id, type: oneOf(scalar(fm.type), blocks_1.TYPES, 'feature'), status: oneOf(scalar(fm.status), exports.STATUSES, 'backlog'),
|
|
174
|
+
requester: scalar(fm.requester), priority: oneOf(scalar(fm.priority), blocks_1.PRIORITIES, 'medium'), size: oneOf(scalar(fm.size), blocks_1.SIZES, '?'),
|
|
175
|
+
created: scalar(fm.created), updated: scalar(fm.updated), parent: scalar(fm.parent) || null, pr: scalar(fm.pr) || null,
|
|
176
|
+
conversation: scalar(fm.conversation) || null,
|
|
177
|
+
need: (sections.need || '').trim(), value: (sections.value || '').trim(),
|
|
178
|
+
criteria: bulletsOf(sections['acceptance criteria'] || '').map((c) => c.replace(/^C\d+\s*[—–-]\s*/, '')),
|
|
179
|
+
outOfScope: bulletsOf(sections['out of scope'] || ''), notes: [(sections.notes || '').trim(), extra].filter(Boolean).join('\n\n'),
|
|
180
|
+
acceptance, feedback: bulletsOf(sections.feedback || ''),
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/** Ticket text as an agent reads it in its prompt. */
|
|
184
|
+
function ticketBrief(t) {
|
|
185
|
+
return [
|
|
186
|
+
`Ticket ${t.id} — ${t.title}`, `type: ${t.type} · priority: ${t.priority} · size: ${t.size} · requester: ${t.requester || 'unknown'}${t.parent ? ` · follows up ${t.parent}` : ''}`,
|
|
187
|
+
'', 'Need:', t.need || '(not stated)', '', 'Value:', t.value || '(not stated)', '',
|
|
188
|
+
'Acceptance criteria (business language):', ...(t.criteria.length ? t.criteria.map((c, i) => `- C${i + 1} — ${c}`) : ['(none)']),
|
|
189
|
+
'', 'Out of scope:', ...(t.outOfScope.length ? t.outOfScope.map((c) => `- ${c}`) : ['(none)']),
|
|
190
|
+
...(t.notes ? ['', 'Notes:', t.notes] : []),
|
|
191
|
+
...(t.feedback.length ? ['', 'Feedback from acceptance:', ...t.feedback.map((f) => `- ${f}`)] : []),
|
|
192
|
+
].join('\n');
|
|
193
|
+
}
|
|
194
|
+
// ---------------------------------------------------------------------------------------------------------------
|
|
195
|
+
// The store
|
|
196
|
+
class Tracker {
|
|
197
|
+
info;
|
|
198
|
+
vault;
|
|
199
|
+
constructor(info, vault = null) {
|
|
200
|
+
this.info = info;
|
|
201
|
+
this.vault = vault;
|
|
202
|
+
}
|
|
203
|
+
file(id) { return path_1.default.join(this.info.dir, `${id}.md`); }
|
|
204
|
+
list() {
|
|
205
|
+
let names = [];
|
|
206
|
+
try {
|
|
207
|
+
names = fs_1.default.readdirSync(this.info.dir).filter((n) => n.endsWith('.md'));
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
return [];
|
|
211
|
+
}
|
|
212
|
+
const out = [];
|
|
213
|
+
for (const n of names) {
|
|
214
|
+
try {
|
|
215
|
+
const t = parse(fs_1.default.readFileSync(path_1.default.join(this.info.dir, n), 'utf8'), n.slice(0, -3));
|
|
216
|
+
if (t)
|
|
217
|
+
out.push(t);
|
|
218
|
+
}
|
|
219
|
+
catch { /* unreadable note */ }
|
|
220
|
+
}
|
|
221
|
+
return out.sort((a, b) => b.updated.localeCompare(a.updated));
|
|
222
|
+
}
|
|
223
|
+
get(id) {
|
|
224
|
+
if (!(0, exports.isTicketId)(id))
|
|
225
|
+
return null;
|
|
226
|
+
try {
|
|
227
|
+
return parse(fs_1.default.readFileSync(this.file(id), 'utf8'), id);
|
|
228
|
+
}
|
|
229
|
+
catch {
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
freeId(title) {
|
|
234
|
+
const base = (0, blocks_1.slug)(title, 48);
|
|
235
|
+
let id = base;
|
|
236
|
+
for (let i = 2; fs_1.default.existsSync(this.file(id)); i++)
|
|
237
|
+
id = `${base}-${i}`;
|
|
238
|
+
return id;
|
|
239
|
+
}
|
|
240
|
+
write(t) {
|
|
241
|
+
fs_1.default.mkdirSync(this.info.dir, { recursive: true });
|
|
242
|
+
const f = this.file(t.id);
|
|
243
|
+
const tmp = `${f}.${process.pid}.tmp`;
|
|
244
|
+
fs_1.default.writeFileSync(tmp, serialize(t));
|
|
245
|
+
fs_1.default.renameSync(tmp, f);
|
|
246
|
+
return t;
|
|
247
|
+
}
|
|
248
|
+
create(p, extra = {}) {
|
|
249
|
+
const now = today();
|
|
250
|
+
const t = {
|
|
251
|
+
id: this.freeId(p.title), title: p.title, type: p.type || 'feature', status: 'backlog', requester: '', priority: p.priority || 'medium', size: p.size || '?',
|
|
252
|
+
created: now.slice(0, 10), updated: now, parent: p.parent || null, pr: null, conversation: null,
|
|
253
|
+
need: p.need || '', value: p.value || '', criteria: p.criteria || [], outOfScope: p.outOfScope || [], notes: '', acceptance: null, feedback: [], ...extra,
|
|
254
|
+
};
|
|
255
|
+
return this.write(t);
|
|
256
|
+
}
|
|
257
|
+
update(id, patch) {
|
|
258
|
+
const cur = this.get(id);
|
|
259
|
+
if (!cur)
|
|
260
|
+
return null;
|
|
261
|
+
return this.write({ ...cur, ...patch, id: cur.id, created: cur.created, updated: today() });
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Moves the ticket's card to the column of its status. Never throws: the board is a mirror.
|
|
265
|
+
* Moves on one board run one after another IN THE ORDER they were asked: kanban-move.sh's lock serializes
|
|
266
|
+
* writers but not their order, and two moves a few milliseconds apart (building, then checkpoint) would
|
|
267
|
+
* otherwise land in either order.
|
|
268
|
+
*/
|
|
269
|
+
move(t) {
|
|
270
|
+
if (this.info.kind !== 'obsidian' || !this.info.board)
|
|
271
|
+
return Promise.resolve('');
|
|
272
|
+
const key = this.info.board;
|
|
273
|
+
const run = (QUEUE.get(key) || Promise.resolve('')).then(() => this.moveNow(t), () => this.moveNow(t));
|
|
274
|
+
QUEUE.set(key, run);
|
|
275
|
+
void run.finally(() => { if (QUEUE.get(key) === run)
|
|
276
|
+
QUEUE.delete(key); });
|
|
277
|
+
return run;
|
|
278
|
+
}
|
|
279
|
+
moveNow(t) {
|
|
280
|
+
// the status at the time of the move, not of the call: a later write may have moved on already
|
|
281
|
+
const cur = this.get(t.id) || t;
|
|
282
|
+
t = cur;
|
|
283
|
+
const stage = STAGE_OF[t.status];
|
|
284
|
+
const rel = this.vault ? path_1.default.relative(this.vault, this.file(t.id)).replace(/\\/g, '/').replace(/\.md$/, '') : t.id;
|
|
285
|
+
const label = t.title.replace(/[[\]|#\n]/g, ' ').replace(/\s+/g, ' ').trim();
|
|
286
|
+
const title = `[[${rel}|${label}]]`;
|
|
287
|
+
return new Promise((resolve) => {
|
|
288
|
+
const child = (0, child_process_1.spawn)('sh', [path_1.default.join(legacy_1.repo, 'scripts', 'kanban-move.sh'), this.info.board, t.id, stage, '--title', title], { stdio: ['ignore', 'pipe', 'pipe'] });
|
|
289
|
+
let out = '';
|
|
290
|
+
child.stdout.on('data', (d) => { out += d; });
|
|
291
|
+
child.stderr.on('data', (d) => { out += d; });
|
|
292
|
+
child.on('error', (e) => resolve(`kanban: ${e.message}`));
|
|
293
|
+
child.on('close', () => resolve(out.trim()));
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
exports.Tracker = Tracker;
|
|
298
|
+
function trackerFor(globalDir, root, projectId) {
|
|
299
|
+
const info = trackerOf(globalDir, root, projectId);
|
|
300
|
+
let vault = null;
|
|
301
|
+
if (info.kind === 'obsidian') {
|
|
302
|
+
try {
|
|
303
|
+
vault = yaml.parse(fs_1.default.readFileSync((0, exports.configPath)(globalDir), 'utf8'))?.obsidian?.vault_path || null;
|
|
304
|
+
}
|
|
305
|
+
catch {
|
|
306
|
+
vault = null;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return new Tracker(info, vault);
|
|
310
|
+
}
|
|
311
|
+
// ---------------------------------------------------------------------------------------------------------------
|
|
312
|
+
// Connecting Obsidian from the page — targeted edits of the user's hand-written config (never a rewrite).
|
|
313
|
+
class TrackerError extends Error {
|
|
314
|
+
}
|
|
315
|
+
exports.TrackerError = TrackerError;
|
|
316
|
+
const lines = (t) => t.split('\n');
|
|
317
|
+
const indentOf = (l) => l.match(/^ */)[0].length;
|
|
318
|
+
const isKey = (l, key) => new RegExp(`^\\s*${key}:(\\s|$)`).test(l);
|
|
319
|
+
/** [start, end) of the block owned by the key at line i (lines more indented than it, blanks included). */
|
|
320
|
+
function blockEnd(ls, i) {
|
|
321
|
+
const ind = indentOf(ls[i]);
|
|
322
|
+
let j = i + 1;
|
|
323
|
+
while (j < ls.length && (ls[j].trim() === '' || ls[j].trim().startsWith('#') || indentOf(ls[j]) > ind))
|
|
324
|
+
j++;
|
|
325
|
+
while (j > i + 1 && ls[j - 1].trim() === '')
|
|
326
|
+
j--;
|
|
327
|
+
return j;
|
|
328
|
+
}
|
|
329
|
+
function topKey(ls, key) { return ls.findIndex((l) => indentOf(l) === 0 && isKey(l, key)); }
|
|
330
|
+
function childKey(ls, parent, key) {
|
|
331
|
+
const end = blockEnd(ls, parent);
|
|
332
|
+
for (let i = parent + 1; i < end; i++)
|
|
333
|
+
if (ls[i].trim() && !ls[i].trim().startsWith('#') && isKey(ls[i], key) && indentOf(ls[i]) > indentOf(ls[parent])) {
|
|
334
|
+
// a direct child: the first non-comment line's indent under the parent
|
|
335
|
+
return i;
|
|
336
|
+
}
|
|
337
|
+
return -1;
|
|
338
|
+
}
|
|
339
|
+
function setValue(line, value) {
|
|
340
|
+
const m = line.match(/^(\s*[\w.-]+:)\s*(?:"[^"]*"|'[^']*'|[^#]*?)?\s*(#.*)?$/);
|
|
341
|
+
if (!m)
|
|
342
|
+
return line;
|
|
343
|
+
return `${m[1]} ${value}${m[2] ? ` ${m[2]}` : ''}`;
|
|
344
|
+
}
|
|
345
|
+
function withVault(text, vault) {
|
|
346
|
+
const ls = lines(text);
|
|
347
|
+
const ob = topKey(ls, 'obsidian');
|
|
348
|
+
if (ob < 0)
|
|
349
|
+
return `${text.replace(/\n*$/, '\n')}\nobsidian:\n vault_path: ${q(vault)}\n`;
|
|
350
|
+
const vp = childKey(ls, ob, 'vault_path');
|
|
351
|
+
if (vp < 0)
|
|
352
|
+
ls.splice(ob + 1, 0, ` vault_path: ${q(vault)}`);
|
|
353
|
+
else
|
|
354
|
+
ls[vp] = setValue(ls[vp], q(vault));
|
|
355
|
+
return ls.join('\n');
|
|
356
|
+
}
|
|
357
|
+
function withBoard(text, name, rel) {
|
|
358
|
+
let ls = lines(text);
|
|
359
|
+
let kb = topKey(ls, 'kanban');
|
|
360
|
+
if (kb < 0) {
|
|
361
|
+
ls = lines(`${text.replace(/\n*$/, '\n')}\nkanban:\n enabled: true\n boards: {}\n`);
|
|
362
|
+
kb = topKey(ls, 'kanban');
|
|
363
|
+
}
|
|
364
|
+
const en = childKey(ls, kb, 'enabled');
|
|
365
|
+
if (en < 0)
|
|
366
|
+
ls.splice(kb + 1, 0, ' enabled: true');
|
|
367
|
+
else
|
|
368
|
+
ls[en] = setValue(ls[en], 'true');
|
|
369
|
+
let bd = childKey(ls, kb, 'boards');
|
|
370
|
+
if (bd < 0) {
|
|
371
|
+
const end = blockEnd(ls, kb);
|
|
372
|
+
ls.splice(end, 0, ' boards: {}');
|
|
373
|
+
bd = end;
|
|
374
|
+
}
|
|
375
|
+
const ind = ' '.repeat(indentOf(ls[bd]) + 2);
|
|
376
|
+
if (/boards:\s*\{\s*\}/.test(ls[bd]))
|
|
377
|
+
ls[bd] = ls[bd].replace(/boards:\s*\{\s*\}/, 'boards:');
|
|
378
|
+
const entry = childKey(ls, bd, name.replace(/[.]/g, '\\.'));
|
|
379
|
+
if (entry < 0)
|
|
380
|
+
ls.splice(bd + 1, 0, `${ind}${name}:`, `${ind} board: ${q(rel)}`);
|
|
381
|
+
else {
|
|
382
|
+
const b = childKey(ls, entry, 'board');
|
|
383
|
+
if (b < 0)
|
|
384
|
+
ls.splice(entry + 1, 0, `${ind} board: ${q(rel)}`);
|
|
385
|
+
else
|
|
386
|
+
ls[b] = setValue(ls[b], q(rel));
|
|
387
|
+
}
|
|
388
|
+
return ls.join('\n');
|
|
389
|
+
}
|
|
390
|
+
function companyBoard() {
|
|
391
|
+
return [
|
|
392
|
+
'---', '', 'kanban-plugin: board', '', '---', '',
|
|
393
|
+
...exports.COMPANY_COLUMNS.flatMap(([, h]) => [`## ${h}`, '', '']),
|
|
394
|
+
'%% kanban:settings', '```', JSON.stringify({ 'kanban-plugin': 'board', 'list-collapse': exports.COMPANY_COLUMNS.map(() => false) }), '```', '%%', '',
|
|
395
|
+
].join('\n');
|
|
396
|
+
}
|
|
397
|
+
/** Points this project at a board in an Obsidian vault: config edited, board created (company layout) if absent. */
|
|
398
|
+
function connectObsidian(globalDir, root, body) {
|
|
399
|
+
const name = (0, ops_1.readProfile)(root).name;
|
|
400
|
+
if (!name)
|
|
401
|
+
throw new TrackerError('this project has no `name` in its PIPELINE.md profile — run /cohorte-init-pipeline first');
|
|
402
|
+
if (!/^[\w.-]+$/.test(name))
|
|
403
|
+
throw new TrackerError(`the project name "${name}" cannot be a config key (letters, digits, . _ - only)`);
|
|
404
|
+
const vault = typeof body.vault === 'string' ? body.vault.trim() : '';
|
|
405
|
+
if (!vault || !path_1.default.isAbsolute(vault))
|
|
406
|
+
throw new TrackerError('the vault must be an absolute path');
|
|
407
|
+
if (!fs_1.default.existsSync(vault) || !fs_1.default.statSync(vault).isDirectory())
|
|
408
|
+
throw new TrackerError(`no folder at ${vault}`);
|
|
409
|
+
const rel = (typeof body.board === 'string' && body.board.trim() ? body.board.trim() : `${name}/Tasks.md`).replace(/\\/g, '/');
|
|
410
|
+
if (!rel.endsWith('.md') || rel.startsWith('/') || rel.split('/').includes('..'))
|
|
411
|
+
throw new TrackerError('the board must be a .md path inside the vault');
|
|
412
|
+
const cfg = (0, exports.configPath)(globalDir);
|
|
413
|
+
let text = '';
|
|
414
|
+
try {
|
|
415
|
+
text = fs_1.default.readFileSync(cfg, 'utf8');
|
|
416
|
+
}
|
|
417
|
+
catch {
|
|
418
|
+
try {
|
|
419
|
+
text = fs_1.default.readFileSync(path_1.default.join(legacy_1.repo, 'profile', 'cohorte.config.template.yaml'), 'utf8');
|
|
420
|
+
}
|
|
421
|
+
catch {
|
|
422
|
+
text = 'enabled: true\n';
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
text = withBoard(withVault(text, vault), name, rel);
|
|
426
|
+
fs_1.default.mkdirSync(path_1.default.dirname(cfg), { recursive: true });
|
|
427
|
+
fs_1.default.writeFileSync(`${cfg}.tmp`, text);
|
|
428
|
+
fs_1.default.renameSync(`${cfg}.tmp`, cfg);
|
|
429
|
+
const board = path_1.default.join(vault, rel);
|
|
430
|
+
let created = false;
|
|
431
|
+
if (!fs_1.default.existsSync(board)) {
|
|
432
|
+
fs_1.default.mkdirSync(path_1.default.dirname(board), { recursive: true });
|
|
433
|
+
fs_1.default.writeFileSync(board, companyBoard());
|
|
434
|
+
created = true;
|
|
435
|
+
}
|
|
436
|
+
fs_1.default.mkdirSync(path_1.default.join(path_1.default.dirname(board), 'Tickets'), { recursive: true });
|
|
437
|
+
return { created, board };
|
|
438
|
+
}
|