claude-code-session-manager 0.138.0 → 0.140.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.
Files changed (194) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/README.md +352 -79
  3. package/dist/assets/AppSettings-CMFEM68R.js +2 -0
  4. package/dist/assets/History--JwsFnbn.js +2 -0
  5. package/dist/assets/HomeClaudeConfig-ijEXs--3.js +3 -0
  6. package/dist/assets/{Panel-CeDiyuNn.js → Panel-CALyU0pe.js} +1 -1
  7. package/dist/assets/ProjectClaudeConfig-sdlA-fUb.js +26 -0
  8. package/dist/assets/Scheduler-YT3j8SUa.js +16 -0
  9. package/dist/assets/{SkillReferenceGraph-CFMK8NJh.js → SkillReferenceGraph-CxAuwhNN.js} +1 -1
  10. package/dist/assets/Skills-DtRzghn5.js +67 -0
  11. package/dist/assets/{TiptapBody-D1kTj-tn.js → TiptapBody-DApeu7x8.js} +60 -54
  12. package/dist/assets/ViewTabs-B7qLXRAH.js +1 -0
  13. package/dist/assets/{VoiceButton-CZeyPM31.js → VoiceButton-DtStfv1H.js} +1 -1
  14. package/dist/assets/{historyTotals-B00l64Jw.js → historyTotals-ydfnwepc.js} +1 -1
  15. package/dist/assets/index-CtxruO1L.js +3121 -0
  16. package/dist/assets/{index-62tyjEQB.css → index-DKXdXfka.css} +1 -1
  17. package/dist/index.html +2 -2
  18. package/dist-web/app.css +1 -1
  19. package/dist-web/app.js +467 -451
  20. package/package.json +17 -6
  21. package/plugins/AGENTS.md +60 -0
  22. package/plugins/CLAUDE.md +1 -60
  23. package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
  24. package/plugins/session-manager-dev/skills/builder/SKILL.md +12 -4
  25. package/plugins/session-manager-dev/skills/builder/scripts/publish-preflight.cjs +255 -0
  26. package/plugins/session-manager-dev/skills/develop/SKILL.md +36 -22
  27. package/plugins/session-manager-dev/skills/maintaining-md-network/SKILL.md +5 -4
  28. package/plugins/session-manager-dev/skills/maintaining-md-network/audit.md +4 -2
  29. package/plugins/session-manager-dev/skills/maintaining-md-network/drift-check.md +16 -12
  30. package/plugins/session-manager-dev/skills/maintaining-md-network/migrate-to-agents-md.md +15 -0
  31. package/plugins/session-manager-dev/skills/maintaining-md-network/placement.md +50 -2
  32. package/plugins/session-manager-dev/skills/maintaining-md-network/plan.md +10 -10
  33. package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/drift-check.cjs +117 -112
  34. package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/mdDuplicates.cjs +182 -0
  35. package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/mdLinks.cjs +340 -0
  36. package/scripts/README.md +2 -0
  37. package/scripts/hooks/guard-tool-risk.cjs +91 -0
  38. package/scripts/hooks/lib/guard-tool-risk-policy.cjs +217 -0
  39. package/scripts/ops-sweep.cjs +53 -23
  40. package/scripts/scheduler-mcp-server.cjs +360 -35
  41. package/src/main/build-info.json +4 -4
  42. package/src/main/chatRunner.cjs +2 -2
  43. package/src/main/config.cjs +112 -8
  44. package/src/main/docEdit.cjs +6 -1
  45. package/src/main/exchanges.cjs +70 -5
  46. package/src/main/files.cjs +7 -27
  47. package/src/main/health.cjs +48 -15
  48. package/src/main/historyAggregator.cjs +172 -63
  49. package/src/main/historyDashboard.cjs +87 -17
  50. package/src/main/index.cjs +78 -4
  51. package/src/main/ipcSchemas.cjs +233 -20
  52. package/src/main/lib/AGENTS.md +54 -0
  53. package/src/main/lib/CLAUDE.md +1 -54
  54. package/src/main/lib/agent-cli/adapters/codex.cjs +5 -2
  55. package/src/main/lib/agent-cli/agentCliIpc.cjs +18 -2
  56. package/src/main/lib/agent-cli/agentCliSessionStore.cjs +1 -0
  57. package/src/main/lib/agent-cli/agentCliTurn.cjs +20 -2
  58. package/src/main/lib/agent-cli/geminiContextDefaults.cjs +94 -0
  59. package/src/main/lib/claude/effectiveModelInfo.cjs +92 -22
  60. package/src/main/lib/claude/jobSandboxPolicy.cjs +202 -0
  61. package/src/main/lib/claude/modelPricing.cjs +148 -0
  62. package/src/main/lib/claude/personaToolScope.cjs +12 -6
  63. package/src/main/lib/claude/rateLimitDetect.cjs +13 -2
  64. package/src/main/lib/claude/runClaudeP.cjs +6 -1
  65. package/src/main/lib/claude/toolRiskIpc.cjs +177 -0
  66. package/src/main/lib/claude/toolRiskMarks.cjs +373 -0
  67. package/src/main/lib/demo-video-kit/seedKit.cjs +27 -6
  68. package/src/main/lib/ephemeralCwd.cjs +37 -2
  69. package/src/main/lib/epic/delegationReadiness.cjs +42 -9
  70. package/src/main/lib/epic/epicAdminRoutes.cjs +121 -0
  71. package/src/main/lib/epic/epicJobReceipt.cjs +87 -0
  72. package/src/main/lib/epic/epicOutsideRead.cjs +423 -0
  73. package/src/main/lib/epic/epicOutsideState.cjs +233 -0
  74. package/src/main/lib/epic/epicSettle.cjs +1 -1
  75. package/src/main/lib/epic/epicStateWatcher.cjs +157 -0
  76. package/src/main/lib/epic/epicSweepValidator.cjs +7 -2
  77. package/src/main/lib/epic/epicValidationHook.cjs +24 -4
  78. package/src/main/lib/epic/externalRef.cjs +37 -0
  79. package/src/main/lib/epic/externalRefIndex.cjs +136 -0
  80. package/src/main/lib/epic/guardSpawnSettings.cjs +57 -1
  81. package/src/main/lib/epic/restorableSessions.cjs +151 -17
  82. package/src/main/lib/epic/transcriptUsage.cjs +197 -0
  83. package/src/main/lib/externalContract.cjs +137 -0
  84. package/src/main/lib/feedback-remote/crossProjectFeedback.cjs +176 -5
  85. package/src/main/lib/feedback-remote/crossProjectReply.cjs +186 -9
  86. package/src/main/lib/feedback-remote/customerFeedbackAdminRoutes.cjs +16 -6
  87. package/src/main/lib/feedback-remote/customerFeedbackClient.cjs +50 -8
  88. package/src/main/lib/feedback-remote/customerFeedbackInbox.cjs +218 -4
  89. package/src/main/lib/feedback-remote/customerFeedbackIpc.cjs +19 -3
  90. package/src/main/lib/feedback-remote/feedbackImages.cjs +171 -0
  91. package/src/main/lib/feedback-remote/localAdminHttp.cjs +11 -10
  92. package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +167 -21
  93. package/src/main/lib/feedback-remote/needsYouAdminRoutes.cjs +133 -0
  94. package/src/main/lib/feedback-remote/needsYouIpc.cjs +50 -0
  95. package/src/main/lib/feedback-remote/needsYouStore.cjs +285 -0
  96. package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +98 -1
  97. package/src/main/lib/feedback-remote/remoteIpcDispatch.cjs +5 -0
  98. package/src/main/lib/git/branchSweep.cjs +209 -4
  99. package/src/main/lib/git/gitWorktree.cjs +41 -5
  100. package/src/main/lib/guardShims.cjs +1 -1
  101. package/src/main/lib/historyRollup.cjs +58 -5
  102. package/src/main/lib/insideHome.cjs +27 -1
  103. package/src/main/lib/mcpToolCatalog.cjs +232 -25
  104. package/src/main/lib/mdDocCensus.cjs +59 -78
  105. package/src/main/lib/mdDocRefs.cjs +71 -93
  106. package/src/main/lib/mdNetworkScan.cjs +245 -250
  107. package/src/main/lib/mdReviewRecord.cjs +22 -9
  108. package/src/main/lib/memoryMdNetwork.cjs +5 -12
  109. package/src/main/lib/opsOwnership.cjs +18 -2
  110. package/src/main/lib/opsRetentionSettings.cjs +28 -4
  111. package/src/main/lib/persona-macro/agentAdminRoutes.cjs +121 -0
  112. package/src/main/lib/persona-macro/macroJobDispatch.cjs +90 -20
  113. package/src/main/lib/persona-macro/macroJobIpc.cjs +144 -46
  114. package/src/main/lib/persona-macro/macroJobStatus.cjs +87 -9
  115. package/src/main/lib/persona-macro/macroLibrary.cjs +95 -5
  116. package/src/main/lib/persona-macro/personaImportHealth.cjs +78 -17
  117. package/src/main/lib/persona-macro/projectVideoToolCheck.cjs +96 -0
  118. package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +11 -0
  119. package/src/main/lib/prd/depSlugResolve.cjs +104 -4
  120. package/src/main/lib/prd/prdAdminRoutes.cjs +35 -2
  121. package/src/main/lib/prd/prdCreate.cjs +351 -23
  122. package/src/main/lib/prd/prdDisposition.cjs +11 -2
  123. package/src/main/lib/prd/prdFrontmatter.cjs +96 -3
  124. package/src/main/lib/process/loginItem.cjs +171 -0
  125. package/src/main/lib/process/loginItemPlan.cjs +193 -0
  126. package/src/main/lib/project-pages/playerBridge.cjs +4 -0
  127. package/src/main/lib/project-pages/videoReview.cjs +268 -0
  128. package/src/main/lib/project-pages/videoReviewIpc.cjs +229 -0
  129. package/src/main/lib/promptSessionSchema.cjs +4 -0
  130. package/src/main/lib/remoteTranscriptTail.cjs +32 -1
  131. package/src/main/lib/scheduler/cpuSample.cjs +131 -4
  132. package/src/main/lib/scheduler/fixPlanSlug.cjs +4 -3
  133. package/src/main/lib/scheduler/loadGate.cjs +24 -6
  134. package/src/main/lib/scheduler/planRecordHarvest.cjs +108 -0
  135. package/src/main/lib/scheduler/planRecordRetention.cjs +144 -0
  136. package/src/main/lib/scheduler/queueStore.cjs +7 -0
  137. package/src/main/lib/scheduler/rcaReport.cjs +21 -1
  138. package/src/main/lib/scheduler/reaperHelpers.cjs +35 -5
  139. package/src/main/lib/scheduler/runLogRetention.cjs +104 -3
  140. package/src/main/lib/scheduler/scheduleJobSchema.cjs +3 -0
  141. package/src/main/lib/scheduler/schedulerBatch.cjs +25 -48
  142. package/src/main/lib/scheduler/schedulerPaths.cjs +12 -0
  143. package/src/main/lib/scheduler/sessionSlots.cjs +176 -21
  144. package/src/main/lib/scheduler/validationQuality.cjs +282 -0
  145. package/src/main/lib/scheduler/validatorVerdictSchema.cjs +254 -0
  146. package/src/main/lib/tasks/taskAdminRoutes.cjs +641 -0
  147. package/src/main/lib/tasks/taskIpc.cjs +80 -0
  148. package/src/main/lib/tasks/taskLedger.cjs +502 -0
  149. package/src/main/lib/tasks/taskRun.cjs +313 -0
  150. package/src/main/lib/tasks/taskSwitch.cjs +120 -0
  151. package/src/main/lib/telemetry/auditEvents.cjs +176 -0
  152. package/src/main/lib/telemetry/eventsAdminRoutes.cjs +45 -0
  153. package/src/main/loginItemIpc.cjs +35 -0
  154. package/src/main/loopEfficiencyHandlers.cjs +11 -2
  155. package/src/main/projectPages.cjs +6 -15
  156. package/src/main/promptSessionEvents.cjs +9 -1
  157. package/src/main/queueOps.cjs +260 -3
  158. package/src/main/runVerify.cjs +53 -25
  159. package/src/main/scheduler/AGENTS.md +26 -0
  160. package/src/main/scheduler/CLAUDE.md +1 -26
  161. package/src/main/scheduler/budget.cjs +239 -9
  162. package/src/main/scheduler/cancelDependents.cjs +154 -0
  163. package/src/main/scheduler/prdParser.cjs +4 -1
  164. package/src/main/scheduler/starvation.cjs +20 -18
  165. package/src/main/scheduler.cjs +774 -64
  166. package/src/main/supervisor.cjs +5 -1
  167. package/src/main/templates/PRD_AUTHORING.md +7 -1
  168. package/src/main/transcripts.cjs +62 -7
  169. package/src/main/validationQualityHandlers.cjs +199 -0
  170. package/src/main/webRemote.cjs +132 -20
  171. package/src/preload/api.d.ts +434 -28
  172. package/src/preload/apiSurface.cjs +7 -0
  173. package/src/preload/apiSurface.json +485 -81
  174. package/src/preload/index.cjs +38 -5
  175. package/src/seed/agents/validator.md +19 -8
  176. package/dist/assets/AgentLibrary-C1d_D7uQ.js +0 -2
  177. package/dist/assets/AppSettings-CgDhqrsU.js +0 -2
  178. package/dist/assets/Button-Bk23rEnZ.js +0 -1
  179. package/dist/assets/DocumentEditorPane-BqY5Nq6W.js +0 -1
  180. package/dist/assets/Extensions-CXem-uwI.js +0 -2
  181. package/dist/assets/History-BwO3coo4.js +0 -2
  182. package/dist/assets/Library-BDV69fSe.js +0 -32
  183. package/dist/assets/ListDetail-CD-Fm6mh.js +0 -1
  184. package/dist/assets/ProjectClaudeConfig-NjdKdwe8.js +0 -25
  185. package/dist/assets/ProvenanceBadge-Bu8NmI_R.js +0 -1
  186. package/dist/assets/Scheduler-CkhTvG7C.js +0 -16
  187. package/dist/assets/Settings-COT34hBF.js +0 -2
  188. package/dist/assets/Skills-BgexoUkQ.js +0 -29
  189. package/dist/assets/SourceChip-BXjcdeb1.js +0 -1
  190. package/dist/assets/SystemPrompt-CeeH3EeW.js +0 -1
  191. package/dist/assets/Toggle-CENi19iK.js +0 -1
  192. package/dist/assets/ViewTabs-DDBb0x96.js +0 -1
  193. package/dist/assets/claude-settings-schema-COigsajx.js +0 -3
  194. package/dist/assets/index-CgCxpunJ.js +0 -3116
