borgmcp 0.9.55 → 0.9.57
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/dist/assimilate-cmd.d.ts +2 -5
- package/dist/assimilate-cmd.d.ts.map +1 -1
- package/dist/assimilate-cmd.js +12 -0
- package/dist/assimilate-cmd.js.map +1 -1
- package/dist/assimilate-deps.d.ts.map +1 -1
- package/dist/assimilate-deps.js +2 -9
- package/dist/assimilate-deps.js.map +1 -1
- package/dist/claude.js +28 -6
- package/dist/claude.js.map +1 -1
- package/dist/cli-help.d.ts +16 -0
- package/dist/cli-help.d.ts.map +1 -0
- package/dist/cli-help.js +24 -0
- package/dist/cli-help.js.map +1 -0
- package/dist/codex-remote.d.ts +60 -12
- package/dist/codex-remote.d.ts.map +1 -1
- package/dist/codex-remote.js +173 -80
- package/dist/codex-remote.js.map +1 -1
- package/dist/inbox-monitor.d.ts.map +1 -1
- package/dist/inbox-monitor.js +15 -0
- package/dist/inbox-monitor.js.map +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/regen-format.d.ts +19 -0
- package/dist/regen-format.d.ts.map +1 -1
- package/dist/regen-format.js +55 -1
- package/dist/regen-format.js.map +1 -1
- package/dist/role-section.d.ts +110 -0
- package/dist/role-section.d.ts.map +1 -0
- package/dist/role-section.js +207 -0
- package/dist/role-section.js.map +1 -0
- package/dist/setup.js +15 -6
- package/dist/setup.js.map +1 -1
- package/dist/subscription-retry.d.ts +40 -0
- package/dist/subscription-retry.d.ts.map +1 -0
- package/dist/subscription-retry.js +23 -0
- package/dist/subscription-retry.js.map +1 -0
- package/dist/templates.d.ts +1 -0
- package/dist/templates.d.ts.map +1 -1
- package/dist/templates.js +76 -14
- package/dist/templates.js.map +1 -1
- package/package.json +1 -1
package/dist/regen-format.d.ts
CHANGED
|
@@ -58,6 +58,25 @@ export declare function parseRationalePointer(stub: string): {
|
|
|
58
58
|
role: string;
|
|
59
59
|
section: string;
|
|
60
60
|
} | null;
|
|
61
|
+
/**
|
|
62
|
+
* gh#496-A(b) — compress a role's `detailed_description` for rendering.
|
|
63
|
+
*
|
|
64
|
+
* Splits the role text into sections (via the client port of the worker's
|
|
65
|
+
* `parseRoleSections`, parity-guarded) and replaces each `… rationale:`
|
|
66
|
+
* plain-label section's BODY with a one-line on-demand stub
|
|
67
|
+
* (`formatRationalePointer(role, heading)` verbatim — heading sans colon).
|
|
68
|
+
* Every other section — preamble, operational-rule sections, and ALL woven
|
|
69
|
+
* safety-discipline text — is emitted INLINE, fetch-free. No content is lost:
|
|
70
|
+
* `getRoleRationale(role, heading)` serves the full section on demand, so
|
|
71
|
+
* core-inline + Σ(every stub resolved) reconstructs the stored text.
|
|
72
|
+
*
|
|
73
|
+
* ⛔ SAFETY-NEVER-COMPRESS: a section is stubbed ONLY when (a) its heading,
|
|
74
|
+
* sans-colon/trimmed/lowercased, ends with `rationale`, AND (b) its body
|
|
75
|
+
* contains NONE of `ALL_SAFETY_DISCIPLINES`. Any ambiguity (a safety string
|
|
76
|
+
* present, or simply not a `rationale:` heading) fails safe to INLINE — a
|
|
77
|
+
* wrongly-compressed LIVE rule is the catastrophic mode, so we over-include.
|
|
78
|
+
*/
|
|
79
|
+
export declare function compressRoleText(roleName: string, detailedDescription: string | null | undefined): string;
|
|
61
80
|
export declare function formatRegenMarkdown(result: {
|
|
62
81
|
cube: any & {
|
|
63
82
|
directive_hash?: string | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"regen-format.d.ts","sourceRoot":"","sources":["../src/regen-format.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"regen-format.d.ts","sourceRoot":"","sources":["../src/regen-format.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAQH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CA0FzC;AAED;;;;GAIG;AACH,eAAO,MAAM,cAAc,QAAqB,CAAC;AAE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CAClB,EACD,IAAI,GAAE;IAAE,IAAI,CAAC,EAAE,SAAS,CAAA;CAAO,GAC9B,MAAM,CAkHR;AAED,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,GAAG,EACV,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3B,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,GACzB,MAAM,CASR"}
|
package/dist/regen-format.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* index.ts's stdio MCP server bootstrap.
|
|
7
7
|
*/
|
|
8
8
|
import { ROLE_SCOPED_SAFETY_DISCIPLINES, UNIVERSAL_SAFETY_DISCIPLINES, } from './templates.js';
|
|
9
|
+
import { parseRoleSections } from './role-section.js';
|
|
9
10
|
/**
|
|
10
11
|
* Build the universal drone playbook.
|
|
11
12
|
*
|
|
@@ -189,6 +190,52 @@ export function parseRationalePointer(stub) {
|
|
|
189
190
|
return null;
|
|
190
191
|
}
|
|
191
192
|
}
|
|
193
|
+
/** The full safety-discipline corpus — a `… rationale:` section is NEVER
|
|
194
|
+
* compressed if its body contains ANY of these (⛔ safety-never-compress
|
|
195
|
+
* fail-safe). Over-inclusive on purpose: checks ALL role-scoped disciplines,
|
|
196
|
+
* not just the role's own, so a wrongly-placed LIVE rule can never be stubbed. */
|
|
197
|
+
const ALL_SAFETY_DISCIPLINES = [
|
|
198
|
+
...UNIVERSAL_SAFETY_DISCIPLINES,
|
|
199
|
+
...ROLE_SCOPED_SAFETY_DISCIPLINES,
|
|
200
|
+
];
|
|
201
|
+
/**
|
|
202
|
+
* gh#496-A(b) — compress a role's `detailed_description` for rendering.
|
|
203
|
+
*
|
|
204
|
+
* Splits the role text into sections (via the client port of the worker's
|
|
205
|
+
* `parseRoleSections`, parity-guarded) and replaces each `… rationale:`
|
|
206
|
+
* plain-label section's BODY with a one-line on-demand stub
|
|
207
|
+
* (`formatRationalePointer(role, heading)` verbatim — heading sans colon).
|
|
208
|
+
* Every other section — preamble, operational-rule sections, and ALL woven
|
|
209
|
+
* safety-discipline text — is emitted INLINE, fetch-free. No content is lost:
|
|
210
|
+
* `getRoleRationale(role, heading)` serves the full section on demand, so
|
|
211
|
+
* core-inline + Σ(every stub resolved) reconstructs the stored text.
|
|
212
|
+
*
|
|
213
|
+
* ⛔ SAFETY-NEVER-COMPRESS: a section is stubbed ONLY when (a) its heading,
|
|
214
|
+
* sans-colon/trimmed/lowercased, ends with `rationale`, AND (b) its body
|
|
215
|
+
* contains NONE of `ALL_SAFETY_DISCIPLINES`. Any ambiguity (a safety string
|
|
216
|
+
* present, or simply not a `rationale:` heading) fails safe to INLINE — a
|
|
217
|
+
* wrongly-compressed LIVE rule is the catastrophic mode, so we over-include.
|
|
218
|
+
*/
|
|
219
|
+
export function compressRoleText(roleName, detailedDescription) {
|
|
220
|
+
const text = detailedDescription ?? '';
|
|
221
|
+
const sections = parseRoleSections(text);
|
|
222
|
+
return sections
|
|
223
|
+
.map((section) => {
|
|
224
|
+
if (section.kind !== 'label' || section.heading == null)
|
|
225
|
+
return section.body;
|
|
226
|
+
const isRationale = section.heading.trim().toLowerCase().endsWith('rationale');
|
|
227
|
+
if (!isRationale)
|
|
228
|
+
return section.body;
|
|
229
|
+
// ⛔ fail-safe: never stub a section carrying any safety-discipline text.
|
|
230
|
+
if (ALL_SAFETY_DISCIPLINES.some((d) => section.body.includes(d)))
|
|
231
|
+
return section.body;
|
|
232
|
+
// Preserve the heading line verbatim; replace the rationale body with the stub.
|
|
233
|
+
const nlIdx = section.body.indexOf('\n');
|
|
234
|
+
const headingLine = nlIdx === -1 ? section.body + '\n' : section.body.slice(0, nlIdx + 1);
|
|
235
|
+
return headingLine + formatRationalePointer(roleName, section.heading) + '\n';
|
|
236
|
+
})
|
|
237
|
+
.join('');
|
|
238
|
+
}
|
|
192
239
|
export function formatRegenMarkdown(result, opts = {}) {
|
|
193
240
|
const mode = opts.mode ?? 'full';
|
|
194
241
|
const roleOverview = result.roles
|
|
@@ -226,7 +273,14 @@ export function formatRegenMarkdown(result, opts = {}) {
|
|
|
226
273
|
const taxonomyTip = nullTaxonomyTip(result.cube.message_taxonomy);
|
|
227
274
|
const roleTextHash = result.role.detailed_description_hash ?? null;
|
|
228
275
|
const directiveHash = result.cube.directive_hash ?? null;
|
|
229
|
-
|
|
276
|
+
// gh#496-A(b): full mode (and the lite emit-role-text branch) render the
|
|
277
|
+
// COMPRESSED-core role text — `… rationale:` sections become on-demand
|
|
278
|
+
// borg:role-rationale stubs; rules + all safety stay inline. The lite
|
|
279
|
+
// hash-gating path (shouldEmitRoleText, over the STORED detailed_description
|
|
280
|
+
// hash) and the lite-omitted safety set below are unchanged.
|
|
281
|
+
const roleText = result.role.detailed_description
|
|
282
|
+
? compressRoleText(result.role.name, result.role.detailed_description)
|
|
283
|
+
: '_(no detailed description set)_';
|
|
230
284
|
const directiveText = result.cube.cube_directive || '_(none)_';
|
|
231
285
|
const shouldEmitRoleText = mode === 'full' || roleTextHash == null || roleTextHash !== cachedRoleTextHash;
|
|
232
286
|
const shouldEmitDirective = mode === 'full' || directiveHash == null || directiveHash !== cachedDirectiveHash;
|
package/dist/regen-format.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"regen-format.js","sourceRoot":"","sources":["../src/regen-format.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,8BAA8B,EAC9B,4BAA4B,GAC7B,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"regen-format.js","sourceRoot":"","sources":["../src/regen-format.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,8BAA8B,EAC9B,4BAA4B,GAC7B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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* Role-text section parsing + granular section patching (gh#473 PR1).
|
|
3
|
+
*
|
|
4
|
+
* Platform-dependency-free, same shape as `message-taxonomy.ts`: pure
|
|
5
|
+
* string logic so the worker DB layer AND unit tests can both import it
|
|
6
|
+
* without dragging in Cloudflare / Neon types.
|
|
7
|
+
*
|
|
8
|
+
* ## Why not markdown `##` headings
|
|
9
|
+
*
|
|
10
|
+
* Real role `detailed_description` text (see `client/src/templates.ts`)
|
|
11
|
+
* does NOT use `##` headings. It is structured as:
|
|
12
|
+
*
|
|
13
|
+
* - a PREAMBLE — free prose before the first label line
|
|
14
|
+
* (e.g. "You implement changes to the codebase…");
|
|
15
|
+
* - one or more SECTIONS, each headed by a PLAIN-LABEL LINE — a line
|
|
16
|
+
* that is a short label terminated by a single trailing colon and
|
|
17
|
+
* nothing else (e.g. `Workflow:`, `Project conventions:`,
|
|
18
|
+
* `Your job:`, `Log conventions you use:`);
|
|
19
|
+
* - TRAILING inlined `${ESCALATION_DISCIPLINE}` / `${...}` constant
|
|
20
|
+
* text woven onto the end of the field. That text uses `**bold:**`
|
|
21
|
+
* markdown emphasis, NOT bare label lines, so it is NOT a section
|
|
22
|
+
* boundary — it falls into the last label section as literal text.
|
|
23
|
+
*
|
|
24
|
+
* A parser that splits on `##` finds ZERO sections in real role text.
|
|
25
|
+
* The label-line delimiter below matches the ACTUAL structure.
|
|
26
|
+
*
|
|
27
|
+
* ## Byte-identical round-trip invariant
|
|
28
|
+
*
|
|
29
|
+
* `serializeSections(parseRoleSections(text)) === text` for ANY input.
|
|
30
|
+
* The parser does not trim, normalize newlines, or otherwise rewrite
|
|
31
|
+
* bytes — each section's `body` retains the exact slice (including its
|
|
32
|
+
* heading line and the newline that terminates it) so concatenation
|
|
33
|
+
* reproduces the original field verbatim. The single named-fragment
|
|
34
|
+
* mutation is therefore the ONLY byte-level change a patch makes.
|
|
35
|
+
*/
|
|
36
|
+
/** What kind of label heads a section. */
|
|
37
|
+
export type RoleSectionKind = 'preamble' | 'label';
|
|
38
|
+
export interface RoleSection {
|
|
39
|
+
/**
|
|
40
|
+
* The section's label WITHOUT the trailing colon, trimmed
|
|
41
|
+
* (e.g. "Workflow", "Project conventions"). `null` for the preamble
|
|
42
|
+
* (the pre-first-label span). Used as the addressing key for patches.
|
|
43
|
+
*/
|
|
44
|
+
heading: string | null;
|
|
45
|
+
kind: RoleSectionKind;
|
|
46
|
+
/**
|
|
47
|
+
* The EXACT source slice for this section, including its heading line
|
|
48
|
+
* (for label sections) and every byte through to (but not including)
|
|
49
|
+
* the next section's heading line. Concatenating every section's
|
|
50
|
+
* `body` in order reproduces the original text byte-for-byte.
|
|
51
|
+
*/
|
|
52
|
+
body: string;
|
|
53
|
+
}
|
|
54
|
+
export type RoleSectionPatchOp = {
|
|
55
|
+
action: 'replace';
|
|
56
|
+
heading: string;
|
|
57
|
+
body: string;
|
|
58
|
+
} | {
|
|
59
|
+
action: 'insert';
|
|
60
|
+
heading: string;
|
|
61
|
+
body: string;
|
|
62
|
+
after?: string | null;
|
|
63
|
+
} | {
|
|
64
|
+
action: 'delete';
|
|
65
|
+
heading: string;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Test whether a single line is a plain-label section heading.
|
|
69
|
+
*
|
|
70
|
+
* Rules (deliberately narrow to avoid false positives against prose
|
|
71
|
+
* that merely contains a colon):
|
|
72
|
+
* - no leading whitespace (label lines start at column 0);
|
|
73
|
+
* - the line ends with exactly one `:`;
|
|
74
|
+
* - the text before the colon is non-empty, contains no other `:`,
|
|
75
|
+
* and is "short" (≤ 60 chars) — long colon-terminated prose lines
|
|
76
|
+
* are not labels;
|
|
77
|
+
* - the label is not a markdown emphasis run (does not start with
|
|
78
|
+
* `*`, `-`, `#`, `>` or backtick) — those are list/markdown lines,
|
|
79
|
+
* not plain labels (the woven `**Dense communication discipline:**`
|
|
80
|
+
* constant headings must NOT be treated as section boundaries).
|
|
81
|
+
*/
|
|
82
|
+
export declare function isLabelLine(line: string): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Parse role `detailed_description` text into ordered sections.
|
|
85
|
+
*
|
|
86
|
+
* The result always round-trips byte-identical through
|
|
87
|
+
* `serializeSections`. An empty string yields a single empty preamble
|
|
88
|
+
* section so callers always have a stable shape to address.
|
|
89
|
+
*/
|
|
90
|
+
export declare function parseRoleSections(text: string): RoleSection[];
|
|
91
|
+
/** Concatenate sections back into the original field text. */
|
|
92
|
+
export declare function serializeSections(sections: RoleSection[]): string;
|
|
93
|
+
/**
|
|
94
|
+
* Apply a single section-level patch to role text, returning the new
|
|
95
|
+
* full field text. Every other byte is preserved.
|
|
96
|
+
*
|
|
97
|
+
* - replace: overwrite the matched section's body with a re-rendered
|
|
98
|
+
* `<heading>:\n<body>` block. The heading match is case-insensitive
|
|
99
|
+
* on the label; the re-rendered heading uses the supplied casing.
|
|
100
|
+
* - insert: add a new label section. Placed after the section named by
|
|
101
|
+
* `after` (case-insensitive), or appended at the end when `after` is
|
|
102
|
+
* omitted/null. Rejects if a section with the same heading already
|
|
103
|
+
* exists (use replace instead).
|
|
104
|
+
* - delete: drop the matched section entirely.
|
|
105
|
+
*
|
|
106
|
+
* Throws when the target section is missing (replace/delete) or already
|
|
107
|
+
* present (insert), or when `after` does not resolve.
|
|
108
|
+
*/
|
|
109
|
+
export declare function patchRoleSectionText(text: string, op: RoleSectionPatchOp): string;
|
|
110
|
+
//# sourceMappingURL=role-section.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"role-section.d.ts","sourceRoot":"","sources":["../src/role-section.ts"],"names":[],"mappings":"AAcA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,0CAA0C;AAC1C,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG,OAAO,CAAC;AAEnD,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,IAAI,EAAE,eAAe,CAAC;IACtB;;;;;OAKG;IACH,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,kBAAkB,GAC1B;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACpD;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAC1E;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1C;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAYjD;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,EAAE,CA4C7D;AAED,8DAA8D;AAC9D,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,MAAM,CAEjE;AAiDD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,kBAAkB,GAAG,MAAM,CA2DjF"}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
// ⚠ gh#496-A(b) client/worker PARSER-AGREEMENT — this file MUST stay
|
|
2
|
+
// behavior-identical to `workers/role-section.ts`. The client render
|
|
3
|
+
// compression (`regen-format.ts`) splits role text with THIS parser to
|
|
4
|
+
// decide which `… rationale:` sections to stub; the worker's
|
|
5
|
+
// `getRoleRationale` resolves stub headings with the worker copy. They
|
|
6
|
+
// MUST derive section headings identically (sans-colon, isLabelLine rules)
|
|
7
|
+
// or a correctly-quoted stub won't resolve. Parity is enforced by
|
|
8
|
+
// `client/__tests__/role-section-parity.test.ts` (client parse == worker
|
|
9
|
+
// parse, section-for-section, on every shipped role). If you edit one,
|
|
10
|
+
// edit BOTH — or relocate to a shared module both packages import (tracked
|
|
11
|
+
// DRY follow-up). Verbatim port; zero logic change.
|
|
12
|
+
//
|
|
13
|
+
// ---- (verbatim copy of workers/role-section.ts below this line) ----
|
|
14
|
+
/**
|
|
15
|
+
* Test whether a single line is a plain-label section heading.
|
|
16
|
+
*
|
|
17
|
+
* Rules (deliberately narrow to avoid false positives against prose
|
|
18
|
+
* that merely contains a colon):
|
|
19
|
+
* - no leading whitespace (label lines start at column 0);
|
|
20
|
+
* - the line ends with exactly one `:`;
|
|
21
|
+
* - the text before the colon is non-empty, contains no other `:`,
|
|
22
|
+
* and is "short" (≤ 60 chars) — long colon-terminated prose lines
|
|
23
|
+
* are not labels;
|
|
24
|
+
* - the label is not a markdown emphasis run (does not start with
|
|
25
|
+
* `*`, `-`, `#`, `>` or backtick) — those are list/markdown lines,
|
|
26
|
+
* not plain labels (the woven `**Dense communication discipline:**`
|
|
27
|
+
* constant headings must NOT be treated as section boundaries).
|
|
28
|
+
*/
|
|
29
|
+
export function isLabelLine(line) {
|
|
30
|
+
// Leading whitespace disqualifies (label lines are flush-left).
|
|
31
|
+
if (/^\s/.test(line))
|
|
32
|
+
return false;
|
|
33
|
+
if (!line.endsWith(':'))
|
|
34
|
+
return false;
|
|
35
|
+
const label = line.slice(0, -1);
|
|
36
|
+
if (label.length === 0)
|
|
37
|
+
return false;
|
|
38
|
+
if (label.length > 60)
|
|
39
|
+
return false;
|
|
40
|
+
// Exactly one colon total (the trailing one).
|
|
41
|
+
if (label.includes(':'))
|
|
42
|
+
return false;
|
|
43
|
+
// Markdown/list/quote/code lead-ins are not plain labels.
|
|
44
|
+
if (/^[*\-#>`]/.test(label))
|
|
45
|
+
return false;
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Parse role `detailed_description` text into ordered sections.
|
|
50
|
+
*
|
|
51
|
+
* The result always round-trips byte-identical through
|
|
52
|
+
* `serializeSections`. An empty string yields a single empty preamble
|
|
53
|
+
* section so callers always have a stable shape to address.
|
|
54
|
+
*/
|
|
55
|
+
export function parseRoleSections(text) {
|
|
56
|
+
const sections = [];
|
|
57
|
+
const lines = text.split('\n');
|
|
58
|
+
// Reconstruct each line WITH its terminating newline so that the
|
|
59
|
+
// concatenation is lossless. `split('\n')` drops the separators; we
|
|
60
|
+
// re-append '\n' to every line except the last (which had no trailing
|
|
61
|
+
// newline in the source unless the source ended with one — in which
|
|
62
|
+
// case the final split element is '' and contributes nothing).
|
|
63
|
+
const lineWithSep = (idx) => idx < lines.length - 1 ? lines[idx] + '\n' : lines[idx];
|
|
64
|
+
let currentHeading = null;
|
|
65
|
+
let currentKind = 'preamble';
|
|
66
|
+
let currentBody = '';
|
|
67
|
+
let started = false;
|
|
68
|
+
const flush = () => {
|
|
69
|
+
sections.push({ heading: currentHeading, kind: currentKind, body: currentBody });
|
|
70
|
+
};
|
|
71
|
+
for (let i = 0; i < lines.length; i++) {
|
|
72
|
+
const raw = lines[i];
|
|
73
|
+
if (isLabelLine(raw)) {
|
|
74
|
+
// Close the in-progress section (preamble or previous label) and
|
|
75
|
+
// open a new label section headed by this line.
|
|
76
|
+
flush();
|
|
77
|
+
currentHeading = raw.slice(0, -1).trim();
|
|
78
|
+
currentKind = 'label';
|
|
79
|
+
currentBody = lineWithSep(i);
|
|
80
|
+
started = true;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
currentBody += lineWithSep(i);
|
|
84
|
+
started = true;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// Always emit the final in-progress section. For empty input this is a
|
|
88
|
+
// single empty preamble (started === false, currentBody === '').
|
|
89
|
+
if (started || sections.length === 0) {
|
|
90
|
+
flush();
|
|
91
|
+
}
|
|
92
|
+
return sections;
|
|
93
|
+
}
|
|
94
|
+
/** Concatenate sections back into the original field text. */
|
|
95
|
+
export function serializeSections(sections) {
|
|
96
|
+
return sections.map((s) => s.body).join('');
|
|
97
|
+
}
|
|
98
|
+
function normalizeHeading(value) {
|
|
99
|
+
return value.trim().toLowerCase();
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Build the body for a freshly inserted/replaced label section from a
|
|
103
|
+
* heading + caller-supplied body text.
|
|
104
|
+
*
|
|
105
|
+
* The heading line is rendered as `<heading>:` on its own line. The
|
|
106
|
+
* caller's `body` is the text BELOW the heading. We guarantee the
|
|
107
|
+
* section body ends with a single trailing newline so adjacent sections
|
|
108
|
+
* stay separated when re-serialized (matching how real role text
|
|
109
|
+
* separates label sections with blank lines is the caller's choice via
|
|
110
|
+
* their body text; we only ensure the structural newline).
|
|
111
|
+
*/
|
|
112
|
+
function renderLabelSection(heading, body) {
|
|
113
|
+
const headingLine = `${heading.trim()}:\n`;
|
|
114
|
+
if (body === '')
|
|
115
|
+
return headingLine;
|
|
116
|
+
// Ensure the body ends with a newline so the next section's heading
|
|
117
|
+
// starts on its own line.
|
|
118
|
+
const normalizedBody = body.endsWith('\n') ? body : body + '\n';
|
|
119
|
+
return headingLine + normalizedBody;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Guarantee the section at `idx` ends in a newline before a new section
|
|
123
|
+
* heading is glued on after it.
|
|
124
|
+
*
|
|
125
|
+
* Real role `detailed_description` text (every template role) ends WITHOUT
|
|
126
|
+
* a trailing newline — it closes on the woven `${...DISCIPLINE}` constant.
|
|
127
|
+
* Appending a `<heading>:` line directly onto such text would fuse the
|
|
128
|
+
* heading onto the prior section's last line, so the heading is no longer
|
|
129
|
+
* a flush-left label and the inserted section is LOST on re-parse. Adding
|
|
130
|
+
* the structural newline here keeps the inserted heading on its own line.
|
|
131
|
+
*
|
|
132
|
+
* No-ops when the preceding body is empty (an empty preamble needs no
|
|
133
|
+
* separator) or already ends in '\n' (preserves the already-correct case
|
|
134
|
+
* byte-for-byte).
|
|
135
|
+
*/
|
|
136
|
+
function ensureTrailingNewline(sections, idx) {
|
|
137
|
+
if (idx < 0 || idx >= sections.length)
|
|
138
|
+
return;
|
|
139
|
+
const prev = sections[idx];
|
|
140
|
+
if (prev.body !== '' && !prev.body.endsWith('\n')) {
|
|
141
|
+
sections[idx] = { ...prev, body: prev.body + '\n' };
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Apply a single section-level patch to role text, returning the new
|
|
146
|
+
* full field text. Every other byte is preserved.
|
|
147
|
+
*
|
|
148
|
+
* - replace: overwrite the matched section's body with a re-rendered
|
|
149
|
+
* `<heading>:\n<body>` block. The heading match is case-insensitive
|
|
150
|
+
* on the label; the re-rendered heading uses the supplied casing.
|
|
151
|
+
* - insert: add a new label section. Placed after the section named by
|
|
152
|
+
* `after` (case-insensitive), or appended at the end when `after` is
|
|
153
|
+
* omitted/null. Rejects if a section with the same heading already
|
|
154
|
+
* exists (use replace instead).
|
|
155
|
+
* - delete: drop the matched section entirely.
|
|
156
|
+
*
|
|
157
|
+
* Throws when the target section is missing (replace/delete) or already
|
|
158
|
+
* present (insert), or when `after` does not resolve.
|
|
159
|
+
*/
|
|
160
|
+
export function patchRoleSectionText(text, op) {
|
|
161
|
+
const sections = parseRoleSections(text);
|
|
162
|
+
const targetKey = normalizeHeading(op.heading);
|
|
163
|
+
if (op.action === 'replace') {
|
|
164
|
+
const idx = sections.findIndex((s) => s.kind === 'label' && s.heading != null && normalizeHeading(s.heading) === targetKey);
|
|
165
|
+
if (idx === -1) {
|
|
166
|
+
throw new Error(`Role section "${op.heading}" not found. Use action="insert" to add it.`);
|
|
167
|
+
}
|
|
168
|
+
sections[idx] = {
|
|
169
|
+
heading: op.heading.trim(),
|
|
170
|
+
kind: 'label',
|
|
171
|
+
body: renderLabelSection(op.heading, op.body),
|
|
172
|
+
};
|
|
173
|
+
return serializeSections(sections);
|
|
174
|
+
}
|
|
175
|
+
if (op.action === 'delete') {
|
|
176
|
+
const idx = sections.findIndex((s) => s.kind === 'label' && s.heading != null && normalizeHeading(s.heading) === targetKey);
|
|
177
|
+
if (idx === -1) {
|
|
178
|
+
throw new Error(`Role section "${op.heading}" not found.`);
|
|
179
|
+
}
|
|
180
|
+
sections.splice(idx, 1);
|
|
181
|
+
return serializeSections(sections);
|
|
182
|
+
}
|
|
183
|
+
// insert
|
|
184
|
+
const exists = sections.some((s) => s.kind === 'label' && s.heading != null && normalizeHeading(s.heading) === targetKey);
|
|
185
|
+
if (exists) {
|
|
186
|
+
throw new Error(`Role section "${op.heading}" already exists. Use action="replace" to overwrite it.`);
|
|
187
|
+
}
|
|
188
|
+
const newSection = {
|
|
189
|
+
heading: op.heading.trim(),
|
|
190
|
+
kind: 'label',
|
|
191
|
+
body: renderLabelSection(op.heading, op.body),
|
|
192
|
+
};
|
|
193
|
+
if (op.after == null) {
|
|
194
|
+
ensureTrailingNewline(sections, sections.length - 1);
|
|
195
|
+
sections.push(newSection);
|
|
196
|
+
return serializeSections(sections);
|
|
197
|
+
}
|
|
198
|
+
const afterKey = normalizeHeading(op.after);
|
|
199
|
+
const afterIdx = sections.findIndex((s) => s.kind === 'label' && s.heading != null && normalizeHeading(s.heading) === afterKey);
|
|
200
|
+
if (afterIdx === -1) {
|
|
201
|
+
throw new Error(`Cannot insert after section "${op.after}" — it does not exist.`);
|
|
202
|
+
}
|
|
203
|
+
ensureTrailingNewline(sections, afterIdx);
|
|
204
|
+
sections.splice(afterIdx + 1, 0, newSection);
|
|
205
|
+
return serializeSections(sections);
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=role-section.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"role-section.js","sourceRoot":"","sources":["../src/role-section.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,qEAAqE;AACrE,uEAAuE;AACvE,6DAA6D;AAC7D,uEAAuE;AACvE,2EAA2E;AAC3E,kEAAkE;AAClE,yEAAyE;AACzE,uEAAuE;AACvE,2EAA2E;AAC3E,oDAAoD;AACpD,EAAE;AACF,uEAAuE;AA+DvE;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC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ithGoogle } from './auth.js';
|
|
15
15
|
import { checkSubscriptionStatus, createSubscription } from './remote-client.js';
|
|
16
|
+
import { retrySubscriptionCheck } from './subscription-retry.js';
|
|
16
17
|
import { addMcpServer, addSessionStartHook, addUserPromptSubmitHook, addCodexMcpServer, addCodexSessionStartHook, addCodexUserPromptSubmitHook, isMcpServerConfigured, isCodexMcpServerConfigured, } from './config-utils.js';
|
|
17
18
|
import { isAuthenticated } from './config.js';
|
|
18
19
|
import { handleVersionFlag } from './version.js';
|
|
@@ -105,14 +106,27 @@ async function main() {
|
|
|
105
106
|
console.error(chalk.red(`\n◼ Failed to check subscription: ${error.message}\n`));
|
|
106
107
|
process.exit(1);
|
|
107
108
|
}
|
|
109
|
+
// gh#521: a user who just subscribed via web hits propagation lag — retry a
|
|
110
|
+
// few times (non-alarmingly) before declaring no subscription, instead of
|
|
111
|
+
// flashing a scary "not found" immediately after payment.
|
|
112
|
+
status = await retrySubscriptionCheck(status, {
|
|
113
|
+
check: checkSubscriptionStatus,
|
|
114
|
+
sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
|
|
115
|
+
onRetry: (attempt, total) => console.log(chalk.gray(`◼ Checking subscription... (attempt ${attempt}/${total})`)),
|
|
116
|
+
});
|
|
108
117
|
if (!status.hasAccess) {
|
|
109
|
-
console.log(chalk.yellow('◼
|
|
118
|
+
console.log(chalk.yellow('◼ Subscription not found yet — this can take a moment to activate after subscribing.'));
|
|
110
119
|
console.log(chalk.gray('◼ Cube tier: $1/cube/month. Free tier is permanent (1 cube + 3 drones).\n'));
|
|
111
120
|
const { subscribeMethod } = await prompts({
|
|
112
121
|
type: 'select',
|
|
113
122
|
name: 'subscribeMethod',
|
|
114
123
|
message: 'How would you like to subscribe?',
|
|
115
124
|
choices: [
|
|
125
|
+
{
|
|
126
|
+
title: '◼ I already subscribed',
|
|
127
|
+
value: 'recheck',
|
|
128
|
+
description: 'Re-check now — a just-completed subscription can take a moment to activate'
|
|
129
|
+
},
|
|
116
130
|
{
|
|
117
131
|
title: '◼ Open web dashboard (recommended)',
|
|
118
132
|
value: 'web',
|
|
@@ -123,11 +137,6 @@ async function main() {
|
|
|
123
137
|
value: 'stripe',
|
|
124
138
|
description: 'Fast checkout in browser'
|
|
125
139
|
},
|
|
126
|
-
{
|
|
127
|
-
title: '◼ I already subscribed',
|
|
128
|
-
value: 'recheck',
|
|
129
|
-
description: 'Check subscription status again'
|
|
130
|
-
},
|
|
131
140
|
{
|
|
132
141
|
title: '◼ Skip for now',
|
|
133
142
|
value: 'skip',
|
package/dist/setup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":";AACA;;;;;;;GAOG;AAEH,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACjF,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,uBAAuB,EACvB,iBAAiB,EACjB,wBAAwB,EACxB,4BAA4B,EAC5B,qBAAqB,EACrB,0BAA0B,GAC3B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD;;GAEG;AACH,KAAK,UAAU,IAAI;IACjB,iBAAiB,EAAE,CAAC;IACpB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC,CAAC;IAE5D,uCAAuC;IACvC,IAAI,aAAa,GAAkB,IAAI,CAAC;IACxC,IAAI,YAAY,GAAkB,IAAI,CAAC;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CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,qBAAqB,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC;IACjE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gh#521 — post-subscribe subscription-status retry.
|
|
3
|
+
*
|
|
4
|
+
* A user who just subscribed via the web hits propagation lag: `borg setup`
|
|
5
|
+
* authenticates, then the subscription check can still report no-access for a
|
|
6
|
+
* few seconds (or up to the ~60s server-side subscription cache) — so setup
|
|
7
|
+
* flashed a scary "No active subscription found" right after payment. This
|
|
8
|
+
* retries the check a few times (non-alarmingly) before declaring no
|
|
9
|
+
* subscription, so most just-subscribed users succeed on retry 2-3.
|
|
10
|
+
*
|
|
11
|
+
* Pure + injectable (no console / network / real timer of its own) so it's
|
|
12
|
+
* unit-testable without the interactive setup flow — the cli-help.ts /
|
|
13
|
+
* parse-assimilate-args.ts pattern.
|
|
14
|
+
*/
|
|
15
|
+
export interface SubscriptionStatus {
|
|
16
|
+
hasAccess: boolean;
|
|
17
|
+
/** ISO date / epoch / Date of subscription expiry, when present. */
|
|
18
|
+
expiresAt?: string | number | Date;
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
}
|
|
21
|
+
export interface RetrySubscriptionDeps {
|
|
22
|
+
/** Re-check subscription status (e.g. checkSubscriptionStatus). */
|
|
23
|
+
check: () => Promise<SubscriptionStatus>;
|
|
24
|
+
/** Delay between attempts (injected so tests don't actually wait). */
|
|
25
|
+
sleep: (ms: number) => Promise<void>;
|
|
26
|
+
/** Called before each RETRY (attempts 2..total) — for a non-alarming status line. */
|
|
27
|
+
onRetry?: (attempt: number, total: number) => void;
|
|
28
|
+
/** Total attempts including the initial one (default 3). */
|
|
29
|
+
attempts?: number;
|
|
30
|
+
/** Backoff between attempts in ms (default 2000). */
|
|
31
|
+
backoffMs?: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Given the initial check result, retry up to `attempts` total times with
|
|
35
|
+
* `backoffMs` backoff, stopping early as soon as access is granted. A transient
|
|
36
|
+
* error on a retry is swallowed (keep the prior status and keep trying). Returns
|
|
37
|
+
* the latest status.
|
|
38
|
+
*/
|
|
39
|
+
export declare function retrySubscriptionCheck(initial: SubscriptionStatus, deps: RetrySubscriptionDeps): Promise<SubscriptionStatus>;
|
|
40
|
+
//# sourceMappingURL=subscription-retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscription-retry.d.ts","sourceRoot":"","sources":["../src/subscription-retry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,OAAO,CAAC;IACnB,oEAAoE;IACpE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACnC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,qBAAqB;IACpC,mEAAmE;IACnE,KAAK,EAAE,MAAM,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACzC,sEAAsE;IACtE,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,qFAAqF;IACrF,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnD,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qDAAqD;IACrD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,kBAAkB,EAC3B,IAAI,EAAE,qBAAqB,GAC1B,OAAO,CAAC,kBAAkB,CAAC,CAc7B"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Given the initial check result, retry up to `attempts` total times with
|
|
3
|
+
* `backoffMs` backoff, stopping early as soon as access is granted. A transient
|
|
4
|
+
* error on a retry is swallowed (keep the prior status and keep trying). Returns
|
|
5
|
+
* the latest status.
|
|
6
|
+
*/
|
|
7
|
+
export async function retrySubscriptionCheck(initial, deps) {
|
|
8
|
+
const attempts = deps.attempts ?? 3;
|
|
9
|
+
const backoffMs = deps.backoffMs ?? 2000;
|
|
10
|
+
let status = initial;
|
|
11
|
+
for (let attempt = 2; attempt <= attempts && !status.hasAccess; attempt++) {
|
|
12
|
+
deps.onRetry?.(attempt, attempts);
|
|
13
|
+
await deps.sleep(backoffMs);
|
|
14
|
+
try {
|
|
15
|
+
status = await deps.check();
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
// Transient error on a retry — keep the prior status and continue retrying.
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return status;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=subscription-retry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscription-retry.js","sourceRoot":"","sources":["../src/subscription-retry.ts"],"names":[],"mappings":"AAkCA;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,OAA2B,EAC3B,IAA2B;IAE3B,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAC;IACpC,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC;IACzC,IAAI,MAAM,GAAG,OAAO,CAAC;IACrB,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,IAAI,QAAQ,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE,CAAC;QAC1E,IAAI,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QAClC,MAAM,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAC5B,IAAI,CAAC;YACH,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;QAC9B,CAAC;QAAC,MAAM,CAAC;YACP,4EAA4E;QAC9E,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|