@skillre/dsh-plugin-work-dashboard 0.0.0-stage → 0.9.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/LICENSE +21 -0
- package/README.en.md +259 -0
- package/README.md +371 -2
- package/UNINSTALL.md +7 -0
- package/compatibility.json +195 -0
- package/cordis.patch.yml +24 -0
- package/docs/DESIGN-0.3.md +122 -0
- package/docs/DETAIL.md +1 -0
- package/docs/DETAIL.zh.md +1 -0
- package/docs/PLAN-0.7-0.9.md +230 -0
- package/docs/preview.svg +254 -0
- package/docs/preview.zh.svg +254 -0
- package/icon.svg +17 -0
- package/lib/blockers.d.ts +45 -0
- package/lib/blockers.js +160 -0
- package/lib/client/api.d.ts +42 -0
- package/lib/client/api.js +45 -0
- package/lib/client/contracts.d.ts +94 -0
- package/lib/client/contracts.js +21 -0
- package/lib/client/css/base.d.ts +31 -0
- package/lib/client/css/base.js +461 -0
- package/lib/client/css/blockers.d.ts +18 -0
- package/lib/client/css/blockers.js +196 -0
- package/lib/client/css/charts.d.ts +14 -0
- package/lib/client/css/charts.js +191 -0
- package/lib/client/css/detail.d.ts +21 -0
- package/lib/client/css/detail.js +423 -0
- package/lib/client/css/insights.d.ts +27 -0
- package/lib/client/css/insights.js +660 -0
- package/lib/client/css/overview.d.ts +23 -0
- package/lib/client/css/overview.js +327 -0
- package/lib/client/css/summary.d.ts +13 -0
- package/lib/client/css/summary.js +187 -0
- package/lib/client/format.d.ts +57 -0
- package/lib/client/format.js +96 -0
- package/lib/client/preferences.d.ts +56 -0
- package/lib/client/preferences.js +118 -0
- package/lib/client/styles.d.ts +17 -0
- package/lib/client/styles.js +24 -0
- package/lib/client/text.d.ts +32 -0
- package/lib/client/text.js +1112 -0
- package/lib/client/view-contract.d.ts +118 -0
- package/lib/client/view-contract.js +28 -0
- package/lib/client.js +6599 -0
- package/lib/config.d.ts +61 -0
- package/lib/config.js +67 -0
- package/lib/form.d.ts +218 -0
- package/lib/form.js +1075 -0
- package/lib/gap.d.ts +60 -0
- package/lib/gap.js +227 -0
- package/lib/index.d.ts +40 -0
- package/lib/index.js +159 -0
- package/lib/repo.d.ts +124 -0
- package/lib/repo.js +407 -0
- package/lib/risks.d.ts +24 -0
- package/lib/risks.js +85 -0
- package/lib/skill.d.ts +94 -0
- package/lib/skill.js +220 -0
- package/lib/store.d.ts +63 -0
- package/lib/store.js +505 -0
- package/lib/timeline.d.ts +23 -0
- package/lib/timeline.js +93 -0
- package/lib/transport.d.ts +67 -0
- package/lib/transport.js +131 -0
- package/lib/types.d.ts +701 -0
- package/lib/types.js +78 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +117 -4
- package/skills/poc-export/SKILL.md +81 -0
- package/skills/poc-export/scripts/export-form.mjs +654 -0
- package/skills/poc-ledger/SKILL.md +171 -0
- package/skills/poc-submit/SKILL.md +186 -0
package/lib/repo.js
ADDED
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local git cache of the POC ledger repository.
|
|
3
|
+
*
|
|
4
|
+
* Three invariants drive this module:
|
|
5
|
+
*
|
|
6
|
+
* 1. **The cache is disposable.** It is wiped at mount and rebuilt on demand,
|
|
7
|
+
* so the plugin can never corrupt the real data source: the repository on
|
|
8
|
+
* GitHub stays the only truth.
|
|
9
|
+
* 2. **The cache is only ever a fast-forward copy.** A refresh is
|
|
10
|
+
* `clone` (first time) or `fetch --depth 1` + `reset --hard origin/<branch>`.
|
|
11
|
+
* Never `pull`: a merge could block on a conflict in a directory nobody is
|
|
12
|
+
* meant to edit.
|
|
13
|
+
* 3. **A refresh is exclusive.** One lock file keeps two console instances in
|
|
14
|
+
* the same DSH home from cloning into the same directory at once.
|
|
15
|
+
*
|
|
16
|
+
* Authentication is deliberately never stored: the token is read from the
|
|
17
|
+
* already-authenticated `gh` CLI at call time and passed to git through an
|
|
18
|
+
* environment-scoped `http.extraheader`, so it never lands in `.git/config`,
|
|
19
|
+
* never appears in a process argument list, and never reaches the Client.
|
|
20
|
+
*/
|
|
21
|
+
import { spawn } from 'node:child_process';
|
|
22
|
+
import { access, mkdir, readdir, readFile, rm, stat, writeFile } from 'node:fs/promises';
|
|
23
|
+
import { join } from 'node:path';
|
|
24
|
+
/** Failure carrying a stable code the transport maps onto the RPC envelope. */
|
|
25
|
+
export class RepoError extends Error {
|
|
26
|
+
code;
|
|
27
|
+
details;
|
|
28
|
+
constructor(code, message, details = {}) {
|
|
29
|
+
super(message);
|
|
30
|
+
this.code = code;
|
|
31
|
+
this.details = details;
|
|
32
|
+
this.name = 'RepoError';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** Ownership marker: the plugin only wipes a cache directory it created. */
|
|
36
|
+
const MARKER = '.work-dashboard-cache';
|
|
37
|
+
/** Lock file name inside the cache root. */
|
|
38
|
+
const LOCK = '.lock';
|
|
39
|
+
/** A lock older than this is treated as a crashed refresh and reclaimed. */
|
|
40
|
+
const LOCK_STALE_MS = 120_000;
|
|
41
|
+
/** Longest a lock wait will block before reporting a concurrent refresh. */
|
|
42
|
+
const LOCK_WAIT_MS = 15_000;
|
|
43
|
+
/** Largest single YAML file the store will read, in bytes. */
|
|
44
|
+
export const MAX_YAML_BYTES = 512 * 1024;
|
|
45
|
+
/**
|
|
46
|
+
* Reject a cache root that is obviously not a disposable directory.
|
|
47
|
+
*
|
|
48
|
+
* The mount wipes this path, so a mistaken value (home, `/`, a parent of the
|
|
49
|
+
* DSH home) must fail at mount rather than delete real user data.
|
|
50
|
+
*/
|
|
51
|
+
export function assertSafeCacheRoot(cacheRoot, home) {
|
|
52
|
+
const path = cacheRoot.trim();
|
|
53
|
+
if (path === '')
|
|
54
|
+
throw new RepoError('bad-cache-root', 'The POC console cache root is empty.');
|
|
55
|
+
if (path === home)
|
|
56
|
+
throw new RepoError('bad-cache-root', 'The POC console cache root must not be the home directory.');
|
|
57
|
+
if (path.split('/').filter((part) => part !== '').length < 3) {
|
|
58
|
+
throw new RepoError('bad-cache-root', `The POC console cache root is too shallow to be a cache: ${path}`);
|
|
59
|
+
}
|
|
60
|
+
return path;
|
|
61
|
+
}
|
|
62
|
+
/** Environment for one git invocation: no prompts, and optional auth header. */
|
|
63
|
+
function gitEnv(token) {
|
|
64
|
+
const env = {
|
|
65
|
+
...process.env,
|
|
66
|
+
// A missing credential must fail, never wait on a terminal prompt.
|
|
67
|
+
GIT_TERMINAL_PROMPT: '0',
|
|
68
|
+
GIT_ASKPASS: 'true',
|
|
69
|
+
// No interactive pager and no locale-dependent output parsing.
|
|
70
|
+
GIT_PAGER: 'cat',
|
|
71
|
+
LC_ALL: 'C',
|
|
72
|
+
};
|
|
73
|
+
if (token !== null) {
|
|
74
|
+
// Passed through the environment so the token is not visible in `ps`.
|
|
75
|
+
// `x-access-token` is the GitHub App-compatible basic-auth user for a PAT.
|
|
76
|
+
const basic = Buffer.from(`x-access-token:${token}`, 'utf8').toString('base64');
|
|
77
|
+
env.GIT_CONFIG_COUNT = '1';
|
|
78
|
+
env.GIT_CONFIG_KEY_0 = 'http.https://github.com/.extraheader';
|
|
79
|
+
env.GIT_CONFIG_VALUE_0 = `Authorization: Basic ${basic}`;
|
|
80
|
+
}
|
|
81
|
+
return env;
|
|
82
|
+
}
|
|
83
|
+
/** Run one command with a hard timeout, killing its process group on expiry. */
|
|
84
|
+
function run(command, args, options) {
|
|
85
|
+
return new Promise((resolve, reject) => {
|
|
86
|
+
const child = spawn(command, args, {
|
|
87
|
+
...(options.cwd === undefined ? {} : { cwd: options.cwd }),
|
|
88
|
+
env: options.env,
|
|
89
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
90
|
+
// Own process group so a timeout can kill git and any transport child.
|
|
91
|
+
detached: process.platform !== 'win32',
|
|
92
|
+
});
|
|
93
|
+
let stdout = '';
|
|
94
|
+
let stderr = '';
|
|
95
|
+
let timedOut = false;
|
|
96
|
+
const append = (current, chunk) => (current + chunk.toString('utf8')).slice(-8_000);
|
|
97
|
+
child.stdout.on('data', (chunk) => { stdout = append(stdout, chunk); });
|
|
98
|
+
child.stderr.on('data', (chunk) => { stderr = append(stderr, chunk); });
|
|
99
|
+
const timer = setTimeout(() => {
|
|
100
|
+
timedOut = true;
|
|
101
|
+
killTree(child.pid);
|
|
102
|
+
}, options.timeoutMs);
|
|
103
|
+
child.once('error', (error) => {
|
|
104
|
+
clearTimeout(timer);
|
|
105
|
+
reject(new RepoError('git-missing', `Cannot run ${command}: ${error.message}`, { command }));
|
|
106
|
+
});
|
|
107
|
+
child.once('close', (code, signal) => {
|
|
108
|
+
clearTimeout(timer);
|
|
109
|
+
resolve({ code, signal, stdout, stderr, timedOut });
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/** Kill a detached child's whole process group, falling back to the child. */
|
|
114
|
+
function killTree(pid) {
|
|
115
|
+
if (pid === undefined)
|
|
116
|
+
return;
|
|
117
|
+
try {
|
|
118
|
+
if (process.platform === 'win32')
|
|
119
|
+
process.kill(pid, 'SIGKILL');
|
|
120
|
+
else
|
|
121
|
+
process.kill(-pid, 'SIGKILL');
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
// The group may already be gone; a later SIGTERM would be a no-op anyway.
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/** Map a failed git invocation onto a user-actionable message. */
|
|
128
|
+
function classify(result, action, repository) {
|
|
129
|
+
const text = `${result.stderr}\n${result.stdout}`.toLowerCase();
|
|
130
|
+
if (result.timedOut) {
|
|
131
|
+
return new RepoError('timeout', `git ${action} for ${repository} did not finish within the configured timeout. On a slow network, raise cloneTimeoutMs / fetchTimeoutMs in the plugin configuration.`, { action, repository });
|
|
132
|
+
}
|
|
133
|
+
if (text.includes('authentication failed') ||
|
|
134
|
+
text.includes('could not read username') ||
|
|
135
|
+
text.includes('permission denied') ||
|
|
136
|
+
text.includes('repository not found') ||
|
|
137
|
+
text.includes('invalid username or password') ||
|
|
138
|
+
text.includes('terminal prompts disabled')) {
|
|
139
|
+
return new RepoError('auth', `Cannot read ${repository}: the GitHub credential was rejected. Run "gh auth login" for the account that can read this private repository.`, { action, repository });
|
|
140
|
+
}
|
|
141
|
+
if (text.includes('could not resolve host') ||
|
|
142
|
+
text.includes('connection timed out') ||
|
|
143
|
+
text.includes('failed to connect') ||
|
|
144
|
+
text.includes('network is unreachable') ||
|
|
145
|
+
text.includes('connection reset')) {
|
|
146
|
+
return new RepoError('network', `Cannot reach github.com while running git ${action}.`, { action, repository });
|
|
147
|
+
}
|
|
148
|
+
if (text.includes('not found') || text.includes('does not exist')) {
|
|
149
|
+
return new RepoError('not-found', `The repository ${repository} does not exist, or this account cannot see it.`, { action, repository });
|
|
150
|
+
}
|
|
151
|
+
const detail = `${result.stderr}`.trim().split('\n').slice(-3).join(' ').slice(0, 500);
|
|
152
|
+
return new RepoError('git-failed', `git ${action} failed${detail === '' ? '' : `: ${detail}`}`, { action, repository, exitCode: result.code });
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* The disposable git cache.
|
|
156
|
+
*
|
|
157
|
+
* Lifecycle: `prepare()` at mount wipes and recreates the cache root; the first
|
|
158
|
+
* `refresh()` clones, later ones fast-forward. Every method is safe to call
|
|
159
|
+
* concurrently except that refreshes serialize on a lock.
|
|
160
|
+
*/
|
|
161
|
+
export class RepoCache {
|
|
162
|
+
options;
|
|
163
|
+
/** Directory the ledger is read from once a clone exists. */
|
|
164
|
+
repoPath;
|
|
165
|
+
fetchedAt = null;
|
|
166
|
+
head = null;
|
|
167
|
+
constructor(options) {
|
|
168
|
+
this.options = options;
|
|
169
|
+
this.repoPath = join(options.cacheRoot, 'repo');
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Wipe the cache and recreate it, so every DSH start begins from "no data".
|
|
173
|
+
*
|
|
174
|
+
* Only a directory this plugin created is ever removed: a pre-existing
|
|
175
|
+
* directory without the ownership marker fails loudly instead of being
|
|
176
|
+
* deleted, because a mistaken `cacheRoot` must not destroy user files.
|
|
177
|
+
*/
|
|
178
|
+
async prepare() {
|
|
179
|
+
const root = this.options.cacheRoot;
|
|
180
|
+
let exists = false;
|
|
181
|
+
try {
|
|
182
|
+
exists = (await stat(root)).isDirectory();
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
// A permission denial is not "absent": report it instead of pretending
|
|
186
|
+
// the cache is cold, then failing later with an opaque mkdir error.
|
|
187
|
+
if (error.code !== 'ENOENT')
|
|
188
|
+
throw this.fsFailure(error, root);
|
|
189
|
+
exists = false;
|
|
190
|
+
}
|
|
191
|
+
if (exists) {
|
|
192
|
+
const owned = (await this.hasMarker(root)) || (await this.isEmptyDirectory(root));
|
|
193
|
+
if (!owned) {
|
|
194
|
+
throw new RepoError('cache-not-owned', `The cache root ${root} already exists but was not created by the POC console; refusing to clear it. Remove it manually or point cacheRoot at a fresh directory.`, { cacheRoot: root });
|
|
195
|
+
}
|
|
196
|
+
await rm(root, { recursive: true, force: true });
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
await mkdir(root, { recursive: true });
|
|
200
|
+
await writeFile(join(root, MARKER), 'This directory is a disposable POC console cache.\n', 'utf8');
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
throw this.fsFailure(error, root);
|
|
204
|
+
}
|
|
205
|
+
this.fetchedAt = null;
|
|
206
|
+
this.head = null;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Map a filesystem failure onto an authored, user-actionable code.
|
|
210
|
+
*
|
|
211
|
+
* The cache lives under `$DSH_HOME/cache`, which the Host process normally
|
|
212
|
+
* owns; a sandboxed or read-only deployment can deny it. Without this mapping
|
|
213
|
+
* the first request would surface as an opaque "internal error".
|
|
214
|
+
*/
|
|
215
|
+
fsFailure(error, path) {
|
|
216
|
+
const code = error.code ?? '';
|
|
217
|
+
if (code === 'EPERM' || code === 'EACCES' || code === 'EROFS') {
|
|
218
|
+
return new RepoError('cache-unwritable', `Cannot write the POC console cache at ${path}: the Host process has no permission. Point cacheRoot at a writable directory in the plugin configuration.`, { path, filesystemCode: code });
|
|
219
|
+
}
|
|
220
|
+
if (code === 'ENOSPC') {
|
|
221
|
+
return new RepoError('cache-full', `Cannot write the POC console cache at ${path}: the disk is full.`, { path });
|
|
222
|
+
}
|
|
223
|
+
return new RepoError('cache-failed', `Cannot prepare the POC console cache at ${path}: ${code || String(error)}.`, { path, filesystemCode: code });
|
|
224
|
+
}
|
|
225
|
+
async hasMarker(root) {
|
|
226
|
+
try {
|
|
227
|
+
const marker = await stat(join(root, MARKER));
|
|
228
|
+
return marker.isFile();
|
|
229
|
+
}
|
|
230
|
+
catch {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* An empty directory is safe to adopt: nothing can be lost by clearing it.
|
|
236
|
+
*
|
|
237
|
+
* This matters on the very first mount, when `mkdir -p` may have been run
|
|
238
|
+
* outside the plugin (a user pre-creating `~/.dsh/cache/work-dashboard`), and on
|
|
239
|
+
* a re-mount after a wipe that left the root empty.
|
|
240
|
+
*/
|
|
241
|
+
async isEmptyDirectory(root) {
|
|
242
|
+
try {
|
|
243
|
+
return (await readdir(root)).length === 0;
|
|
244
|
+
}
|
|
245
|
+
catch {
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
/** Whether a clone exists and its working tree is readable. */
|
|
250
|
+
async isReady() {
|
|
251
|
+
try {
|
|
252
|
+
await access(join(this.repoPath, '.git'));
|
|
253
|
+
await access(join(this.repoPath, 'projects'));
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
catch {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
/** ISO timestamp of the last successful refresh in this process. */
|
|
261
|
+
get lastFetchedAt() {
|
|
262
|
+
return this.fetchedAt;
|
|
263
|
+
}
|
|
264
|
+
/** The configured `owner/name` data source. */
|
|
265
|
+
get repository() {
|
|
266
|
+
return this.options.repository;
|
|
267
|
+
}
|
|
268
|
+
/** The configured branch the cache tracks. */
|
|
269
|
+
get branch() {
|
|
270
|
+
return this.options.branch;
|
|
271
|
+
}
|
|
272
|
+
/** Short HEAD sha after the last successful refresh, if known. */
|
|
273
|
+
get lastHead() {
|
|
274
|
+
return this.head;
|
|
275
|
+
}
|
|
276
|
+
/** Read the `gh` token at call time; absent when `gh` is not authenticated. */
|
|
277
|
+
async ghToken() {
|
|
278
|
+
const result = await run('gh', ['auth', 'token'], {
|
|
279
|
+
env: gitEnv(null),
|
|
280
|
+
timeoutMs: 10_000,
|
|
281
|
+
}).catch(() => null);
|
|
282
|
+
if (result === null || result.code !== 0)
|
|
283
|
+
return null;
|
|
284
|
+
const token = result.stdout.trim();
|
|
285
|
+
return token === '' ? null : token;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Clone or fast-forward the cache.
|
|
289
|
+
*
|
|
290
|
+
* Serialized by a lock file in the cache root: two browser tabs pressing
|
|
291
|
+
* refresh, or two DSH instances sharing a home, must not clone into the same
|
|
292
|
+
* directory concurrently.
|
|
293
|
+
*/
|
|
294
|
+
async refresh() {
|
|
295
|
+
const startedAt = Date.now();
|
|
296
|
+
const release = await this.acquireLock();
|
|
297
|
+
try {
|
|
298
|
+
const token = await this.ghToken();
|
|
299
|
+
if (token === null) {
|
|
300
|
+
throw new RepoError('gh-unauthenticated', 'The gh CLI is not authenticated. Run "gh auth login" for an account that can read the POC ledger repository.', { repository: this.options.repository });
|
|
301
|
+
}
|
|
302
|
+
const remote = this.options.remoteUrl;
|
|
303
|
+
const env = gitEnv(token);
|
|
304
|
+
const ready = await this.isReady();
|
|
305
|
+
const mode = ready ? 'fetch' : 'clone';
|
|
306
|
+
if (!ready) {
|
|
307
|
+
try {
|
|
308
|
+
await rm(this.repoPath, { recursive: true, force: true });
|
|
309
|
+
}
|
|
310
|
+
catch (error) {
|
|
311
|
+
throw this.fsFailure(error, this.repoPath);
|
|
312
|
+
}
|
|
313
|
+
const result = await run('git', ['clone', '--depth', '1', '--single-branch', '--branch', this.options.branch, remote, this.repoPath], { env, timeoutMs: this.options.cloneTimeoutMs });
|
|
314
|
+
if (result.code !== 0)
|
|
315
|
+
throw classify(result, 'clone', this.options.repository);
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
const fetch = await run('git', ['fetch', '--depth', '1', 'origin', this.options.branch], {
|
|
319
|
+
cwd: this.repoPath,
|
|
320
|
+
env,
|
|
321
|
+
timeoutMs: this.options.fetchTimeoutMs,
|
|
322
|
+
});
|
|
323
|
+
if (fetch.code !== 0)
|
|
324
|
+
throw classify(fetch, 'fetch', this.options.repository);
|
|
325
|
+
// The cache is a read-only copy, so align it forcibly instead of merging.
|
|
326
|
+
const reset = await run('git', ['reset', '--hard', `origin/${this.options.branch}`], {
|
|
327
|
+
cwd: this.repoPath,
|
|
328
|
+
env,
|
|
329
|
+
timeoutMs: this.options.fetchTimeoutMs,
|
|
330
|
+
});
|
|
331
|
+
if (reset.code !== 0)
|
|
332
|
+
throw classify(reset, 'fetch', this.options.repository);
|
|
333
|
+
}
|
|
334
|
+
const head = await run('git', ['rev-parse', '--short', 'HEAD'], { cwd: this.repoPath, env, timeoutMs: 10_000 });
|
|
335
|
+
this.head = head.code === 0 ? head.stdout.trim() : null;
|
|
336
|
+
this.fetchedAt = new Date().toISOString();
|
|
337
|
+
return {
|
|
338
|
+
mode,
|
|
339
|
+
durationMs: Date.now() - startedAt,
|
|
340
|
+
finishedAt: this.fetchedAt,
|
|
341
|
+
head: this.head ?? '',
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
finally {
|
|
345
|
+
await release();
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
/** Take the cache lock, waiting briefly and reclaiming a stale one. */
|
|
349
|
+
async acquireLock() {
|
|
350
|
+
const path = join(this.options.cacheRoot, LOCK);
|
|
351
|
+
const deadline = Date.now() + LOCK_WAIT_MS;
|
|
352
|
+
for (;;) {
|
|
353
|
+
try {
|
|
354
|
+
await writeFile(path, `${process.pid} ${Date.now()}\n`, { encoding: 'utf8', flag: 'wx' });
|
|
355
|
+
return async () => {
|
|
356
|
+
await rm(path, { force: true });
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
catch (error) {
|
|
360
|
+
const code = error.code;
|
|
361
|
+
if (code !== 'EEXIST')
|
|
362
|
+
throw this.fsFailure(error, path);
|
|
363
|
+
// Reclaim a lock left behind by a crashed process.
|
|
364
|
+
try {
|
|
365
|
+
const info = await stat(path);
|
|
366
|
+
if (Date.now() - info.mtimeMs > LOCK_STALE_MS) {
|
|
367
|
+
await rm(path, { force: true });
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
catch {
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
if (Date.now() > deadline) {
|
|
375
|
+
throw new RepoError('busy', 'Another POC console refresh is already running; try again in a moment.');
|
|
376
|
+
}
|
|
377
|
+
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
/** Every `projects/*.yaml` file path in the cache, sorted by file name. */
|
|
382
|
+
async projectFiles() {
|
|
383
|
+
const dir = join(this.repoPath, 'projects');
|
|
384
|
+
let names;
|
|
385
|
+
try {
|
|
386
|
+
names = await readdir(dir);
|
|
387
|
+
}
|
|
388
|
+
catch (error) {
|
|
389
|
+
if (error.code === 'ENOENT') {
|
|
390
|
+
throw new RepoError('no-projects', `The repository has no projects/ directory at ${dir}.`, { path: dir });
|
|
391
|
+
}
|
|
392
|
+
throw error;
|
|
393
|
+
}
|
|
394
|
+
return names
|
|
395
|
+
.filter((name) => name.endsWith('.yaml') || name.endsWith('.yml'))
|
|
396
|
+
.sort()
|
|
397
|
+
.map((name) => join(dir, name));
|
|
398
|
+
}
|
|
399
|
+
/** Read one project file, bounded so one huge file cannot stall the console. */
|
|
400
|
+
async readProject(path) {
|
|
401
|
+
const info = await stat(path);
|
|
402
|
+
if (info.size > MAX_YAML_BYTES) {
|
|
403
|
+
throw new RepoError('too-large', `${path} is larger than ${MAX_YAML_BYTES} bytes and was skipped.`, { path, size: info.size });
|
|
404
|
+
}
|
|
405
|
+
return readFile(path, 'utf8');
|
|
406
|
+
}
|
|
407
|
+
}
|
package/lib/risks.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The risk board: every project's risks, sorted by severity.
|
|
3
|
+
*
|
|
4
|
+
* The board answers a different question from the project table. The table says
|
|
5
|
+
* "which project needs attention"; the board says "what could go wrong, and
|
|
6
|
+
* where". It is built from the same records, so the two can never disagree.
|
|
7
|
+
*
|
|
8
|
+
* Severity ordering is deliberate: a `high` risk sorts above every `medium`,
|
|
9
|
+
* and a blank level sorts LAST rather than first. An unset level is not a
|
|
10
|
+
* statement that the risk is mild — it is a missing judgement, and putting it
|
|
11
|
+
* at the top would bury the risks someone actually assessed as serious.
|
|
12
|
+
*/
|
|
13
|
+
import type { ScanOptions } from './gap.js';
|
|
14
|
+
import type { PocRecord, RiskBoard } from './types.js';
|
|
15
|
+
/** Severity rank: higher sorts first. A blank level ranks below `low`. */
|
|
16
|
+
export declare function riskRank(level: string): number;
|
|
17
|
+
/**
|
|
18
|
+
* Build the board from the loaded records.
|
|
19
|
+
*
|
|
20
|
+
* Rows are ordered by severity, then by project id, then by the risk's own
|
|
21
|
+
* order inside the record — a stable order that does not reshuffle between
|
|
22
|
+
* refreshes.
|
|
23
|
+
*/
|
|
24
|
+
export declare function buildRiskBoard(records: readonly PocRecord[], options: ScanOptions): RiskBoard;
|
package/lib/risks.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The risk board: every project's risks, sorted by severity.
|
|
3
|
+
*
|
|
4
|
+
* The board answers a different question from the project table. The table says
|
|
5
|
+
* "which project needs attention"; the board says "what could go wrong, and
|
|
6
|
+
* where". It is built from the same records, so the two can never disagree.
|
|
7
|
+
*
|
|
8
|
+
* Severity ordering is deliberate: a `high` risk sorts above every `medium`,
|
|
9
|
+
* and a blank level sorts LAST rather than first. An unset level is not a
|
|
10
|
+
* statement that the risk is mild — it is a missing judgement, and putting it
|
|
11
|
+
* at the top would bury the risks someone actually assessed as serious.
|
|
12
|
+
*/
|
|
13
|
+
import { normalizeStage, scanGaps, text } from './gap.js';
|
|
14
|
+
/** Severity rank: higher sorts first. A blank level ranks below `low`. */
|
|
15
|
+
export function riskRank(level) {
|
|
16
|
+
switch (level.toLowerCase()) {
|
|
17
|
+
case 'high':
|
|
18
|
+
return 3;
|
|
19
|
+
case 'medium':
|
|
20
|
+
return 2;
|
|
21
|
+
case 'low':
|
|
22
|
+
return 1;
|
|
23
|
+
default:
|
|
24
|
+
return 0;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Count the gaps a project carries, for board context.
|
|
29
|
+
*
|
|
30
|
+
* Delegates to the shared scanner so the board and the pending list can never
|
|
31
|
+
* disagree about a project's gaps.
|
|
32
|
+
*/
|
|
33
|
+
function gapCounts(record, options) {
|
|
34
|
+
const gaps = scanGaps(record, options);
|
|
35
|
+
return { total: gaps.length, high: gaps.filter((item) => item.level === 'high').length };
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Build the board from the loaded records.
|
|
39
|
+
*
|
|
40
|
+
* Rows are ordered by severity, then by project id, then by the risk's own
|
|
41
|
+
* order inside the record — a stable order that does not reshuffle between
|
|
42
|
+
* refreshes.
|
|
43
|
+
*/
|
|
44
|
+
export function buildRiskBoard(records, options) {
|
|
45
|
+
const rows = [];
|
|
46
|
+
let projectsWithRisks = 0;
|
|
47
|
+
for (const record of records) {
|
|
48
|
+
const pocId = text(record.poc_id);
|
|
49
|
+
const pocName = text(record.name) === '' ? pocId : text(record.name);
|
|
50
|
+
const { stage } = normalizeStage(record.stage);
|
|
51
|
+
const risks = Array.isArray(record.plan?.risks) ? record.plan.risks : [];
|
|
52
|
+
if (risks.length === 0)
|
|
53
|
+
continue;
|
|
54
|
+
projectsWithRisks += 1;
|
|
55
|
+
const counts = gapCounts(record, options);
|
|
56
|
+
for (const raw of risks) {
|
|
57
|
+
const value = (raw ?? {});
|
|
58
|
+
const level = text(value.level).toLowerCase();
|
|
59
|
+
rows.push({
|
|
60
|
+
pocId,
|
|
61
|
+
pocName,
|
|
62
|
+
stage,
|
|
63
|
+
level,
|
|
64
|
+
rank: riskRank(level),
|
|
65
|
+
name: text(value.name),
|
|
66
|
+
mitigation: text(value.mitigation),
|
|
67
|
+
gapCount: counts.total,
|
|
68
|
+
highGapCount: counts.high,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
rows.sort((left, right) => right.rank - left.rank || left.pocId.localeCompare(right.pocId) || left.name.localeCompare(right.name));
|
|
73
|
+
const counts = { high: 0, medium: 0, low: 0, unset: 0, total: rows.length };
|
|
74
|
+
for (const row of rows) {
|
|
75
|
+
if (row.level === 'high')
|
|
76
|
+
counts.high += 1;
|
|
77
|
+
else if (row.level === 'medium')
|
|
78
|
+
counts.medium += 1;
|
|
79
|
+
else if (row.level === 'low')
|
|
80
|
+
counts.low += 1;
|
|
81
|
+
else
|
|
82
|
+
counts.unset += 1;
|
|
83
|
+
}
|
|
84
|
+
return { rows, counts, projectsWithRisks, projectsTotal: records.length };
|
|
85
|
+
}
|
package/lib/skill.d.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registration of the three skills that ship inside this package.
|
|
3
|
+
*
|
|
4
|
+
* The skills live in `skills/<name>/` rather than in the user's profile, so
|
|
5
|
+
* installing the plugin is what publishes them, and uninstalling removes them.
|
|
6
|
+
* That is the point of bundling them: a colleague who installs the dashboard
|
|
7
|
+
* gets the ledger-reading, form-exporting and PR-submitting skills in the same
|
|
8
|
+
* action, on the same version, with no separate install step that can drift.
|
|
9
|
+
*
|
|
10
|
+
* Every step is best-effort by design: `skills` is an optional service, and a
|
|
11
|
+
* profile without it — or a package whose skill file went missing — must still
|
|
12
|
+
* get the dashboard. Missing service, missing file and unusable frontmatter
|
|
13
|
+
* therefore warn and return; nothing throws out of `apply`.
|
|
14
|
+
*
|
|
15
|
+
* The skills are read from disk at registration time rather than inlined into
|
|
16
|
+
* the bundle, so the `scripts/` beside them ship as real files the model can
|
|
17
|
+
* run, and so an operator can read exactly what was published.
|
|
18
|
+
*/
|
|
19
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
20
|
+
/** Names of the bundled skills, in the order they are registered. */
|
|
21
|
+
export declare const BUNDLED_SKILL_NAMES: readonly ["poc-ledger", "poc-export", "poc-submit"];
|
|
22
|
+
/**
|
|
23
|
+
* Structural slice of the `skills` service this module depends on.
|
|
24
|
+
*
|
|
25
|
+
* Declared locally instead of importing `@deepseek-ai/dsh-skill`: handing the
|
|
26
|
+
* registry one object literal is not worth a runtime dependency, and only a
|
|
27
|
+
* profile that actually provides the service ever resolves this shape.
|
|
28
|
+
*/
|
|
29
|
+
export interface SkillRegistryLike {
|
|
30
|
+
/** Publish one readonly runtime skill into the calling context's layer. */
|
|
31
|
+
register(skill: SkillRegistrationLike): () => void;
|
|
32
|
+
}
|
|
33
|
+
/** Payload accepted by {@link SkillRegistryLike.register}. */
|
|
34
|
+
export interface SkillRegistrationLike {
|
|
35
|
+
readonly name: string;
|
|
36
|
+
readonly description: string;
|
|
37
|
+
readonly content: string;
|
|
38
|
+
readonly source: string;
|
|
39
|
+
readonly whenToUse?: string;
|
|
40
|
+
readonly path?: string;
|
|
41
|
+
readonly resourceBase?: SkillResourceBaseLike;
|
|
42
|
+
}
|
|
43
|
+
/** Where a skill's relative resources live; only the directory variant is used. */
|
|
44
|
+
export interface SkillResourceBaseLike {
|
|
45
|
+
readonly kind: 'directory';
|
|
46
|
+
readonly path: string;
|
|
47
|
+
}
|
|
48
|
+
/** Fields extracted from a bundled `SKILL.md`. */
|
|
49
|
+
export interface ParsedSkill {
|
|
50
|
+
readonly name: string;
|
|
51
|
+
readonly description: string;
|
|
52
|
+
readonly whenToUse?: string;
|
|
53
|
+
readonly content: string;
|
|
54
|
+
}
|
|
55
|
+
/** Outcome of parsing a bundled `SKILL.md`; a failure carries the reason. */
|
|
56
|
+
export type SkillParseResult = {
|
|
57
|
+
readonly ok: true;
|
|
58
|
+
readonly skill: ParsedSkill;
|
|
59
|
+
} | {
|
|
60
|
+
readonly ok: false;
|
|
61
|
+
readonly reason: string;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Absolute path of the directory holding the bundled skills.
|
|
65
|
+
*
|
|
66
|
+
* `src/` and `lib/` both sit directly under the package root, so the same
|
|
67
|
+
* relative URL resolves whether the plugin runs from source (tests) or from the
|
|
68
|
+
* built package (an installed profile).
|
|
69
|
+
*/
|
|
70
|
+
export declare function bundledSkillsDirectory(): string;
|
|
71
|
+
/**
|
|
72
|
+
* Parse the single-line `key: value` frontmatter of a bundled `SKILL.md`.
|
|
73
|
+
*
|
|
74
|
+
* Deliberately not a YAML parser: these files only carry string scalars we
|
|
75
|
+
* control, and a plugin should not pull a YAML dependency to read its own
|
|
76
|
+
* resources. A value may be wrapped in one matching pair of quotes, which are
|
|
77
|
+
* stripped; escape sequences are left exactly as written.
|
|
78
|
+
*/
|
|
79
|
+
export declare function parseSkillMarkdown(source: string): SkillParseResult;
|
|
80
|
+
/**
|
|
81
|
+
* Register the bundled skills into the running profile's skill catalog.
|
|
82
|
+
*
|
|
83
|
+
* Called from `apply`, and returns immediately: the actual registration happens
|
|
84
|
+
* on the injected child fiber, whenever the `skills` service exists. Nothing
|
|
85
|
+
* here is order-sensitive, and nothing here can fail a mount — a profile that
|
|
86
|
+
* never provides a skill registry simply never runs the callback.
|
|
87
|
+
*
|
|
88
|
+
* `skills` is deliberately **not** in the plugin's static `inject`: that would
|
|
89
|
+
* hold the whole plugin in PENDING until the registry appears, and a profile
|
|
90
|
+
* without one would never mount the dashboard at all.
|
|
91
|
+
*/
|
|
92
|
+
export declare function registerBundledSkills(ctx: Context, options?: {
|
|
93
|
+
readonly dir?: string;
|
|
94
|
+
}): void;
|