@@ -15,8 +15,16 @@
15
15
  * - parseGitLog(stdout) — `git log --max-count=2000 --no-renames
16
16
  * --format=%x01%ct --name-only -z` stdout -> newest-first { ms, files }.
17
17
  * - importsOf(text, fromPath) — the path.md imports (at-sign prefixed) a doc makes.
18
+ * - recordCollectionDocs(census) — every doc inside a record collection, linked
19
+ * or not, except the root and README/CLAUDE/AGENTS/index docs.
18
20
  *
19
- * Roles, by precedence: map (the root + its transitive imports, depth <= 5)
21
+ * - rootMapDoc(has) — the root map doc: AGENTS.md when `has('AGENTS.md')`, else
22
+ * CLAUDE.md. Beside a root AGENTS.md, a root CLAUDE.md (the stub that imports
23
+ * it) is part of the map too.
24
+ *
25
+ * Roles, by precedence: map (the root map doc — root AGENTS.md, else root
26
+ * CLAUDE.md — plus a root CLAUDE.md beside an AGENTS.md root, and their
27
+ * transitive imports, depth <= 5)
20
28
  * > scoped (any other CLAUDE.md / AGENTS.md / CLAUDE.local.md) > agent
21
29
  * (.claude/, skills/<x>/, plugins/<x>/agents|commands/) > record (in a record
22
30
  * collection, unreachable, not a README/CLAUDE/AGENTS/index) > doc.
