@sabaiway/agent-workflow-kit 23.10.0 → 23.12.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.
@@ -54,6 +54,7 @@ import { isDirectRun } from './direct-run.mjs';
54
54
  import { ACTIVITIES, resolveActivityRecipe, composeReadiness, safeLine } from './recipes.mjs';
55
55
  import { surveyFamily, surveyGateHook } from './family-registry.mjs';
56
56
  import { probeSandboxMasks, needsMasksApply, patternToRel } from './sandbox-masks.mjs';
57
+ import { SKIP_REASON_CAP, composeSkip, renderSkip } from './advisor-skip/index.mjs';
57
58
  import { shellQuoteArg } from './review-state.mjs';
58
59
  import { isFinalCapableDeclaration } from './run-gates.mjs';
59
60
  import { loadDeclaration, canonicalCheckerGates, coverageProducerPrecedes, isKitOwnedCheckerGate, movableEarlierForm } from './gates-declaration.mjs';
@@ -323,7 +324,7 @@ export const WHATS = Object.freeze({
323
324
 
324
325
  // ── the shape contract (D2): registry strings AND composed items stay one line under the cap ────
325
326
  export const ITEM_LINE_CAP = 140;
326
- export const SKIP_REASON_CAP = 200;
327
+ export { SKIP_REASON_CAP };
327
328
 
328
329
  const oneLineOf = (text) => String(text).replace(/\s*[\r\n]+\s*/g, ' ').trim();
329
330
  // Scalar truncation-with-count — a capped value states what it dropped, never a silent cut.
@@ -1628,9 +1629,7 @@ export const buildRecommendations = ({ cwd, deps = {} } = {}) => {
1628
1629
  const root = resolve(cwd);
1629
1630
  const items = [];
1630
1631
  const skips = [];
1631
- // Skip reasons ride arbitrary Error.messages — normalized to ONE line and length-capped so a
1632
- // multiline or oversized message can never rebuild a prose wall (D2).
1633
- const skip = (key, err) => skips.push({ key, reason: truncatedTo(oneLineOf(err?.message ?? String(err)), SKIP_REASON_CAP) });
1632
+ const skip = (key, err) => skips.push(composeSkip(key, err)); // docs/ai/specs/kit/advisor-skip.md
1634
1633
  // The runtime shape backstop (D2): every COMPOSED item is validated at construction — a
1635
1634
  // violation surfaces through the stated-skip lane, never a crash, never a rendered violation.
1636
1635
  // `variant` defaults to the item key; a per-site arm passes its `<key>.<variant>` entry. It is
@@ -1723,7 +1722,7 @@ export const formatRecommendations = ({ items, skips }) => {
1723
1722
  });
1724
1723
  }
1725
1724
  for (const s of skips) {
1726
- lines.push(` ⚠ skipped item ${s.key} — probe failed: ${s.reason}`);
1725
+ for (const line of renderSkip(s)) lines.push(line);
1727
1726
  }
1728
1727
  return lines.join('\n');
1729
1728
  };
@@ -1740,7 +1739,8 @@ facts or its alternative, such as the bridge-tier missing-entries line or
1740
1739
  the worktrees-dir ack fallback) · the harness or kit check line · the exact consent-gated apply one-liner}. --cwd is
