@skitterbyte/skitterspec-github 3.1.3 → 3.2.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.
@@ -0,0 +1,229 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * The pages an autonomous run leaves behind (feat-autonomous-run, phase 3):
5
+ *
6
+ * - a SNAPSHOT per phase — that phase's review page, kept as it was when the
7
+ * run committed it (`reviews/<spec>/phase-<n>.html`), read-only;
8
+ * - the RUN INDEX — every snapshot as it lands, with its commit and report,
9
+ * served at `/<token>/<spec>/run` so the run can be read while it goes;
10
+ * - the AGGREGATE that heads the final page — every phase's Notes and
11
+ * Follow-ups, the stops and compactions, in one list.
12
+ *
13
+ * Everything here is built from records the engine already keeps (the run
14
+ * record, the report sidecar) and is escaped on the way out. Nothing reads a
15
+ * diff, and nothing here decides anything.
16
+ */
17
+
18
+ const fs = require('node:fs')
19
+ const path = require('node:path')
20
+
21
+ const { readReport, reportHtmlFor, CARRIED } = require('./report.js')
22
+ const { readRun, compactionSummary } = require('./run.js')
23
+
24
+ function escapeHtml(s) {
25
+ return String(s).replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' })[c])
26
+ }
27
+
28
+ function inline(text) {
29
+ return escapeHtml(text)
30
+ .replace(/`([^`]+)`/g, '<code>$1</code>')
31
+ .replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>')
32
+ }
33
+
34
+ /** Where a phase's snapshot lives, beside the spec's page. */
35
+ function snapshotPath(outPath, phase) {
36
+ return path.join(outPath.replace(/\.html$/, ''), `phase-${phase}.html`)
37
+ }
38
+
39
+ // The state dir is the reviews dir's parent; the run record sits beside it.
40
+ function stateDirOf(outPath) {
41
+ return path.dirname(path.dirname(outPath))
42
+ }
43
+
44
+ /** Which phases have a snapshot on disk, ascending. Never throws. */
45
+ function snapshotPhases(outPath) {
46
+ let names
47
+ try {
48
+ names = fs.readdirSync(outPath.replace(/\.html$/, ''))
49
+ } catch {
50
+ return []
51
+ }
52
+ return names
53
+ .map((n) => /^phase-(\d+)\.html$/.exec(n))
54
+ .filter(Boolean)
55
+ .map((m) => Number(m[1]))
56
+ .sort((a, b) => a - b)
57
+ }
58
+
59
+ // A value that says nothing — `none`, `—` — is not an item to carry forward.
60
+ const EMPTY = /^(none|—|-|n\/a)\.?$/i
61
+
62
+ /**
63
+ * Every phase's carried rows, in phase order: `[{ phase, field, value, more }]`.
64
+ * Pure.
65
+ */
66
+ function carriedItems(report) {
67
+ const phases = Object.values((report && report.phases) || {})
68
+ .filter((e) => e && Array.isArray(e.rows))
69
+ .sort((a, b) => (Number(a.phase) || 0) - (Number(b.phase) || 0))
70
+ const out = []
71
+ for (const e of phases) {
72
+ for (const r of e.rows) {
73
+ if (!CARRIED.includes(r.field) || EMPTY.test(String(r.value).trim())) continue
74
+ out.push({ phase: e.phase, field: r.field, value: r.value, more: r.more || [] })
75
+ }
76
+ }
77
+ return out
78
+ }
79
+
80
+ /**
81
+ * The block that heads the final page. Empty string when the run left nothing
82
+ * to say AND there is no run — so a final page for a spec with no record reads
83
+ * as an ordinary page rather than an empty box.
84
+ */
85
+ function renderAggregate({ report, run, spec, snapshots = [] }) {
86
+ const items = carriedItems(report)
87
+ const stops = (run && run.stops) || []
88
+ const compacted = compactionSummary(run)
89
+ if (!items.length && !stops.length && !compacted && !snapshots.length && !run) return ''
90
+ const parts = ['<section class="report run-aggregate">', '<h2 class="report-heading">The whole run</h2>']
91
+ const followUps = items.filter((i) => i.field === 'Follow-ups')
92
+ const notes = items.filter((i) => i.field === 'Notes')
93
+ const list = (title, rows) => {
94
+ if (!rows.length) return
95
+ parts.push(`<p class="report-title"><strong>${title}</strong></p>`, '<ul class="run-items">')
96
+ for (const i of rows) {
97
+ const more = i.more.map((m) => `<br>${inline(m)}`).join('')
98
+ parts.push(`<li><span class="run-phase">phase ${escapeHtml(i.phase)}</span> ${inline(i.value)}${more}</li>`)
99
+ }
100
+ parts.push('</ul>')
101
+ }
102
+ list('Follow-ups, bugs and suggestions', followUps)
103
+ list('Notes', notes)
104
+ if (!followUps.length && !notes.length) parts.push('<p class="report-title">No phase recorded a follow-up or a note.</p>')
105
+ if (stops.length) {
106
+ parts.push('<p class="report-title"><strong>Stops</strong></p>', '<ul class="run-items">')
107
+ for (const s of stops) parts.push(`<li><span class="run-phase">phase ${escapeHtml(s.phase)}</span> ${inline(s.reason)}</li>`)
108
+ parts.push('</ul>')
109
+ }
110
+ if (compacted) parts.push(`<p class="report-title">Context ${escapeHtml(compacted)}.</p>`)
111
+ if (snapshots.length) {
112
+ const links = snapshots.map((n) => `<a href="${encodeURIComponent(spec)}/phase-${n}">phase ${n}</a>`).join(' · ')
113
+ parts.push(`<p class="report-title">Each phase as reviewed: ${links} · <a href="${encodeURIComponent(spec)}/run">run index</a></p>`)
114
+ }
115
+ parts.push('</section>')
116
+ return parts.join('\n')
117
+ }
118
+
119
+ /** The aggregate for a spec, read from its records. '' on any cannot-tell. */
120
+ function aggregateHtmlFor(outPath, spec) {
121
+ const read = readReport(outPath, spec)
122
+ const run = readRun(stateDirOf(outPath), spec)
123
+ return renderAggregate({
124
+ report: read.corrupt ? null : read.report,
125
+ run: run.corrupt ? null : run.record,
126
+ spec,
127
+ snapshots: snapshotPhases(outPath),
128
+ })
129
+ }
130
+
131
+ /**
132
+ * The run index page — a doorway, styled like the server's index. Pure.
133
+ * `phases` is the union of what the run record and the disk know, so a
134
+ * snapshot written before its `run phase` call still shows.
135
+ */
136
+ function renderRunIndex({ spec, run = null, report = null, snapshots = [], token = null, project = null }) {
137
+ const prefix = token ? `/${token}` : ''
138
+ const base = `${prefix}/${encodeURIComponent(spec)}`
139
+ const byPhase = new Map()
140
+ for (const p of (run && run.phases) || []) byPhase.set(p.n, { ...p })
141
+ for (const n of snapshots) byPhase.set(n, { n, ...(byPhase.get(n) || {}), snapshot: true })
142
+ const reports = (report && report.phases) || {}
143
+ const rows = [...byPhase.values()]
144
+ .sort((a, b) => a.n - b.n)
145
+ .map((p) => {
146
+ const r = reports[String(p.n)]
147
+ const built = r && r.rows ? r.rows.find((x) => x.field === 'Built') : null
148
+ const link = p.snapshot ? `<a href="${base}/phase-${p.n}">phase ${p.n}</a>` : `phase ${p.n}`
149
+ return (
150
+ `<li>${link}` +
151
+ (p.commit ? `<span class="b">${escapeHtml(String(p.commit).slice(0, 8))}</span>` : '') +
152
+ (built ? `<span class="t">${inline(built.value)}</span>` : '') +
153
+ '</li>'
154
+ )
155
+ })
156
+ const state = run ? (run.active ? `running · ends on <strong>${escapeHtml(run.then)}</strong>` : `ended · ${escapeHtml(run.outcome || run.then)}`) : 'no run recorded'
157
+ const compacted = compactionSummary(run)
158
+ const heading = `${project ? `${escapeHtml(project)} · ` : ''}${escapeHtml(spec)} · run`
159
+ const body = rows.length ? `<ul>\n${rows.join('\n')}\n</ul>` : '<p class="empty">No phase has been committed by this run yet.</p>'
160
+ return `<!doctype html>
161
+ <html lang="en">
162
+ <head>
163
+ <meta charset="utf-8">
164
+ <meta name="viewport" content="width=device-width, initial-scale=1">
165
+ <title>${heading}</title>
166
+ <style>
167
+ :root { --bg:#fff; --fg:#1a1a1a; --dim:#6b6b6b; --line:#e3e3e3; --link:#0b5fbd }
168
+ @media (prefers-color-scheme: dark) {
169
+ :root:not([data-theme="light"]) { --bg:#16181c; --fg:#e6e6e6; --dim:#9a9a9a; --line:#2c2f36; --link:#7cb7ff }
170
+ }
171
+ * { box-sizing:border-box }
172
+ body { margin:0; padding:2rem 1rem; background:var(--bg); color:var(--fg);
173
+ font:15px/1.5 ui-sans-serif,system-ui,-apple-system,Segoe UI,Roboto,sans-serif }
174
+ main { max-width:52rem; margin:0 auto }
175
+ h1 { font-size:1.1rem; margin:0 0 .25rem; font-weight:600 }
176
+ .state { color:var(--dim); margin:0 0 1.25rem }
177
+ ul { list-style:none; margin:0; padding:0 }
178
+ li { display:flex; flex-wrap:wrap; gap:.75rem; align-items:baseline; padding:.7rem 0; border-top:1px solid var(--line) }
179
+ a { color:var(--link); text-decoration:none; font-weight:600 }
180
+ a:hover { text-decoration:underline }
181
+ .b { color:var(--dim); font-family:ui-monospace,SFMono-Regular,Menlo,monospace; font-size:.85em }
182
+ .t { flex-basis:100%; color:var(--fg); font-size:.9em; overflow-wrap:anywhere }
183
+ .empty { color:var(--dim) }
184
+ code { font-family:ui-monospace,SFMono-Regular,Menlo,monospace }
185
+ </style>
186
+ </head>
187
+ <body>
188
+ <main>
189
+ <h1>${heading}</h1>
190
+ <p class="state">${state}${compacted ? ` · ${escapeHtml(compacted)}` : ''} · <a href="${base}">current page</a></p>
191
+ ${body}
192
+ </main>
193
+ </body>
194
+ </html>
195
+ `
196
+ }
197
+
198
+ /** The run index for a spec, read from its records. */
199
+ function runIndexFor(outPath, spec, { token = null, project = null } = {}) {
200
+ const read = readReport(outPath, spec)
201
+ const run = readRun(stateDirOf(outPath), spec)
202
+ return renderRunIndex({
203
+ spec,
204
+ run: run.corrupt ? null : run.record,
205
+ report: read.corrupt ? null : read.report,
206
+ snapshots: snapshotPhases(outPath),
207
+ token,
208
+ project,
209
+ })
210
+ }
211
+
212
+ /**
213
+ * What heads a page, by its button set: the final page carries the whole run;
214
+ * every other page its latest phase report. '' when there is nothing to show.
215
+ */
216
+ function pageHeadFor(outPath, spec, buttons) {
217
+ return buttons === 'final' ? aggregateHtmlFor(outPath, spec) : reportHtmlFor(outPath, spec)
218
+ }
219
+
220
+ module.exports = {
221
+ pageHeadFor,
222
+ snapshotPath,
223
+ snapshotPhases,
224
+ carriedItems,
225
+ renderAggregate,
226
+ aggregateHtmlFor,
227
+ renderRunIndex,
228
+ runIndexFor,
229
+ }
package/src/env/serve.js CHANGED
@@ -30,6 +30,7 @@ const fs = require('node:fs')
30
30
  const path = require('node:path')
31
31
  const crypto = require('node:crypto')
32
32
 
33
+ const { pageHeadFor, runIndexFor, snapshotPath } = require('./runpage.js')
33
34
  const {
34
35
  liveWorktreePaths,
35
36
  allSpecs,
@@ -44,7 +45,7 @@ const { renderEpicPage } = require('./epicpage.js')
44
45
  const { readRegistry } = require('./registry.js')
45
46
  const { loadEnvConfig } = require('./config.js')
46
47
  const { primaryAnchor, attachProject, projectName, repoRootOf, prefixOf, fromRepoPath, toRepoPath } = require('./project.js')
47
- const { specDocsIn, classifyDirtyTree, dirtyPaths } = require('./classify.js')
48
+ const { specDocsIn, classifyDirtyTree, dirtyPaths, treeReader } = require('./classify.js')
48
49
  const { liveStateFor } = require('./live.js')
49
50
  const { preferRemoteBase } = require('./host.js')
50
51
  const { ROUTE: TADA_ROUTE, renderServedTada } = require('../tada/serve.js')
@@ -96,6 +97,15 @@ function routeFor(url, { token = null } = {}) {
96
97
  }
97
98
 
98
99
  if (segments.length === 0) return { kind: 'index' }
100
+ // AN AUTONOMOUS RUN'S PAGES (feat-autonomous-run): `<spec>/run` is the run
101
+ // index, `<spec>/phase-<n>` a kept phase page. Both are reads; anything else
102
+ // two segments deep is not a page.
103
+ if (segments.length === 2) {
104
+ if (segments[1] === 'run') return { kind: 'run', spec: segments[0] }
105
+ const m = /^phase-(\d+)$/.exec(segments[1])
106
+ if (m) return { kind: 'snapshot', spec: segments[0], phase: Number(m[1]) }
107
+ return { kind: 'notfound' }
108
+ }
99
109
  if (segments.length > 1) return { kind: 'notfound' }
100
110
  // The ta-da page: a window, not a spec. Its query is the window and passed
101
111
  // through whole, to be read — and refused if unreadable — by `tada/serve.js`.
@@ -253,7 +263,8 @@ function docsWorktree(wt, spec, config) {
253
263
  const paths = dirtyPaths(trimmedGitReader(wt))
254
264
  // Cannot tell — not "no documents".
255
265
  if (paths === null) return null
256
- const { owned, foreign } = classifyDirtyTree(spec, paths, config)
266
+ // An epic's members, written beside it in this same tree, are its documents.
267
+ const { owned, foreign } = classifyDirtyTree(spec, paths, config, { readFile: treeReader(wt) })
257
268
  // A TRACKER SNAPSHOT IS NOT SOMEBODY ELSE'S WORK, and requiring a
258
269
  // foreign-free tree cost the whole page for the commonest authoring tree
259
270
  // there is. The linking push writes `specs/.core/linear-base/<ID>.base.json`
@@ -518,7 +529,9 @@ function receivePass(dir, config, spec, blob) {
518
529
  * so every `/no-spec` page served over http offered to put nothing in flight,
519
530
  * and the pass came back naming a verdict its own skill could not act on.
520
531
  */
521
- const NARROWING_SETS = ['midrun', 'refresh', 'fix']
532
+ // `final` too: the run's last render declared it, and a served re-render
533
+ // must keep offering the ending rather than fall back to `Commit`.
534
+ const NARROWING_SETS = ['midrun', 'refresh', 'fix', 'final']
522
535
 
523
536
  function buttonsForView(viewKind, spec, recorded) {
524
537
  if (NARROWING_SETS.includes(recorded)) return recorded
@@ -573,7 +586,7 @@ function renderSpecPage(dir, config, spec, { branch = false } = {}) {
573
586
  treePath: view.tree,
574
587
  })
575
588
  return {
576
- html: renderReviewPage(data, { reviewHtml: renderReviewBlock(data.review) }),
589
+ html: renderReviewPage(data, { reviewHtml: pageHeadFor(out, spec.folder, buttons) + renderReviewBlock(data.review) }),
577
590
  totals: data.totals,
578
591
  mode: data.mode,
579
592
  fellBack: false,
@@ -680,7 +693,7 @@ function renderSpecPage(dir, config, spec, { branch = false } = {}) {
680
693
  }
681
694
 
682
695
  return {
683
- html: renderReviewPage(data, { reviewHtml: renderReviewBlock(data.review) }),
696
+ html: renderReviewPage(data, { reviewHtml: pageHeadFor(reviewOutPath(dir, spec.folder, null), spec.folder, buttons) + renderReviewBlock(data.review) }),
684
697
  totals: data.totals,
685
698
  mode: data.mode,
686
699
  fellBack,
@@ -815,7 +828,7 @@ function readBody(req, limit = MAX_PASS_BYTES) {
815
828
  })
816
829
  }
817
830
 
818
- function createReviewServer({ resolveEntries, resolveEpics = () => [], render, receive = null, passState = null, tada = null, token = null, project = null }) {
831
+ function createReviewServer({ resolveEntries, resolveEpics = () => [], render, receive = null, passState = null, tada = null, runPage = null, snapshot = null, token = null, project = null }) {
819
832
  return http.createServer((req, res) => {
820
833
  const send = (code, body, type = 'text/html; charset=utf-8') => {
821
834
  res.writeHead(code, { 'content-type': type, 'cache-control': 'no-store' })
@@ -882,6 +895,19 @@ function createReviewServer({ resolveEntries, resolveEpics = () => [], render, r
882
895
  return
883
896
  }
884
897
 
898
+ // A SERVER BUILT WITHOUT THE HOOKS is an older one, and says not found —
899
+ // the same answer an unknown path gets.
900
+ if (route.kind === 'run' || route.kind === 'snapshot') {
901
+ const hook = route.kind === 'run' ? runPage : snapshot
902
+ if (!hook) return send(404, 'not found', 'text/plain; charset=utf-8')
903
+ try {
904
+ const out = route.kind === 'run' ? hook(route.spec, { token }) : hook(route.spec, route.phase)
905
+ return out && out.html ? send(200, out.html) : send(404, 'not found', 'text/plain; charset=utf-8')
906
+ } catch (err) {
907
+ return send(500, `render failed: ${err.message}`, 'text/plain; charset=utf-8')
908
+ }
909
+ }
910
+
885
911
  try {
886
912
  if (route.kind === 'index') return send(200, renderIndex(resolveEntries(), { token, epics: resolveEpics(), project }))
887
913
  const out = render(route.spec, { branch: route.branch })
@@ -1105,6 +1131,24 @@ function serverHooks(dir, config) {
1105
1131
  return renderSpecPage(dir, config, resolveOne(folder), opts)
1106
1132
  },
1107
1133
  receive: (folder, blob) => receivePass(dir, config, resolveOne(folder), blob),
1134
+ // The run index, built per request from the run record and the report
1135
+ // sidecar; a spec this daemon cannot resolve is a 404, not an empty run.
1136
+ runPage: (folder, { token: t = null } = {}) => {
1137
+ const one = resolveOne(folder)
1138
+ if (!one) return null
1139
+ return { html: runIndexFor(reviewOutPath(dir, one.folder, null), one.folder, { token: t, project: projectName(config) }) }
1140
+ },
1141
+ // A kept phase page is served as written — it is a record of what that
1142
+ // phase looked like, so re-rendering it from today's tree would defeat it.
1143
+ snapshot: (folder, phase) => {
1144
+ const one = resolveOne(folder)
1145
+ if (!one) return null
1146
+ try {
1147
+ return { html: fs.readFileSync(snapshotPath(reviewOutPath(dir, one.folder, null), phase), 'utf8') }
1148
+ } catch {
1149
+ return null
1150
+ }
1151
+ },
1108
1152
  // A spec this daemon cannot resolve is not a pass that was claimed — it is
1109
1153
  // a lookup that could not see, so it says nothing rather than reporting the
1110
1154
  // comfortable answer. Same rule the engine's own three states follow.
package/src/ideacmd.js CHANGED
@@ -26,7 +26,7 @@ const { describeBaseBranch, baseRemote } = require('./env/resolve.js')
26
26
  const { primaryAnchor } = require('./env/project.js')
27
27
 
28
28
  const USAGE =
29
- 'Usage: skitterspec idea add <text> | list [--count] | drop <id> [--reason <why>] [--json] [--dir <path>]\n'
29
+ 'Usage: skitterspec idea add <text> [--product <key>] | list [--count] | drop <id> [--reason <why>] [--json] [--dir <path>]\n'
30
30
 
31
31
  function reader(cwd) {
32
32
  return (argv) => {
@@ -56,7 +56,7 @@ function git(cwd, argv, { input, env } = {}) {
56
56
  }
57
57
 
58
58
  function parseArgs(argv) {
59
- const flags = { json: false, count: false, dir: null, reason: null }
59
+ const flags = { json: false, count: false, dir: null, reason: null, product: null }
60
60
  const positional = []
61
61
  for (let i = 0; i < argv.length; i++) {
62
62
  const a = argv[i]
@@ -64,6 +64,7 @@ function parseArgs(argv) {
64
64
  else if (a === '--count') flags.count = true
65
65
  else if (a === '--dir') flags.dir = argv[++i]
66
66
  else if (a === '--reason') flags.reason = argv[++i]
67
+ else if (a === '--product') flags.product = argv[++i]
67
68
  else positional.push(a)
68
69
  }
69
70
  return { flags, positional }
@@ -208,6 +209,8 @@ async function fileStore(sub, positional, flags, { cwd, now, out }) {
208
209
  `idea: ${verb} "${plan.id}" ${sub === 'add' ? 'to' : 'from'} ${ctx.rel} on ${ctx.base} (${commit.slice(0, 7)})`,
209
210
  ` title: ${plan.entry.title}`,
210
211
  ` pushed: no — ${push} publishes it`,
212
+ // The file has no products; say so rather than drop the flag in silence.
213
+ ...(sub === 'add' && flags.product ? [` product: ${flags.product} not recorded — specs/ideas.md has no products`] : []),
211
214
  ],
212
215
  )
213
216
  return 0
package/src/provider.js CHANGED
@@ -9,6 +9,7 @@
9
9
  // provider's `src/register.js` from where it is installed, and hands it the
10
10
  // base's own engine modules to register on.
11
11
 
12
+ const { spawnSync } = require('node:child_process')
12
13
  const { existsSync } = require('node:fs')
13
14
  const { dirname, join } = require('node:path')
14
15
 
@@ -89,4 +90,48 @@ function registerConfiguredProvider({ cwd, envConfig, idea, resolve = resolvePac
89
90
  return { provider: p.name, registered: 'config' }
90
91
  }
91
92
 
92
- module.exports = { registerConfiguredProvider, PROVIDERS }
93
+ /**
94
+ * Run a verb the base does not ship (`commands`, e.g. `spec-sync`) on the
95
+ * provider configured in the project at or above `cwd`, through that
96
+ * provider's own bin, so `skitterspec spec-sync …` answers exactly as
97
+ * `skitterspec-<provider> spec-sync …` does — the skills call the bare name.
98
+ *
99
+ * Returns the exit status to use, or `null` when there is nothing to forward
100
+ * and the base should carry on as it would have: a verb it ships, no project,
101
+ * no provider configured, or two of them (registerConfiguredProvider warns).
102
+ *
103
+ * WHAT WOULD FOOL THIS: a provider installed where Node's resolution cannot
104
+ * see it from the base or the project reads as not installed, and the verb is
105
+ * refused naming the package — never run on a guessed provider.
106
+ */
107
+ function forwardProviderCommand({
108
+ cwd,
109
+ argv,
110
+ commands,
111
+ resolve = resolvePackage,
112
+ warn = () => {},
113
+ spawn = spawnSync,
114
+ }) {
115
+ const [cmd] = argv
116
+ if (!commands.includes(cmd)) return null
117
+ const dir = projectDir(cwd)
118
+ if (!dir) return null
119
+ const configured = PROVIDERS.filter((p) => existsSync(join(dir, p.configFile)))
120
+ if (configured.length !== 1) return null
121
+ const p = configured[0]
122
+ const bin = join('bin', `skitterspec-${p.name}.js`)
123
+ for (const [pkg] of p.candidates) {
124
+ const root = resolve(pkg, [__dirname, dir])
125
+ if (root && existsSync(join(root, bin))) {
126
+ const r = spawn(process.execPath, [join(root, bin), ...argv], { cwd, stdio: 'inherit' })
127
+ return r.status ?? 1
128
+ }
129
+ }
130
+ warn(
131
+ `skitterspec: ${cmd} needs @skitterbyte/skitterspec-${p.name} installed beside this one — ` +
132
+ `${p.configFile} is here but it is not. Install it alongside @skitterbyte/skitterspec, at the latest of each.`,
133
+ )
134
+ return 1
135
+ }
136
+
137
+ module.exports = { registerConfiguredProvider, forwardProviderCommand, PROVIDERS }
@@ -138,6 +138,9 @@ async function applyInner({
138
138
  // state name for these and only these (`recordPush`). A held state counts:
139
139
  // run 2 sends it, and what run 2 records has to match what run 1 committed.
140
140
  const sent = { issue: !!heldState || !!(plan.issue && plan.issue.state != null), subIssues: new Set() }
141
+ // A place rides the plan's issue: on a create it is always written, on an
142
+ // update only when the plan carries it. Recorded only once written.
143
+ sent.placement = !!(plan.issue && plan.issue.placement !== undefined)
141
144
  // Handed out immediately, so a throw from anywhere below still reports what
142
145
  // had been stamped by the time it happened.
143
146
  if (progress) progress.result = result
@@ -231,6 +231,18 @@ function stateNamesRecord(projection, previous, sent) {
231
231
  return out
232
232
  }
233
233
 
234
+ /**
235
+ * The `placement` record for a snapshot: the place this push SENT, or the one
236
+ * the previous snapshot had when this push sent none, or undefined. The same
237
+ * rule as `stateNamesRecord` — recording a place nobody wrote would claim the
238
+ * tracker holds it.
239
+ */
240
+ function placementRecord(projection, previous, sent) {
241
+ const p = projection || {}
242
+ if (sent && sent.placement && p.placement !== undefined) return p.placement
243
+ return previous && typeof previous.placement === 'string' ? previous.placement : undefined
244
+ }
245
+
234
246
  // Has the state an unchanged item maps to moved under it — a state-map edit in
235
247
  // the config rather than a move of the spec? Only a RECORDED name can say: an
236
248
  // item with none is cannot-tell and plans nothing, so an upgrade or a config
@@ -304,9 +316,27 @@ function planChanges(projection, snapshot, { linked = false, epic = false } = {}
304
316
  // is above, and nothing is retired (spec feat-epic-migration, Decision 2).
305
317
  if (epic && unclaimed.length) subIssues.retire = unclaimed.slice()
306
318
 
319
+ // PLACEMENT: where the items belong (Azure's area path). Sent when the
320
+ // project places specs and the place differs from the one last sent. An
321
+ // unrecorded place on a linked spec is sent too: placement only comes into
322
+ // play when the project configures it, so that first push is the move the
323
+ // project asked for, not a guess about someone else's filing.
324
+ const place = p.placement
325
+ const moved = place !== undefined && snap.placement !== place
326
+ if (place !== undefined) for (const c of subIssues.create) c.placement = place
327
+ if (moved) {
328
+ for (const s of p.subIssues || []) {
329
+ if (s.id == null) continue
330
+ const existing = subIssues.update.find((u) => String(u.id) === String(s.id))
331
+ if (existing) existing.placement = place
332
+ else subIssues.update.push({ ref: s.ref, id: s.id, placement: place })
333
+ }
334
+ }
335
+
307
336
  const plan = { subIssues }
308
337
  if (unstamped.length) plan.unstamped = unstamped
309
- const issue = issueChanges(p, snap, { linked })
338
+ let issue = issueChanges(p, snap, { linked })
339
+ if (moved) issue = { ...(issue || {}), placement: place }
310
340
  if (issue) plan.issue = issue
311
341
  return plan
312
342
  }
@@ -413,6 +443,7 @@ module.exports = {
413
443
  specIssueFieldHashes,
414
444
  snapshotOf,
415
445
  stateNamesRecord,
446
+ placementRecord,
416
447
  isEmptyPlan,
417
448
  hashField,
418
449
  stableStringify,
@@ -436,7 +436,7 @@ function readSnapshot(snapshotDir, config) {
436
436
  }
437
437
 
438
438
  // The spec's own `> **Severity:**`, `> **Incident:**`, `> **Epic:**`,
439
- // `> **Waits on:**` and `> **Lanes:**` headers, off the overview's blockquote
439
+ // `> **Waits on:**`, `> **Lanes:**` and `> **Product:**` headers, off the overview's blockquote
440
440
  // block. They are PUSH-TIME EXTRAS, deliberately not keys on `normalizeLocal`'s
441
441
  // field set: severity lands in a provider-specific home (a field, a label),
442
442
  // the incident and epic links as typed relations, and the waits and lanes are
@@ -448,7 +448,7 @@ function specHeaders(snapshotDir, config) {
448
448
  try {
449
449
  raw = fs.readFileSync(path.join(snapshotDir, overviewFile), 'utf-8')
450
450
  } catch {
451
- return { severity: null, incident: null, epic: null, waitsOn: [], lanes: null }
451
+ return { severity: null, incident: null, epic: null, waitsOn: [], lanes: null, product: null }
452
452
  }
453
453
  const read = (name) => {
454
454
  const m = new RegExp(`^>\\s*\\*\\*${name}:\\*\\*\\s*(.+)$`, 'm').exec(raw)
@@ -460,6 +460,7 @@ function specHeaders(snapshotDir, config) {
460
460
  epic: unquote(read('Epic')) || null,
461
461
  waitsOn: parseWaitsOn(read('Waits on')),
462
462
  lanes: parseLanes(read('Lanes')),
463
+ product: unquote(read('Product')) || null,
463
464
  }
464
465
  }
465
466
 
@@ -20,7 +20,7 @@ const path = require('node:path')
20
20
  const { normalizeLocal, phasesWithheld, phaseModeFor, ownershipOf, readSnapshot } = require('./normalize.js')
21
21
  const { descriptionMode } = require('./summary.js')
22
22
  const { fieldsOf } = require('./fields.js')
23
- const { planChanges, snapshotOf, stateNamesRecord, isEmptyPlan } = require('./compare.js')
23
+ const { planChanges, snapshotOf, stateNamesRecord, placementRecord, isEmptyPlan } = require('./compare.js')
24
24
  const { readBase, writeBase } = require('./base.js')
25
25
  const { detectLegacyMirror } = require('./legacy.js')
26
26
 
@@ -58,9 +58,34 @@ function projectionOf(snapshotDir, config) {
58
58
  // pulled, and read by name, so it can never reach a hash.
59
59
  if (ownershipOf(config, 'workflowState') === 'pull') projection.statePulled = true
60
60
  attachStateNames(projection, snapshotDir, config)
61
+ attachPlacement(projection, snapshotDir, config)
61
62
  return projection
62
63
  }
63
64
 
65
+ // Where on the tracker this spec's items belong — Azure's area path, from the
66
+ // provider's `config.remote.placement(snapshotDir)` hook: a string when the
67
+ // project places specs, `undefined` when it does not (no hook, or the hook
68
+ // says the feature is not in play). Read by name, so it never reaches a hash:
69
+ // recorded beside them as `placement`, it is what lets a plan see a spec move
70
+ // that no field hash covers. A hook that throws REFUSES the plan — a spec
71
+ // naming a place the project does not have must not be filed somewhere else —
72
+ // but only the plan: the error is carried, not raised, so a status or a list
73
+ // over every spec is not taken down by one spec's bad header.
74
+ function attachPlacement(projection, snapshotDir, config) {
75
+ const hook = config && config.remote && config.remote.placement
76
+ if (typeof hook !== 'function') return
77
+ let value
78
+ try {
79
+ value = hook(snapshotDir)
80
+ } catch (error) {
81
+ // Tagged, so a caller can relay it as the refusal it is rather than a crash.
82
+ if (error && typeof error === 'object') error.placementRefused = true
83
+ Object.defineProperty(projection, 'placementError', { value: error, enumerable: false })
84
+ return
85
+ }
86
+ if (typeof value === 'string' && value) projection.placement = value
87
+ }
88
+
64
89
  // The tracker state NAME each bucket resolves to today, from the provider's
65
90
  // `config.remote.writtenStateName(bucket, role, snapshotDir)` hook: a string,
66
91
  // `null` for "this bucket sends no state", or `undefined` for cannot-tell — no
@@ -103,6 +128,7 @@ function isLinked(snapshotDir, config) {
103
128
 
104
129
  function push({ dir, snapshotDir, identifier, config }) {
105
130
  const projection = projectionOf(snapshotDir, config)
131
+ if (projection.placementError) throw projection.placementError
106
132
  const snapshot = readBase(dir, identifier, config)
107
133
  const epic = path.basename(String(snapshotDir || '')).startsWith('epic-')
108
134
  const plan = planChanges(projection, snapshot, { linked: isLinked(snapshotDir, config), epic })
@@ -150,6 +176,8 @@ function recordPush({ dir, snapshotDir, identifier, config, sent = null, keepSub
150
176
  }
151
177
  const names = stateNamesRecord(projection, before, sent)
152
178
  if (names) snapshot.stateNames = names
179
+ const placement = placementRecord(projection, before, sent)
180
+ if (placement !== undefined) snapshot.placement = placement
153
181
  return writeBase(dir, identifier, config, snapshot)
154
182
  }
155
183