@@ -24,9 +32,11 @@
24
32
  * Never throws on malformed input: invalid entries are skipped.
25
33
  */
26
34
 
27
- const path = require('node:path');
35
+ // importsOf is the shared link convention's; re-exported so consumers keep requiring it from here.
36
+ const { importsOf } = require('../../../plugins/session-manager-dev/skills/maintaining-md-network/scripts/mdLinks.cjs');
28
37
 
29
- const ROOT_DOC = 'CLAUDE.md';
38
+ const AGENTS_DOC = 'AGENTS.md';
39
+ const CLAUDE_DOC = 'CLAUDE.md';
30
40
  const MAX_IMPORT_DEPTH = 5;
31
41
  const COLLECTION_MIN_DOCS = 20;
32
42
  const COLLECTION_MAX_LINKED_SHARE = 0.05;
@@ -36,34 +46,45 @@ const MAX_CODE_REF_FILES = 10;
36
46
  const MAX_DEAD_REFS = 10;
37
47
  const MAX_CHANGED_SINCE = 20;
38
48
 
39
- const MD_RE = /\.md$/i;
40
- const FENCE_RE = /^\s*(`{3,}|~{3,})(.*)$/;
41
- const INLINE_CODE_RE = /(`+).{0,1024}?\1/g;
42
- const IMPORT_RE = /(^|\s)@(\S+)/g;
43
- const TRAILING_PUNCT_RE = /[),.;:!?'"\]]+$/;
44
49
  const AGENT_RE = /(^|\/)\.claude\/|(^|\/)skills\/[^/]+\/|(^|\/)plugins\/[^/]+\/(agents|commands)\//;