1741
1740
  REQUIRED (the target project is explicit, never inferred from the shell's current directory). The
1742
1741
  section renders present-even-when-empty ("${RECOMMENDATIONS_EMPTY_LINE}"); a probe failure is a
1743
- stated skipped-item line. Apply lines are cwd-independent (absolute tool paths, a pinned --cwd;
1742
+ stated skipped-item line, its whole reason below it whenever that line lost anything.
1743
+ Apply lines are cwd-independent (absolute tool paths, a pinned --cwd;
1744
1744
  the doctor item pins via a cd prefix; the ONE exception is the set-autonomy item — a
1745
1745
  conversational skill invocation labeled "run IN the target project") and preserve each writer's
1746
1746
  own consent semantics. The consented velocity-profile --bridge-tier seeds used bridges' code-mode
@@ -0,0 +1,30 @@
1
+ import { composeCheckerBlock } from '../checker-block/index.mjs';
2
+
3
+ export const CHECKER_NAME = 'release-scan';
4
+ export const UNEXPECTED_REMEDY = 'fix the cause the stack below names, then re-run';
5
+ const TARGET_REMEDY = 'fix or drop each mis-aimed target above as its finding says, then re-run';
6
+ const SCAN_REMEDY = 'remove each attribution, reviewer identity, and hardcoded version claim above, then re-run';
7
+
8
+ export const composeScanBlock = ({ cwd, misaimed, findings, after }) => {
9
+ const classes = [];
10
+ const remedies = [];
11
+ if (misaimed.length) {
12
+ classes.push(`${misaimed.length} mis-aimed target(s)`);
13
+ remedies.push(TARGET_REMEDY);
14
+ }
15
+ if (findings.length) {
16
+ classes.push(`${findings.length} finding(s)`);
17
+ remedies.push(SCAN_REMEDY);
18
+ }
19
+ return composeCheckerBlock({
20
+ name: CHECKER_NAME,
21
+ root: cwd,
22
+ failed: classes.join('; '),
23
+ findings: [
24
+ ...misaimed.map(({ path, status, remedy }) => ({ path, text: `${status} — ${remedy}` })),
25
+ ...findings.map(({ file, line, kind, detail }) => ({ path: file, line, text: `${kind} — ${detail}` })),
26
+ ],
27
+ remedies,
28
+ after,
29
+ });
30
+ };
@@ -10,9 +10,12 @@
10
10
  //
11
11
  // Pure `scanText` for unit fixtures; `scanPaths`/CLI for the release tree. Dependency-free, Node >= 22.
12
12
 
13
- import { readFileSync, existsSync, readdirSync, statSync } from 'node:fs';
13
+ import { readFileSync, readdirSync, statSync } from 'node:fs';
14
14
  import { join, extname, basename, resolve } from 'node:path';
15
+ import { composeUsageRefusal } from '../references/scripts/shared/index.mjs';
16
+ import { runCheckerTail } from './checker-block/index.mjs';
15
17
  import { isDirectRun } from './direct-run.mjs';
18
+ import { CHECKER_NAME, UNEXPECTED_REMEDY, composeScanBlock } from './release-scan/index.mjs';
16
19
 
17
20
  export const ALLOWLIST = [
18
21
  'codex-cli-bridge',
@@ -204,16 +207,25 @@ export const TARGET = Object.freeze({
204
207
 
205
208
  const GLOB_META_RE = /[*?[\]]/;
206
209
 
210
+ const statTarget = (path) => {
211
+ try {
212
+ return statSync(path);
213
+ } catch (error) {
214
+ if (error?.code !== 'ENOENT') throw error;
215
+ return null;
216
+ }
217
+ };
218
+
207
219
  // PURE-ish (one fs read): classify ONE caller-named target and collect the files it contributes.
208
220
  // Every zero-contribution status names its own cause, so the refusal can state the remedy rather
209
221
  // than a bare count (a count without a location is the defect class this family bans).
210
222
  export const classifyTarget = (path) => {
211
- if (!existsSync(path)) {
223
+ const st = statTarget(path);
224
+ if (st === null) {
212
225
  return GLOB_META_RE.test(path)
213
226
  ? { path, status: TARGET.unmatchedGlob, files: [] }
214
227
  : { path, status: TARGET.missing, files: [] };
215
228
  }
216
- const st = statSync(path);
217
229
  const name = basename(path);
218
230
  if (st.isDirectory() && EXCLUDE_DIR_NAMES.has(name)) return { path, status: TARGET.excluded, files: [] };
219
231
  if (st.isFile() && (EXCLUDE_FILE_NAMES.has(name) || !TEXT_EXT.has(extname(path)) || path.endsWith('.tgz'))) {
@@ -244,34 +256,43 @@ const findingsIn = (targets, opts) => {
244
256
 
245
257
  export const scanPaths = (paths, opts = {}) => findingsIn(paths.map((p) => classifyTarget(resolve(p))), opts);
246
258
 
247
- export const main = (argv) => {
259
+ const USAGE = 'usage: release-scan.mjs [--report] <path>...';
260
+
261
+ export const runScan = (argv, cwd = process.cwd()) => {
248
262
  const reportOnly = argv.includes('--report');
249
263
  const paths = argv.filter((a) => a !== '--report');
250
264
  if (paths.length === 0) {
251
- console.error('usage: release-scan.mjs [--report] <path>...');
252
- return 2;
265
+ return { code: 2, lines: composeUsageRefusal({ name: CHECKER_NAME, failed: 'no path was given to scan', usage: USAGE }) };
253
266
  }
254
- const targets = paths.map((p) => classifyTarget(resolve(p)));
255
- for (const target of targets) {
256
- if (target.status === TARGET.unmatchedGlob) {
257
- console.log(`[release-scan] skipped ${target.path} — no file matched this glob (an optional target, stated not silent).`);
258
- }
259
- }
260
- const misaimed = targets.filter((target) => TARGET_REMEDY[target.status] !== undefined);
261
- for (const target of misaimed) {
262
- console.log(`[release-scan] target ${target.path} contributed NO file (${target.status}) — ${TARGET_REMEDY[target.status]}`);
267
+ const targets = paths.map((path) => classifyTarget(resolve(cwd, path)));
268
+ const skipped = targets.filter(({ status }) => status === TARGET.unmatchedGlob)
269
+ .map(({ path }) => `[release-scan] skipped ${path} — no file matched this glob (an optional target, stated not silent).`);
270
+ const misaimed = targets.filter(({ status }) => TARGET_REMEDY[status] !== undefined)
271
+ .map(({ path, status }) => ({ path, status, remedy: TARGET_REMEDY[status] }));
272
+ const findings = findingsIn(targets);
273
+ if (findings.length === 0 && misaimed.length === 0) {
274
+ return { code: 0, lines: [...skipped, '[release-scan] clean — no AI attribution or reviewer-round identity found.'] };
263
275
  }
264
- const report = findingsIn(targets);
265
- for (const r of report) console.log(`[${r.kind}] ${r.file}:${r.line} — ${r.detail}`);
276
+ if (!reportOnly) return { code: 1, lines: composeScanBlock({ cwd: resolve(cwd), misaimed, findings, after: skipped }) };
277
+ const lines = [
278
+ ...skipped,
279
+ ...misaimed.map(({ path, status, remedy }) => `[release-scan] target ${path} contributed NO file (${status}) — ${remedy}`),
280
+ ...findings.map(({ kind, file, line, detail }) => `[${kind}] ${file}:${line} — ${detail}`),
281
+ ];
266
282
  if (misaimed.length > 0) {
267
- console.log(`\n[release-scan] ${misaimed.length} mis-aimed target(s) — this run proves nothing about them, so the clean verdict is refused.`);
268
- }
269
- if (report.length > 0) console.log(`\n[release-scan] ${report.length} finding(s).`);
270
- if (report.length === 0 && misaimed.length === 0) {
271
- console.log('[release-scan] clean — no AI attribution or reviewer-round identity found.');
272
- return 0;
283
+ lines.push('', `[release-scan] ${misaimed.length} mis-aimed target(s) — this run proves nothing about them, so the clean verdict is refused.`);
273
284
  }
274
- return reportOnly ? 0 : 1;
285
+ if (findings.length > 0) lines.push('', `[release-scan] ${findings.length} finding(s).`);
286
+ return { code: 0, lines };
287
+ };
288
+
289
+ export const main = (argv) => {
290
+ const { code, lines } = runScan(argv);
291
+ for (const line of lines) console.log(line);
292
+ return code;
275
293
  };
276
294
 
277
- if (isDirectRun(import.meta.url)) process.exitCode = main(process.argv.slice(2));
295
+ if (isDirectRun(import.meta.url)) {
296
+ runCheckerTail({ name: CHECKER_NAME, exitCode: 1, remedy: UNEXPECTED_REMEDY },
297
+ () => runScan(process.argv.slice(2)), process);
298
+ }
@@ -42,6 +42,7 @@ import { isNeverCommittableStat, shellQuoteArg } from './review-state.mjs';
42
42
  import { assertContainedRealPath } from './fs-safe.mjs';
43
43
  import { GIT_MAX_BUFFER } from './git-env.mjs';
44
44
  import { foreignMountTargets } from './mount-masks.mjs';
45
+ import { jsonForLine } from './source-size-refusal.mjs';
45
46
 
46
47
  export const MASKS_FENCE_START = '# >>> agent-workflow sandbox-masks — managed block, fully REPLACED by the kit sandbox-masks lane; do not hand-edit inside >>>';
47
48
  export const MASKS_FENCE_END = '# <<< agent-workflow sandbox-masks <<<';
@@ -225,7 +226,7 @@ export const probeSandboxMasks = ({ cwd = process.cwd(), lstat = lstatSync, list
225
226
  const fence = findMasksFence(lines);
226
227
  const staleReal = fence.state === 'ok' ? revalidateFence(fence.body, { root, lstat: lstatOnce, readMountinfo: once }) : [];
227
228
  const leftovers = clearOnly ? [] : staleReal.filter((rel) => isLeftoverStat(lstatOnce(join(root, rel))));
228
- if (leftovers.length > 0) throw fail(1, [...staleReal.filter((rel) => !leftovers.includes(rel)).map(staleRealLine), ...leftovers.map(leftoverLine)].join('\n'));
229
+ if (leftovers.length > 0) throw fail(1, [...formatGroup(staleRealHead, staleReal.filter((rel) => !leftovers.includes(rel))), ...formatGroup(leftoverHead, leftovers)].join('\n'));
229
230
  const applyCmd = `node ${shellQuoteArg(join(HERE, 'sandbox-masks.mjs'))} --cwd ${shellQuoteArg(root)} --apply`;
230
231
  return { root, excludeFile, gitCommonDir, content, lines, fence, masks, unrenderable, mountOnly, mountSignal, staleReal, applyCmd };
231
232
  };
@@ -281,8 +282,9 @@ export const planApply = (probe, { clear = false } = {}) => {
281
282
 
282
283
  // ── rendering ───────────────────────────────────────────────────────────────────────
283
284
 
284
- const staleRealLine = (rel) => ` ⚠ fenced entry became a REAL path: ${rel} — delete its line from the managed block BEFORE relying on git for this path: an excluded real file is silently skipped by bulk staging (git add -A / git add .), so it stays OUT of your commits, and an explicit git add refuses it without -f; .git/info/exclude never warns`;
285
- const leftoverLine = (rel) => ` ⚠ refusing: fenced entry ${rel} is an empty read-only file no arm calls a mask, so neither verdict is given — a running sandbox's mask: re-run once no other sandboxed command runs; litter a sandbox left: remove the file outside the sandbox and keep its line; a real file: delete its line`;
285
+ const staleRealHead = (n) => ` ⚠ ${n} fenced entr(ies) became REAL path(s) — delete each one's line from the managed block BEFORE relying on git for it: an excluded real file is silently skipped by bulk staging (git add -A / git add .), so it stays OUT of your commits, and an explicit git add refuses it without -f; .git/info/exclude never warns:`;
286
+ const leftoverHead = (n) => ` ⚠ refusing: ${n} fenced entr(ies) are empty read-only files no arm calls a mask, so neither verdict is given — a running sandbox's mask: re-run once no other sandboxed command runs; litter a sandbox left: remove the file outside the sandbox and keep its line; a real file: delete its line:`;
287
+ const formatGroup = (sentence, paths) => paths.length === 0 ? [] : [sentence(paths.length), ...paths.map((rel) => ' ' + jsonForLine(rel))];
286
288
 
287
289
  const formatProbe = (probe) => {
288
290
  const lines = [
@@ -294,7 +296,7 @@ const formatProbe = (probe) => {
294
296
  lines.push(` masks visible now: ${probe.masks.length === 0 ? '0 (outside the sandbox or clean)' : ''}`);
295
297
  for (const m of probe.masks) lines.push(` · ${m}${probe.mountOnly.includes(m) ? ' (mount-only: it rides git add -A and the review fingerprint while git does not ignore it)' : ''}`);
296
298
  if (probe.mountSignal === 'absent') lines.push(' mount signal: not read on this platform — only device/FIFO/socket masks are judged');
297
- lines.push(...probe.staleReal.map(staleRealLine));
299
+ lines.push(...formatGroup(staleRealHead, probe.staleReal));
298
300
  for (const rel of probe.unrenderable) {
299
301
  lines.push(` ⚠ mask name carries a newline or ends with a tab and cannot be expressed as ONE exclude rule — NOT written (the mask itself stays untracked): ${JSON.stringify(rel)}`);
300
302
  }