create-pmos 0.594.0 → 0.596.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.
@@ -5734,6 +5734,22 @@ function dayMarkIds(brief, run) {
5734
5734
  for (const e of brief.calendar || []) known.set(e.id, 'event');
5735
5735
  return known;
5736
5736
  }
5737
+ const CONN_SEEN = () => path.join(STATE, 'connectors-seen.json');
5738
+ let connProbeAt = 0, connProbed = [], connSigMemo = null;
5739
+ /** The services the initiative records of every registered repository link, read at most every 10 minutes (✦ For you). */
5740
+ function connSignals(now = Date.now()) {
5741
+ if (connSigMemo && now - connSigMemo.at < 600000) return connSigMemo.list;
5742
+ const texts = [];
5743
+ for (const w of workspaces.values()) {
5744
+ if (!w || !w.root || texts.length >= 400) continue;
5745
+ const dir = path.join(w.root, 'planning', 'initiatives');
5746
+ let names = []; try { names = fs.readdirSync(dir).filter((f) => f.endsWith('.md')).slice(0, 400 - texts.length); } catch { continue; }
5747
+ for (const f of names) { try { texts.push(fs.readFileSync(path.join(dir, f), 'utf8').slice(0, 65536)); } catch { /* skip */ } }
5748
+ }
5749
+ const list = require('./lib/connector-directory.js').signalsOf(texts);
5750
+ connSigMemo = { at: now, list };
5751
+ return list;
5752
+ }
5737
5753
  // ── Background prepare, slice D3 (initiative proactive-engine) ──────────────────────────────────────────────────
5738
5754
  // The PM approves ONE plan hash from Today. The 60-second tick later starts that session through the SAME path a next-step
5739
5755
  // `go` uses (startWork with origin next-step and the prompt that was shown), only while background prepare is on, outside quiet
@@ -10099,6 +10115,42 @@ async function handleRequest(req, res) {
10099
10115
  if (!w) return json(res, { ok: false, error: 'no workspace' }, 400);
10100
10116
  return json(res, { ok: true, ws: w.id, name: w.name, ...validateLib.readFindings(validationFindingsFile(w)) });
10101
10117
  }
10118
+ /* ── Settings › Connectors as a directory (initiative connectors-directory; canvas CnA, CnB) ──
10119
+ * GET /api/connectors/directory[?probe=1]: the connectors the Claude session has, the new ones ✦ proposes what to read from, and the
10120
+ * services the initiative records link (for ✦ For you). probe=1 (the page sends it while it waits after a +) also asks `claude mcp
10121
+ * list` of the verified login, at most every 20 s, because a connector added in the Claude account reaches the config file only when
10122
+ * a session starts. POST /api/connectors/decide { name, verdict: approve|dismiss } takes a proposal away; the page saves the
10123
+ * proposal's switch with POST /api/proactive/settings first, so nothing reads a new connector before ✓. PMOS stores no key or token. */
10124
+ if (p === '/api/connectors/directory' && req.method === 'GET') {
10125
+ const CD = require('./lib/connector-directory.js');
10126
+ const sc = sessionConnectors(); const list = sc.list.slice(); let probed = false;
10127
+ if (url.searchParams.get('probe') === '1' && Date.now() - connProbeAt > 20000) {
10128
+ connProbeAt = Date.now();
10129
+ try {
10130
+ const b = claudeSetup.bound(defaultProfileFor('claude') || undefined);
10131
+ if (b) {
10132
+ const r = await require('./lib/project-onboard.js').discover({ bound: b });
10133
+ if (r.ok) { probed = true; for (const n of CD.probeNames(r.sources)) if (!list.some((c) => c.name === n)) list.push({ name: n, label: proactiveLib.connectorLabel(n) || n, source: proactiveLib.connectorSource(n), probed: true }); }
10134
+ }
10135
+ } catch { /* the config read stands */ }
10136
+ connProbed = list.filter((c) => c.probed);
10137
+ } else for (const c of connProbed) if (!list.some((x) => x.name === c.name)) list.push(c);
10138
+ let prev = null; try { prev = JSON.parse(fs.readFileSync(CONN_SEEN(), 'utf8')); } catch { /* the first read */ }
10139
+ const n = CD.notice(prev, list.map((c) => c.name));
10140
+ if (JSON.stringify(n.state) !== JSON.stringify(prev)) { try { fs.mkdirSync(STATE, { recursive: true }); fs.writeFileSync(CONN_SEEN(), JSON.stringify(n.state) + '\n'); } catch (e) { warnWriteFail('connectors-seen.json', e); } }
10141
+ return json(res, { ok: true, connectUrl: CD.CONNECT_URL, connected: list, probed,
10142
+ proposals: n.state.pending.map((x) => CD.proposalFor(x.name, proactiveLib.connectorSource(x.name))), signals: connSignals() });
10143
+ }
10144
+ if (p === '/api/connectors/decide' && req.method === 'POST') {
10145
+ let body = {}; try { body = JSON.parse((await readBody(req)) || '{}'); } catch { return json(res, { ok: false, error: 'invalid JSON body' }, 400); }
10146
+ const g = pmGuard.requirePagePress(req, body); if (!g.ok) return json(res, { ok: false, error: g.error }, g.status);
10147
+ const CD = require('./lib/connector-directory.js');
10148
+ let prev = null; try { prev = JSON.parse(fs.readFileSync(CONN_SEEN(), 'utf8')); } catch { /* none */ }
10149
+ const d = CD.decide(prev, String(body.name || ''), body.verdict);
10150
+ if (!d.found) return json(res, { ok: false, error: 'no proposal for that connector' }, 404);
10151
+ try { fs.writeFileSync(CONN_SEEN(), JSON.stringify(d.state) + '\n'); } catch (e) { warnWriteFail('connectors-seen.json', e); return json(res, { ok: false, error: 'could not save — nothing changed' }, 500); }
10152
+ return json(res, { ok: true });
10153
+ }
10102
10154
  /* ── today-goals (G1, G4, G5): the PM's goals for the day, the plan that joins them to the brief and Today, and "plan my
10103
10155
  * day". The goals routes write only goals/<date>.json in the state folder. "Plan my day" seeds the morning-brief
10104
10156
  * schedule when the repository has none and runs it through fireSchedule, the run-now path. Nothing else starts. ── */
@@ -0,0 +1,9 @@
1
+ {
2
+ "_comment": "Initiative connectors-directory (feedback batch 31 item 3a; canvas CnA, CnB): Settings › Connectors as a directory. connectors-directory.test.js is pure: pm/cozy-conndir.js and lib/connector-directory.js.",
3
+ "modules": [
4
+ "connectors-directory.test.js"
5
+ ],
6
+ "seconds": {
7
+ "connectors-directory.test.js": 1
8
+ }
9
+ }