45
50
  const SCOPED_NAMES = new Set(['CLAUDE.md', 'AGENTS.md', 'CLAUDE.local.md']);
46
51
  const NEVER_RECORD_NAMES = new Set(['README.md', 'CLAUDE.md', 'AGENTS.md', 'index.md']);
47
52
 
53
+ /**
54
+ * The root map doc: root AGENTS.md when it exists, else root CLAUDE.md.
55
+ * @param {(relPath: string) => boolean} has whether a repo-relative doc exists
56
+ * @returns {string}
57
+ */
58
+ function rootMapDoc(has) {
59
+ return has(AGENTS_DOC) ? AGENTS_DOC : CLAUDE_DOC;
60
+ }
61
+
62
+ /**
63
+ * The root docs of the map: `root`, plus a root CLAUDE.md beside an AGENTS.md root.
64
+ * @param {string} root @param {(relPath: string) => boolean} has @returns {string[]}
65
+ */
66
+ function mapRoots(root, has) {
67
+ if (!has(root)) return [];
68
+ return root === AGENTS_DOC && has(CLAUDE_DOC) ? [root, CLAUDE_DOC] : [root];
69
+ }
70
+
48
71
  /**
49
72
  * @typedef {'map' | 'scoped' | 'agent' | 'record' | 'doc'} MdDocRole
50
73
  * @typedef {{ path: string, ms: number }} MdChangedSince
51
- * @typedef {{ path: string, role: MdDocRole, depth: number | null, lines: number | null, bytes: number | null, lastCommitMs: number | null, commits: number, linkedFrom: number, codeRefs: number, codeRefFiles: string[], deadRefs: string[], changedSince: MdChangedSince[], collection: string | null }} MdDoc
52
- * @typedef {{ folder: string, docs: number, linked: number, lastCommitMs: number | null, source: 'heuristic' | 'override' }} MdRecordCollection
74
+ * @typedef {{ path: string, role: MdDocRole, depth: number | null, lines: number | null, bytes: number | null, lastCommitMs: number | null, commits: number, linkedFrom: number, codeRefs: number, codeRefFiles: string[], deadRefs: string[], ambiguousRefs: string[], changedSince: MdChangedSince[], collection: string | null }} MdDoc
75
+ * @typedef {{ folder: string, docs: number, linked: number, lastCommitMs: number | null, source: 'heuristic' }} MdRecordCollection
53
76
  * @typedef {{ tracked: number, network: number, records: number, unlinked: number, byRole: Record<MdDocRole, number> }} MdCensusCounts
54
77
  * @typedef {{ docs: MdDoc[], collections: MdRecordCollection[], counts: MdCensusCounts, gitWindow: { commits: number, oldestMs: number | null }, warnings: string[] }} MdCensus
55
78
  * @typedef {{ path: string, text?: string | null, lines?: number | null, bytes?: number | null }} MdCensusDocInput
56
79
  * @typedef {{ ms: number, files: string[] }} GitLogEntry
57
- * @typedef {{ deadRefs: string[], changedSince: MdChangedSince[] }} MdDocRefs
80
+ * @typedef {{ deadRefs: string[], ambiguousRefs: string[], changedSince: MdChangedSince[] }} MdDocRefs
58
81
  * @typedef {object} CensusInput
59
- * @property {string} [root] the root doc (default CLAUDE.md)
82
+ * @property {string} [root] the root map doc (default: rootMapDoc over `docs`)
60
83
  * @property {MdCensusDocInput[]} docs every tracked .md, repo-relative POSIX
61
84
  * @property {Map<string, { depth: number, linkedFrom: number }>} reachable docs links reach from the root
62
85
  * @property {GitLogEntry[]} [log] newest first
63
86
  * @property {Map<string, MdDocRefs>} [refs]
64
87
  * @property {Map<string, string[]>} [codeMentions] doc path -> code files naming it
65
- * @property {string[]} [recordFolders] folders forced to be record collections
66
- * @property {string[]} [docFolders] folders (and subfolders) never record collections
67
88
  */
68
89
 
69
90
  /** @param {unknown} v @returns {v is number} */
@@ -81,14 +102,6 @@ function baseName(p) {
81
102
  return p.slice(p.lastIndexOf('/') + 1);
82
103
  }
83
104
 
84
- /** Folder form with a trailing slash, or '' for the repo root / invalid. @param {unknown} f @returns {string} */
85
- function toFolder(f) {
86
- if (typeof f !== 'string') return '';
87
- const norm = path.posix.normalize(f.trim()).replace(/^\.\/+/, '').replace(/\/+$/, '');
88
- if (!norm || norm === '.' || norm.startsWith('../') || norm === '..' || norm.startsWith('/')) return '';
89
- return `${norm}/`;
90
- }
91
-
92
105
  /** Every ancestor folder of `p`, shallowest first, each with a trailing slash. @param {string} p @returns {string[]} */
93
106
  function foldersOf(p) {
94
107
  /** @type {string[]} */
@@ -97,42 +110,6 @@ function foldersOf(p) {
97
110
  return out;
98
111
  }
99
112
 
100
- /**
101
- * The `@path.md` imports in `text`, outside fenced and inline code, resolved
102
- * against `fromPath`'s folder. Skips `@~/...`, absolute and escaping targets.
103
- * @param {string} text @param {string} fromPath @returns {string[]}
104
- */
105
- function importsOf(text, fromPath) {
106
- if (typeof text !== 'string' || typeof fromPath !== 'string') return [];
107
- const dir = path.posix.dirname(fromPath);
108
- /** @type {string[]} */
109
- const out = [];
110
- const seen = new Set();
111
- let fence = '';
112
- for (const line of text.split(/\r?\n/)) {
113
- const f = FENCE_RE.exec(line);
114
- if (fence) {
115
- if (f && f[1][0] === fence[0] && f[1].length >= fence.length && f[2].trim() === '') fence = '';
116
- continue;
117
- }
118
- if (f && !(f[1][0] === '`' && f[2].includes('`'))) {
119
- fence = f[1];
120
- continue;
121
- }
122
- const visible = line.replace(INLINE_CODE_RE, ' ');
123
- for (const m of visible.matchAll(IMPORT_RE)) {
124
- const target = m[2].replace(TRAILING_PUNCT_RE, '');
125
- if (!MD_RE.test(target) || target.startsWith('~') || target.startsWith('/')) continue;
126
- const resolved = path.posix.normalize(path.posix.join(dir, target));
127
- if (resolved === '..' || resolved.startsWith('../') || resolved.startsWith('/')) continue;
128
- if (seen.has(resolved)) continue;
129
- seen.add(resolved);
130
- out.push(resolved);
131
- }
132
- }
133
- return out;
134
- }
135
-
136
113
  /**
137
114
  * Parse `git log --max-count=2000 --no-renames --format=%x01%ct --name-only -z`.
138
115
  * @param {string} stdout @returns {GitLogEntry[]} newest first; [] when empty or unparseable
@@ -181,14 +158,12 @@ function changedSinceList(list) {
181
158
  */
182
159
  function censusMdDocs(input) {
183
160
  const {
184
- root = ROOT_DOC,
161
+ root: rootInput,
185
162
  docs = [],
186
163
  reachable = new Map(),
187
164
  log = [],
188
165
  refs,
189
166
  codeMentions,
190
- recordFolders = [],
191
- docFolders = [],
192
167
  } = input || /** @type {CensusInput} */ ({ docs: [], reachable: new Map() });
193
168
  /** @type {string[]} */
194
169
  const warnings = [];
@@ -236,10 +211,14 @@ function censusMdDocs(input) {
236
211
  // Map: root + transitive @-imports.
237
212
  /** @type {Map<string, string | null | undefined>} */
238
213
  const textOf = new Map(list.map((d) => [d.path, d.text]));
214
+ /** @param {string} p */
215
+ const hasDoc = (p) => textOf.has(p);
216
+ const root = rootInput === undefined ? rootMapDoc(hasDoc) : rootInput;
239
217
  const mapSet = new Set();
240
- if (typeof root === 'string' && textOf.has(root)) {
241
- mapSet.add(root);
242
- let frontier = [root];
218
+ const roots = typeof root === 'string' ? mapRoots(root, hasDoc) : [];
219
+ if (roots.length > 0) {
220
+ for (const r of roots) mapSet.add(r);
221
+ let frontier = roots;
243
222
  for (let depth = 1; depth <= MAX_IMPORT_DEPTH && frontier.length > 0; depth += 1) {
244
223
  /** @type {string[]} */
245
224
  const next = [];
@@ -259,9 +238,6 @@ function censusMdDocs(input) {
259
238
  const isReachable = (p) => reach.has(p) || mapSet.has(p);
260
239
 
261
240
  // Record collections.
262
- const blocked = (Array.isArray(docFolders) ? docFolders : []).map(toFolder).filter(Boolean);
263
- /** @param {string} folder */
264
- const isBlocked = (folder) => blocked.some((b) => folder.startsWith(b));
265
241
  /** @type {Map<string, { docs: number, linked: number, withCommits: number, writeOnce: number, last: number | null }>} */
266
242
  const stats = new Map();
267
243
  for (const d of list) {
@@ -285,18 +261,9 @@ function censusMdDocs(input) {
285
261
  const collections = [];
286
262
  /** @param {string} folder */
287
263
  const insideChosen = (folder) => collections.some((c) => folder.startsWith(c.folder));
288
- const overrides = [...new Set((Array.isArray(recordFolders) ? recordFolders : []).map(toFolder).filter(Boolean))].sort(
289
- (a, b) => a.length - b.length,
290
- );
291
- for (const folder of overrides) {
292
- if (insideChosen(folder)) continue;
293
- const s = stats.get(folder);
294
- if (!s) warnings.push(`Record folder override matches no doc: ${folder}`);
295
- collections.push({ folder, docs: s ? s.docs : 0, linked: s ? s.linked : 0, lastCommitMs: s ? s.last : null, source: 'override' });
296
- }
297
264
  const candidates = [...stats.keys()].sort((a, b) => a.split('/').length - b.split('/').length || (a < b ? -1 : a > b ? 1 : 0));
298
265
  for (const folder of candidates) {
299
- if (isBlocked(folder) || insideChosen(folder) || overrides.some((o) => o.startsWith(folder))) continue;
266
+ if (insideChosen(folder)) continue;
300
267
  const s = /** @type {NonNullable<ReturnType<typeof stats.get>>} */ (stats.get(folder));
301
268
  if (s.docs < COLLECTION_MIN_DOCS || s.linked > s.docs * COLLECTION_MAX_LINKED_SHARE) continue;
302
269
  if (s.withCommits > 0 && s.writeOnce < s.withCommits * WRITE_ONCE_MIN_SHARE) continue;
@@ -347,6 +314,7 @@ function censusMdDocs(input) {
347
314
  codeRefs: mentions.length,
348
315
  codeRefFiles: mentions.slice(0, MAX_CODE_REF_FILES),
349
316
  deadRefs: ref ? stringList(ref.deadRefs, MAX_DEAD_REFS) : [],
317
+ ambiguousRefs: ref ? stringList(ref.ambiguousRefs, MAX_DEAD_REFS) : [],
350
318
  changedSince: ref ? changedSinceList(ref.changedSince) : [],
351
319
  collection: role === 'record' ? folder : null,
352
320
  });
@@ -361,4 +329,17 @@ function censusMdDocs(input) {
361
329
  };
362
330
  }
363
331
 
364
- module.exports = { censusMdDocs, parseGitLog, importsOf };
332
+ /**
333
+ * Every doc inside one of `census`'s record collections: the role-`record`
334
+ * docs plus linked docs in a collection folder. README/CLAUDE/AGENTS/index docs
335
+ * and map docs are never records. The network scan never walks these.
336
+ * @param {MdCensus} census @returns {string[]}
337
+ */
338
+ function recordCollectionDocs(census) {
339
+ const folders = census.collections.map((c) => c.folder);
340
+ return census.docs
341
+ .filter((d) => d.role === 'record' || (d.role === 'doc' && !NEVER_RECORD_NAMES.has(baseName(d.path)) && folders.some((f) => d.path.startsWith(f))))
342
+ .map((d) => d.path);
343
+ }
344
+
345
+ module.exports = { censusMdDocs, parseGitLog, importsOf, recordCollectionDocs, rootMapDoc, mapRoots };
@@ -4,29 +4,26 @@
4
4
  /**
5
5
  * mdDocRefs — pure helpers for a markdown doc's currency and usage:
6
6
  * - backtickPaths: the repo-path-shaped inline-code tokens a doc names;
7
- * - assessRefs: which named paths no longer exist, and which existing files
8
- * were committed after the doc last changed;
7
+ * - assessRefs: which named paths no longer exist (dead), which name 2+
8
+ * tracked paths by suffix (ambiguous), and which existing files were
9
+ * committed after the doc last changed;
10
+ * - suffixIndex: a resolver from a shorthand token (`lib/x.ts`) to the
11
+ * tracked paths it names (`src/renderer/lib/x.ts`), built once per scan;
9
12
  * - mentionPatterns / parseMentions: the fixed-string patterns for a
10
13
  * `git grep -F -o --null` run and the parse of its output into
11
14
  * doc -> code files that name it.
12
- * No fs, no git: all IO is injected (`exists`, `lastCommitOf`) or done by the
13
- * caller (scanMdNetwork). Fence/comment handling mirrors mdNetworkScan.cjs.
15
+ * No fs, no git: all IO is injected (`exists`, `lastCommitOf`, `ignored`) or done by the
16
+ * caller (scanMdNetwork). backtickPaths (fence/comment handling included) is
17
+ * the shared link convention's, from the skill's mdLinks.cjs; re-exported here.
14
18
  */
15
19
 
16
20
  const path = require('node:path');
21
+ const { backtickPaths } = require('../../../plugins/session-manager-dev/skills/maintaining-md-network/scripts/mdLinks.cjs');
17
22
 
18
- const MAX_TOKENS = 200;
19
23
  const MAX_CHANGED = 20;
20
24
  const MAX_PATTERNS = 4000;
21
25
 
22
- const FENCE_RE = /^\s*(`{3,}|~{3,})(.*)$/;
23
- const INLINE_CODE_RE = /(`+)(.{0,1024}?)\1/g;
24
- const BAD_START_RE = /^(?:[/~$<]|http)/i;
25
- const BAD_CHAR_RE = /[*{}<>:]/;
26
- const EXT_RE = /\.[A-Za-z0-9]{1,8}$/;
27
-
28
26
  /**
29
- * @typedef {{ fence: string, inComment: boolean }} LineState
30
27
  * @typedef {{ path: string, ms: number }} ChangedRef
31
28
  * @typedef {{
32
29
  * docPath: string,
@@ -35,83 +32,11 @@ const EXT_RE = /\.[A-Za-z0-9]{1,8}$/;
35
32
  * docMs: number | null,
36
33
  * exists: (repoPath: string) => boolean,
37
34
  * lastCommitOf: (repoPath: string) => number | null | undefined,
35
+ * ignored?: (repoPath: string) => boolean,
36
+ * suffixMatches?: (token: string) => string[],
38
37
  * }} AssessInput
39
38
  */
40
39
 
41
- /** Drops HTML comments (which may span lines) from one line. @param {string} line @param {LineState} state */
42
- function stripComments(line, state) {
43
- let out = '';
44
- let i = 0;
45
- while (i < line.length) {
46
- if (state.inComment) {
47
- const close = line.indexOf('-->', i);
48
- if (close === -1) return out;
49
- state.inComment = false;
50
- i = close + 3;
51
- } else {
52
- const open = line.indexOf('<!--', i);
53
- if (open === -1) return out + line.slice(i);
54
- out += `${line.slice(i, open)} `;
55
- state.inComment = true;
56
- i = open + 4;
57
- }
58
- }
59
- return out;
60
- }
61
-
62
- /** One line outside fences, comments removed (inline code kept). @param {string} line @param {LineState} state */
63
- function visibleLine(line, state) {
64
- const fence = state.inComment ? null : FENCE_RE.exec(line);
65
- if (state.fence) {
66
- if (fence && fence[1][0] === state.fence[0] && fence[1].length >= state.fence.length && fence[2].trim() === '') {
67
- state.fence = '';
68
- }
69
- return '';
70
- }
71
- if (fence && !(fence[1][0] === '`' && fence[2].includes('`'))) {
72
- state.fence = fence[1];
73
- return '';
74
- }
75
- return stripComments(line, state);
76
- }
77
-
78
- /** The repo-path form of one inline-code token, or null. @param {string} raw @returns {string | null} */
79
- function pathToken(raw) {
80
- const t = raw.trim();
81
- if (t === '' || !t.includes('/') || /\s/.test(t) || BAD_START_RE.test(t)) return null;
82
- const bare = t.replace(/:\d+$/, '').replace(/#.*$/, '');
83
- if (bare === '' || BAD_CHAR_RE.test(bare)) return null;
84
- if (!bare.endsWith('/') && !EXT_RE.test(bare)) return null;
85
- return bare;
86
- }
87
-
88
- /**
89
- * Distinct path-shaped inline-code tokens outside fenced code and HTML comments,
90
- * in document order, at most MAX_TOKENS. O(text length).
91
- * @param {string} text
92
- * @returns {string[]}
93
- */
94
- function backtickPaths(text) {
95
- if (typeof text !== 'string' || text === '') return [];
96
- /** @type {LineState} */
97
- const state = { fence: '', inComment: false };
98
- const seen = new Set();
99
- /** @type {string[]} */
100
- const out = [];
101
- for (const line of text.split(/\r?\n/)) {
102
- const visible = visibleLine(line, state);
103
- if (visible === '' || !visible.includes('`')) continue;
104
- for (const m of visible.matchAll(INLINE_CODE_RE)) {
105
- const tok = pathToken(m[2]);
106
- if (tok === null || seen.has(tok)) continue;
107
- seen.add(tok);
108
- out.push(tok);
109
- if (out.length >= MAX_TOKENS) return out;
110
- }
111
- }
112
- return out;
113
- }
114
-
115
40
  /** Normalised repo path, or null when it escapes the repo. @param {string} p @returns {string | null} */
116
41
  function repoPath(p) {
117
42
  const n = path.posix.normalize(p).replace(/\/+$/, '');
@@ -120,17 +45,48 @@ function repoPath(p) {
120
45
  }
121
46
 
122
47
  /**
123
- * Dead refs (tokens that resolve nowhere) and existing file refs committed
124
- * after the doc (newest first, at most MAX_CHANGED).
48
+ * Resolver from a token to every tracked path equal to it or ending with
49
+ * '/<token>' (whole segments only), in listing order. One Map by basename.
50
+ * @param {string[]} paths tracked files and folders, repo-relative POSIX
51
+ * @returns {(token: string) => string[]}
52
+ */
53
+ function suffixIndex(paths) {
54
+ /** @type {Map<string, string[]>} */
55
+ const byBase = new Map();
56
+ for (const p of Array.isArray(paths) ? paths : []) {
57
+ if (typeof p !== 'string' || p === '') continue;
58
+ const base = path.posix.basename(p);
59
+ const list = byBase.get(base);
60
+ if (list) list.push(p);
61
+ else byBase.set(base, [p]);
62
+ }
63
+ return (token) => {
64
+ const t = typeof token === 'string' ? repoPath(token) : null;
65
+ if (t === null) return [];
66
+ const list = byBase.get(path.posix.basename(t)) ?? [];
67
+ return [...new Set(list.filter((p) => p === t || p.endsWith(`/${t}`)))];
68
+ };
69
+ }
70
+
71
+ /**
72
+ * Dead refs (tokens that resolve nowhere: not present, not gitignored, naming
73
+ * no tracked path by suffix), ambiguous refs (a suffix naming 2+ tracked
74
+ * paths), and existing file refs committed after the doc (newest first, at
75
+ * most MAX_CHANGED). A unique suffix match counts as that file. A bare
76
+ * token (no '/', no extension; one trailing '/' allowed) resolves only as an
77
+ * exact top-level path and is otherwise ignored.
125
78
  * @param {AssessInput} input
126
- * @returns {{ deadRefs: string[], changedSince: ChangedRef[] }}
79
+ * @returns {{ deadRefs: string[], ambiguousRefs: string[], changedSince: ChangedRef[] }}
127
80
  */
128
- function assessRefs({ docPath, linkTargets, tokens, docMs, exists, lastCommitOf }) {
81
+ function assessRefs({ docPath, linkTargets, tokens, docMs, exists, lastCommitOf, ignored, suffixMatches }) {
129
82
  const dir = path.posix.dirname(docPath);
130
83
  /** @type {string[]} */
131
84
  const deadRefs = [];
132
85
  const deadSeen = new Set();
133
86
  /** @type {string[]} */
87
+ const ambiguousRefs = [];
88
+ const ambiguousSeen = new Set();
89
+ /** @type {string[]} */
134
90
  const fileRefs = [];
135
91
  const fileSeen = new Set();
136
92
  /** @param {string} p */
@@ -145,12 +101,34 @@ function assessRefs({ docPath, linkTargets, tokens, docMs, exists, lastCommitOf
145
101
  }
146
102
  for (const tok of Array.isArray(tokens) ? tokens : []) {
147
103
  if (typeof tok !== 'string' || tok === '') continue;
104
+ // A token whose only '/' is one trailing slash (`tasks/`) is the bare name.
105
+ const bare = /^[^/]+\/$/.test(tok) ? tok.slice(0, -1) : tok;
106
+ if (!bare.includes('/') && path.posix.extname(bare) === '') {
107
+ // A bare name (`tasks`, `scripts`) is a name unless it is exactly a
108
+ // top-level tracked file or folder: no suffix match, no doc-folder join,
109
+ // never ambiguous, never dead.
110
+ const top = repoPath(bare);
111
+ if (top !== null && exists(top)) addFile(top);
112
+ continue;
113
+ }
148
114
  const isFolder = tok.endsWith('/');
149
115
  const root = repoPath(tok);
150
116
  const local = dir === '.' ? null : repoPath(path.posix.join(dir, tok));
151
117
  const candidates = [root, local].filter((c) => c !== null);
152
118
  if (candidates.length === 0) continue;
153
- const hit = candidates.find((c) => exists(c));
119
+ let hit = candidates.find((c) => exists(c));
120
+ if (hit === undefined && typeof ignored === 'function' && candidates.some((c) => ignored(c))) continue;
121
+ if (hit === undefined && root !== null && typeof suffixMatches === 'function') {
122
+ const matches = suffixMatches(root);
123
+ if (matches.length === 1) hit = matches[0];
124
+ else if (matches.length >= 2) {
125
+ if (!ambiguousSeen.has(root)) {
126
+ ambiguousSeen.add(root);
127
+ ambiguousRefs.push(root);
128
+ }
129
+ continue;
130
+ }
131
+ }
154
132
  if (hit === undefined) {
155
133
  const dead = /** @type {string} */ (root ?? candidates[0]);
156
134
  if (!deadSeen.has(dead)) {
@@ -169,7 +147,7 @@ function assessRefs({ docPath, linkTargets, tokens, docMs, exists, lastCommitOf
169
147
  if (docMs === null || docMs === undefined || ms > docMs) changed.push({ path: p, ms });
170
148
  }
171
149
  changed.sort((a, b) => b.ms - a.ms || (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
172
- return { deadRefs, changedSince: changed.slice(0, MAX_CHANGED) };
150
+ return { deadRefs, ambiguousRefs, changedSince: changed.slice(0, MAX_CHANGED) };
173
151
  }
174
152
 
175
153
  /**
@@ -246,4 +224,4 @@ function parseMentions(stdout, owner) {
246
224
  return out;
247
225
  }
248
226
 
249
- module.exports = { backtickPaths, assessRefs, mentionPatterns, parseMentions };
227
+ module.exports = { backtickPaths, assessRefs, suffixIndex, mentionPatterns, parseMentions };