@lore-co/core 0.2.20 → 0.2.21

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 (82) hide show
  1. package/dist/approaches.d.ts +431 -36
  2. package/dist/approaches.d.ts.map +1 -1
  3. package/dist/approaches.js +68 -7
  4. package/dist/approaches.js.map +1 -1
  5. package/dist/cloud-recovery-schemas.d.ts +2 -2
  6. package/dist/connector-review.d.ts +11 -0
  7. package/dist/connector-review.d.ts.map +1 -0
  8. package/dist/connector-review.js +36 -0
  9. package/dist/connector-review.js.map +1 -0
  10. package/dist/engine.d.ts.map +1 -1
  11. package/dist/engine.js +17 -10
  12. package/dist/engine.js.map +1 -1
  13. package/dist/guard-schemas.d.ts +4 -4
  14. package/dist/host-envelopes.d.ts +110 -0
  15. package/dist/host-envelopes.d.ts.map +1 -0
  16. package/dist/host-envelopes.js +282 -0
  17. package/dist/host-envelopes.js.map +1 -0
  18. package/dist/in-memory-repository.d.ts +8 -1
  19. package/dist/in-memory-repository.d.ts.map +1 -1
  20. package/dist/in-memory-repository.js +49 -3
  21. package/dist/in-memory-repository.js.map +1 -1
  22. package/dist/index.d.ts +4 -0
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +4 -0
  25. package/dist/index.js.map +1 -1
  26. package/dist/integration-contract.d.ts +32 -32
  27. package/dist/knowledge-quality.d.ts +19 -0
  28. package/dist/knowledge-quality.d.ts.map +1 -1
  29. package/dist/knowledge-quality.js +76 -1
  30. package/dist/knowledge-quality.js.map +1 -1
  31. package/dist/learning-drafts.d.ts +1 -1
  32. package/dist/pilot-schemas.d.ts +68 -47
  33. package/dist/pilot-schemas.d.ts.map +1 -1
  34. package/dist/pilot-schemas.js +16 -0
  35. package/dist/pilot-schemas.js.map +1 -1
  36. package/dist/ports.d.ts +7 -1
  37. package/dist/ports.d.ts.map +1 -1
  38. package/dist/ports.js.map +1 -1
  39. package/dist/prepared-context.d.ts +2 -0
  40. package/dist/prepared-context.d.ts.map +1 -1
  41. package/dist/prepared-context.js +10 -7
  42. package/dist/prepared-context.js.map +1 -1
  43. package/dist/product-usage.d.ts +6 -6
  44. package/dist/reliability-schemas.d.ts +28 -7
  45. package/dist/reliability-schemas.d.ts.map +1 -1
  46. package/dist/reliability-schemas.js +28 -3
  47. package/dist/reliability-schemas.js.map +1 -1
  48. package/dist/repository-location.d.ts +7 -0
  49. package/dist/repository-location.d.ts.map +1 -1
  50. package/dist/repository-location.js +12 -3
  51. package/dist/repository-location.js.map +1 -1
  52. package/dist/schemas.d.ts +71 -53
  53. package/dist/schemas.d.ts.map +1 -1
  54. package/dist/schemas.js +24 -0
  55. package/dist/schemas.js.map +1 -1
  56. package/dist/search-schemas.d.ts +5 -5
  57. package/dist/session-purpose.d.ts.map +1 -1
  58. package/dist/session-purpose.js +6 -2
  59. package/dist/session-purpose.js.map +1 -1
  60. package/dist/session-schemas.d.ts +24 -10
  61. package/dist/session-schemas.d.ts.map +1 -1
  62. package/dist/session-schemas.js +11 -0
  63. package/dist/session-schemas.js.map +1 -1
  64. package/dist/session-titles.d.ts +34 -0
  65. package/dist/session-titles.d.ts.map +1 -0
  66. package/dist/session-titles.js +31 -0
  67. package/dist/session-titles.js.map +1 -0
  68. package/dist/skill-context.d.ts +5 -0
  69. package/dist/skill-context.d.ts.map +1 -1
  70. package/dist/skill-context.js +16 -0
  71. package/dist/skill-context.js.map +1 -1
  72. package/dist/skills.d.ts +8 -8
  73. package/dist/snapshot-schemas.d.ts +32 -32
  74. package/dist/turn-context-request.d.ts +10 -0
  75. package/dist/turn-context-request.d.ts.map +1 -0
  76. package/dist/turn-context-request.js +28 -0
  77. package/dist/turn-context-request.js.map +1 -0
  78. package/dist/user-message.d.ts +9 -1
  79. package/dist/user-message.d.ts.map +1 -1
  80. package/dist/user-message.js +26 -36
  81. package/dist/user-message.js.map +1 -1
  82. package/package.json +9 -1
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Host-injected prompt wrappers, declared once.
3
+ *
4
+ * Connected agents deliver prompts to Lore's hooks with machine envelopes
5
+ * around or instead of the user's words: notices the Claude desktop app
6
+ * writes itself, Codex's ambient browser state and attachment preambles,
7
+ * Copilot's reference tags and review wrappers. This registry is the only
8
+ * place that knows their shapes. Everything else derives from it:
9
+ *
10
+ * - `userMessageText` / `learningMessageText` (user-message.ts) use the
11
+ * JavaScript helpers below for display, digests, titles and extraction.
12
+ * - `HOST_NOTICE_PROMPT_PATTERN` is PostgreSQL-portable and gates titles,
13
+ * activity rows and search hits in the database package.
14
+ * - The web app imports the Codex preamble patterns for attachment display.
15
+ *
16
+ * Rules every consumer keeps: only leading envelopes are metadata; quoted,
17
+ * fenced and indented examples stay untouched; a truncated envelope yields ""
18
+ * so callers fall back; notice-only prompts never establish human intent.
19
+ *
20
+ * Codex's background suggestion jobs are whole prompts rather than wrappers
21
+ * and keep their own pattern in session-purpose.ts.
22
+ */
23
+ export type HostEnvelopeHost = "claude-code" | "codex" | "copilot-cli";
24
+ export type HostEnvelopeKind =
25
+ /** The whole prompt is the host's notice: hide from titles and activity, never human evidence. */
26
+ "notice"
27
+ /** Context the host prepends to the user's request, optionally followed by a request heading. */
28
+ | "ambient-context"
29
+ /** Inline reference the host expands; display its label. */
30
+ | "annotation"
31
+ /** Wrapper around a reviewer's comment; the comment is the human text. */
32
+ | "review-request"
33
+ /** Transport that encodes the user's reply; decoded by user-message.ts. */
34
+ | "transport"
35
+ /** Markdown preamble Codex writes before the request (attachments, diff comments). */
36
+ | "preamble"
37
+ /** Brief a host writes when one agent session starts another; only its task is the request. */
38
+ | "brief"
39
+ /** Tag a host wraps around text the user pasted; the paste is the user's, the tag is not. */
40
+ | "wrapper";
41
+ export interface HostEnvelope {
42
+ readonly id: string;
43
+ readonly host: HostEnvelopeHost;
44
+ readonly kind: HostEnvelopeKind;
45
+ readonly description: string;
46
+ /** XML-like tag name for tag envelopes: `<tag …>…</tag>` or `<tag … />`. */
47
+ readonly tag?: string;
48
+ /** Regex source for attributes the opening tag must carry to count as this envelope. */
49
+ readonly attributes?: string;
50
+ /** Attribute whose value stands in for an annotation on display. */
51
+ readonly labelAttribute?: string;
52
+ /** Regex source for the first line of a preamble or review wrapper. */
53
+ readonly heading?: string;
54
+ /** Regex source for the Markdown heading that introduces the user's own request after the envelope. */
55
+ readonly requestHeading?: string;
56
+ }
57
+ export declare const CODEX_REQUEST_HEADING: string;
58
+ export declare const HOST_ENVELOPES: readonly HostEnvelope[];
59
+ export declare function hostEnvelopes(kind: HostEnvelopeKind, host?: HostEnvelopeHost): readonly HostEnvelope[];
60
+ /**
61
+ * Remove every consecutive leading host envelope: notices from any host and
62
+ * Codex's ambient context with its request heading. A title truncated inside
63
+ * an envelope has no closing tag and yields "" so the caller falls back.
64
+ */
65
+ export declare function withoutLeadingHostEnvelopes(text: string): string;
66
+ /** Replace inline host annotations such as <copilot-ref … /> with their label, outside examples. */
67
+ export declare function withLabeledAnnotations(text: string): string;
68
+ /** Remove host notices wherever they appear, outside examples. Learning evidence never includes them. */
69
+ export declare function withoutHostNotices(text: string): string;
70
+ /**
71
+ * The task from a brief one agent session wrote for another; the background
72
+ * and the notes folder are the host's framing. A brief without a task, such
73
+ * as a stored title cut inside the background, yields "" so callers fall back.
74
+ */
75
+ export declare function withoutSideSessionBrief(text: string): string;
76
+ /**
77
+ * Whether a prompt is the brief one agent session wrote for another: the
78
+ * desktop app delivers it as the new session's first prompt, possibly after
79
+ * its own notices. A quoted, fenced or indented brief is an example, not a
80
+ * brief, and a title cut inside the background still counts as one.
81
+ */
82
+ export declare function isSideSessionBrief(text: string): boolean;
83
+ /** Remove host wrappers around the user's own pasted text, keeping the text, outside examples. */
84
+ export declare function withoutInlineWrappers(text: string): string;
85
+ /**
86
+ * The reviewer's own comment inside a review-request wrapper, or undefined
87
+ * when the text is not such a wrapper or holds no comment. The wrapper's
88
+ * instruction, identifiers and diff are not the reviewer's words.
89
+ */
90
+ export declare function reviewRequestComment(text: string): string | undefined;
91
+ export declare function isReviewRequest(text: string): boolean;
92
+ /** The Codex attachment preamble heading, for callers that list the attached files themselves. */
93
+ export declare const CODEX_ATTACHMENT_PREAMBLE: RegExp;
94
+ /** The instruction line Codex adds under its attachment list. */
95
+ export declare const CODEX_ATTACHMENT_INSTRUCTION: RegExp;
96
+ /** The heading Codex writes before the user's request, as a whole line. */
97
+ export declare const CODEX_REQUEST_HEADING_LINE: RegExp;
98
+ /** Remove Codex's attachment preamble (names, paths and instruction) and keep the request. */
99
+ export declare function withoutAttachmentPreamble(text: string): string;
100
+ /**
101
+ * Keep the reviewer's comments and the request from a Codex diff-comment
102
+ * prompt; the file, side, line and hunk metadata is the host's framing.
103
+ */
104
+ export declare function withoutDiffCommentMetadata(text: string): string;
105
+ export declare const HOST_NOTICE_PROMPT_PATTERN: string;
106
+ /** Test the recorded prompt itself: display helpers already strip these envelopes. */
107
+ export declare function isHostNoticePrompt(value: string): boolean;
108
+ /** PostgreSQL-portable optional prefix for Codex's ambient context before an app-generated prompt. */
109
+ export declare const AMBIENT_CONTEXT_SQL_PREFIX: string;
110
+ //# sourceMappingURL=host-envelopes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-envelopes.d.ts","sourceRoot":"","sources":["../src/host-envelopes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG,OAAO,GAAG,aAAa,CAAC;AAEvE,MAAM,MAAM,gBAAgB;AAC1B,kGAAkG;AAChG,QAAQ;AACV,iGAAiG;GAC/F,iBAAiB;AACnB,4DAA4D;GAC1D,YAAY;AACd,0EAA0E;GACxE,gBAAgB;AAClB,2EAA2E;GACzE,WAAW;AACb,sFAAsF;GACpF,UAAU;AACZ,+FAA+F;GAC7F,OAAO;AACT,6FAA6F;GAC3F,SAAS,CAAC;AAEd,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,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,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAErD;AAGD,kGAAkG;AAClG,eAAO,MAAM,yBAAyB,QAAiE,CAAC;AACxG,iEAAiE;AACjE,eAAO,MAAM,4BAA4B,QAA8D,CAAC;AACxG,2EAA2E;AAC3E,eAAO,MAAM,0BAA0B,QAAoE,CAAC;AAG5G,8FAA8F;AAC9F,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9D;AAID;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAc/D;AASD,eAAO,MAAM,0BAA0B,QAA2I,CAAC;AAGnL,sFAAsF;AACtF,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED,sGAAsG;AACtG,eAAO,MAAM,0BAA0B,QAGxB,CAAC"}
@@ -0,0 +1,282 @@
1
+ /**
2
+ * Host-injected prompt wrappers, declared once.
3
+ *
4
+ * Connected agents deliver prompts to Lore's hooks with machine envelopes
5
+ * around or instead of the user's words: notices the Claude desktop app
6
+ * writes itself, Codex's ambient browser state and attachment preambles,
7
+ * Copilot's reference tags and review wrappers. This registry is the only
8
+ * place that knows their shapes. Everything else derives from it:
9
+ *
10
+ * - `userMessageText` / `learningMessageText` (user-message.ts) use the
11
+ * JavaScript helpers below for display, digests, titles and extraction.
12
+ * - `HOST_NOTICE_PROMPT_PATTERN` is PostgreSQL-portable and gates titles,
13
+ * activity rows and search hits in the database package.
14
+ * - The web app imports the Codex preamble patterns for attachment display.
15
+ *
16
+ * Rules every consumer keeps: only leading envelopes are metadata; quoted,
17
+ * fenced and indented examples stay untouched; a truncated envelope yields ""
18
+ * so callers fall back; notice-only prompts never establish human intent.
19
+ *
20
+ * Codex's background suggestion jobs are whole prompts rather than wrappers
21
+ * and keep their own pattern in session-purpose.ts.
22
+ */
23
+ // The heading Codex writes between its preambles and the user's request.
24
+ export const CODEX_REQUEST_HEADING = String.raw `## My request:`;
25
+ export const HOST_ENVELOPES = [
26
+ // Claude Code: the desktop app starts some turns itself and delivers them to
27
+ // the UserPromptSubmit hook as prompts made only of one or more notices.
28
+ { id: "claude-system-reminder", host: "claude-code", kind: "notice", tag: "system-reminder",
29
+ description: "Proposal starts, linked-session status, worktree notes and reports from sessions this one started." },
30
+ { id: "claude-side-sessions-event", host: "claude-code", kind: "notice", tag: "side-sessions-event",
31
+ description: "A session this one started ended its turn." },
32
+ { id: "claude-ci-monitor-event", host: "claude-code", kind: "notice", tag: "ci-monitor-event",
33
+ description: "Auto-fix CI, merge-conflict and review-comment events; the body may mention the tag itself." },
34
+ { id: "claude-task-notification", host: "claude-code", kind: "notice", tag: "task-notification",
35
+ description: "Background task completion; nests <task-id>, <tool-use-id>, <output-file>, <status> and <summary>." },
36
+ { id: "claude-cross-session-message", host: "claude-code", kind: "notice", tag: "cross-session-message",
37
+ description: "A message another session sent with SendMessage, delivered as a prompt." },
38
+ { id: "claude-agent-message", host: "claude-code", kind: "notice", tag: "agent-message",
39
+ description: "A subagent hand-back report framed by the harness; model output, not the user's words." },
40
+ { id: "claude-side-session-brief", host: "claude-code", kind: "brief", heading: String.raw `(?:Background|Task) \(from the session that started this one\):`,
41
+ description: "Background and task the desktop app writes when a session starts another, optionally ending with the shared notes folder." },
42
+ { id: "claude-pasted-content", host: "claude-code", kind: "wrapper", tag: "pasted_content",
43
+ description: "Tag with a random id around text the user pasted into the prompt." },
44
+ // Copilot CLI: coordination notices use the user role but are host-written.
45
+ { id: "copilot-coordination-revocation", host: "copilot-cli", kind: "notice", tag: "coordination_revocation",
46
+ description: "Automatic coordination ended; earlier report-back instructions are revoked." },
47
+ { id: "copilot-system-notification", host: "copilot-cli", kind: "notice", tag: "system_notification",
48
+ description: "Background status such as synchronization or idle tasks." },
49
+ { id: "copilot-cross-session-message", host: "copilot-cli", kind: "notice", tag: "cross_session_message",
50
+ description: "A message relayed from another Copilot session." },
51
+ { id: "copilot-ref", host: "copilot-cli", kind: "annotation", tag: "copilot-ref", labelAttribute: "label",
52
+ description: "Self-closing reference to a file, pull request or symbol; its label is what the user saw." },
53
+ { id: "copilot-inline-review", host: "copilot-cli", kind: "review-request", heading: String.raw `\[INLINE CODE REVIEW REQUEST\]`,
54
+ description: "Wrapper around a reviewer's inline comment with identifiers and the diff." },
55
+ // Codex: ambient UI state, transport and Markdown preambles.
56
+ { id: "codex-ambient-browser-context", host: "codex", kind: "ambient-context", tag: "in-app-browser-context",
57
+ attributes: String.raw `[ \t]+source=("ambient-ui-state"|'ambient-ui-state')[ \t]*`, requestHeading: CODEX_REQUEST_HEADING,
58
+ description: "Automatically supplied in-app browser state before the request." },
59
+ { id: "codex-question-reply", host: "codex", kind: "transport", tag: "send_user_message_question_reply",
60
+ description: "JSON-encoded answers to a question the agent asked." },
61
+ { id: "codex-attachments", host: "codex", kind: "preamble", heading: String.raw `# Files (mentioned|pasted) by the user:`, requestHeading: CODEX_REQUEST_HEADING,
62
+ description: "Attachment names and paths, an instruction line, then the request." },
63
+ { id: "codex-diff-comments", host: "codex", kind: "preamble", heading: String.raw `# Diff comments:`, requestHeading: CODEX_REQUEST_HEADING,
64
+ description: "Reviewer comments on a diff with file, side, line and hunk metadata, then the request." },
65
+ ];
66
+ export function hostEnvelopes(kind, host) {
67
+ return HOST_ENVELOPES.filter(envelope => envelope.kind === kind && (host === undefined || envelope.host === host));
68
+ }
69
+ const noticeTags = hostEnvelopes("notice").map(envelope => envelope.tag);
70
+ const ambientContexts = hostEnvelopes("ambient-context");
71
+ const annotations = hostEnvelopes("annotation");
72
+ const reviewRequests = hostEnvelopes("review-request");
73
+ const attachmentPreamble = HOST_ENVELOPES.find(envelope => envelope.id === "codex-attachments");
74
+ const diffCommentsPreamble = HOST_ENVELOPES.find(envelope => envelope.id === "codex-diff-comments");
75
+ // Blank lines before an envelope and up to three spaces of indentation are not
76
+ // a code block; four spaces are.
77
+ const leadingBlank = String.raw `(?:[ \t]*\r?\n)* {0,3}`;
78
+ const noticeOpening = new RegExp(String.raw `^${leadingBlank}<(${noticeTags.join("|")})(?:[ \t\r\n][^>]*)?>`, "u");
79
+ // A stored title can be cut inside a long opening tag such as
80
+ // <cross-session-message from="local_…" name="…">; the ellipsis marks the cut.
81
+ const truncatedNoticeOpening = new RegExp(String.raw `^${leadingBlank}<(${noticeTags.join("|")})[ \t\r\n][^>]*…$`, "u");
82
+ const ambientOpenings = ambientContexts.map(envelope => ({
83
+ envelope,
84
+ opening: new RegExp(String.raw `^${leadingBlank}<${envelope.tag}${envelope.attributes ?? ""}>`, "u"),
85
+ }));
86
+ /** Regex for a request heading at the start of the text, with its line break. */
87
+ function requestHeadingStart(heading) {
88
+ return new RegExp(String.raw `^ {0,3}${heading}[ \t]*(?:\r?\n|$)`, "u");
89
+ }
90
+ const trimLeadingBlankLines = (text) => text.replace(/^(?:[ \t]*\r?\n)+/u, "");
91
+ const isBlank = (text) => !/[^ \t\r\n]/u.test(text);
92
+ /**
93
+ * Remove every consecutive leading host envelope: notices from any host and
94
+ * Codex's ambient context with its request heading. A title truncated inside
95
+ * an envelope has no closing tag and yields "" so the caller falls back.
96
+ */
97
+ export function withoutLeadingHostEnvelopes(text) {
98
+ for (;;) {
99
+ if (truncatedNoticeOpening.test(text))
100
+ return "";
101
+ const notice = noticeOpening.exec(text);
102
+ if (notice) {
103
+ const remainder = afterClosingTag(text, notice[1], notice[0].length);
104
+ if (remainder === undefined)
105
+ return "";
106
+ text = remainder;
107
+ continue;
108
+ }
109
+ let stripped = false;
110
+ for (const { envelope, opening } of ambientOpenings) {
111
+ const match = opening.exec(text);
112
+ if (!match)
113
+ continue;
114
+ let remainder = afterClosingTag(text, envelope.tag, match[0].length);
115
+ if (remainder === undefined)
116
+ return "";
117
+ if (envelope.requestHeading)
118
+ remainder = trimLeadingBlankLines(remainder.replace(requestHeadingStart(envelope.requestHeading), ""));
119
+ text = isBlank(remainder) ? "" : remainder;
120
+ stripped = true;
121
+ break;
122
+ }
123
+ if (!stripped)
124
+ return text;
125
+ }
126
+ }
127
+ function afterClosingTag(text, tag, from) {
128
+ const closingTag = `</${tag}>`;
129
+ const closing = text.indexOf(closingTag, from);
130
+ if (closing === -1)
131
+ return undefined;
132
+ const remainder = trimLeadingBlankLines(text.slice(closing + closingTag.length));
133
+ return isBlank(remainder) ? "" : remainder;
134
+ }
135
+ /** Ranges of quoted and code examples, which no inline cleanup may touch. */
136
+ function exampleRanges(text) {
137
+ return [...text.matchAll(/```[\s\S]*?```|~~~[\s\S]*?~~~|`[^`\n]*`|^ {4}[^\n]*|^ {0,3}>[^\n]*/gmu)]
138
+ .map(match => [match.index, match.index + match[0].length]);
139
+ }
140
+ function outsideExamples(text, pattern, replace) {
141
+ const ranges = exampleRanges(text);
142
+ const protectedAt = (offset) => ranges.some(([start, end]) => offset >= start && offset < end);
143
+ let output = "";
144
+ let last = 0;
145
+ for (const match of text.matchAll(pattern)) {
146
+ if (protectedAt(match.index))
147
+ continue;
148
+ output += text.slice(last, match.index) + replace(match);
149
+ last = match.index + match[0].length;
150
+ }
151
+ return output + text.slice(last);
152
+ }
153
+ const annotationTag = annotations.length ? new RegExp(String.raw `<(${annotations.map(envelope => envelope.tag).join("|")})\b[^>]*\/>`, "gu") : undefined;
154
+ /** Replace inline host annotations such as <copilot-ref … /> with their label, outside examples. */
155
+ export function withLabeledAnnotations(text) {
156
+ if (!annotationTag || !text.includes("<"))
157
+ return text;
158
+ return outsideExamples(text, annotationTag, match => {
159
+ const envelope = annotations.find(candidate => candidate.tag === match[1]);
160
+ const attribute = envelope?.labelAttribute ?? "label";
161
+ return new RegExp(String.raw `\b${attribute}=(?:"([^"]*)"|'([^']*)')`, "u").exec(match[0])?.slice(1).find(Boolean) ?? "";
162
+ });
163
+ }
164
+ // A notice anywhere in a message, or one truncated before its closing tag.
165
+ const inlineNotice = new RegExp(String.raw `<(${noticeTags.join("|")})\b[^>]*>(?:[\s\S]*?<\/\1>|[\s\S]*$)`, "gu");
166
+ /** Remove host notices wherever they appear, outside examples. Learning evidence never includes them. */
167
+ export function withoutHostNotices(text) {
168
+ if (!text.includes("<"))
169
+ return text;
170
+ return outsideExamples(text, inlineNotice, () => "");
171
+ }
172
+ const reviewRequestStart = reviewRequests.map(envelope => new RegExp(String.raw `^${leadingBlank}${envelope.heading}`, "u"));
173
+ const briefStart = hostEnvelopes("brief").map(envelope => new RegExp(String.raw `^${leadingBlank}${envelope.heading}(?:[ \t\r\n]+|$)`, "u"));
174
+ // The task heading inside a background-first brief; collapsed legacy titles lost their line breaks.
175
+ const briefTaskHeading = /(?:^|[ \t\r\n])Task(?: \(from the session that started this one\))?:(?:[ \t\r\n]+|$)/u;
176
+ // The folder the desktop app appends for notes between the sessions it started.
177
+ const briefNotesTrailer = /(?:^|[ \t\r\n])Shared notes folder for this group of sessions\b[\s\S]*$/u;
178
+ /**
179
+ * The task from a brief one agent session wrote for another; the background
180
+ * and the notes folder are the host's framing. A brief without a task, such
181
+ * as a stored title cut inside the background, yields "" so callers fall back.
182
+ */
183
+ export function withoutSideSessionBrief(text) {
184
+ const start = briefStart.map(pattern => pattern.exec(text)).find(match => match !== null);
185
+ if (!start)
186
+ return text;
187
+ let body = text.slice(start[0].length);
188
+ if (/^\s*Background/u.test(start[0])) {
189
+ const task = briefTaskHeading.exec(body);
190
+ if (!task)
191
+ return "";
192
+ body = body.slice(task.index + task[0].length);
193
+ }
194
+ body = body.replace(briefNotesTrailer, "").replace(/[ \t\r\n]+$/u, "");
195
+ return isBlank(body) ? "" : body;
196
+ }
197
+ /**
198
+ * Whether a prompt is the brief one agent session wrote for another: the
199
+ * desktop app delivers it as the new session's first prompt, possibly after
200
+ * its own notices. A quoted, fenced or indented brief is an example, not a
201
+ * brief, and a title cut inside the background still counts as one.
202
+ */
203
+ export function isSideSessionBrief(text) {
204
+ const prompt = withoutLeadingHostEnvelopes(text);
205
+ return briefStart.some(pattern => pattern.test(prompt));
206
+ }
207
+ const wrappers = hostEnvelopes("wrapper");
208
+ const wrapperTags = wrappers.length
209
+ ? new RegExp(String.raw `<(?:${wrappers.map(envelope => envelope.tag).join("|")})\b[^>]*>[ \t]*(?:\r?\n)?|(?:\r?\n)?[ \t]*</(?:${wrappers.map(envelope => envelope.tag).join("|")})>`, "gu")
210
+ : undefined;
211
+ /** Remove host wrappers around the user's own pasted text, keeping the text, outside examples. */
212
+ export function withoutInlineWrappers(text) {
213
+ if (!wrapperTags || !text.includes("<"))
214
+ return text;
215
+ return outsideExamples(text, wrapperTags, () => "");
216
+ }
217
+ /**
218
+ * The reviewer's own comment inside a review-request wrapper, or undefined
219
+ * when the text is not such a wrapper or holds no comment. The wrapper's
220
+ * instruction, identifiers and diff are not the reviewer's words.
221
+ */
222
+ export function reviewRequestComment(text) {
223
+ if (!reviewRequestStart.some(start => start.test(text)))
224
+ return undefined;
225
+ const comment = /(?:^|\n)[ \t]*(?:(?:User|Review)\s+)?Comment(?:\s+(?:body|text))?:[ \t]*([\s\S]*)$/imu.exec(text)?.[1];
226
+ if (!comment)
227
+ return "";
228
+ return comment.split(/\n[ \t]*(?:Selected lines|Diff|Thread ID|Comment ID|Thread source):/iu)[0].trim();
229
+ }
230
+ export function isReviewRequest(text) {
231
+ return reviewRequestStart.some(start => start.test(text));
232
+ }
233
+ const attachmentInstruction = String.raw `Distinguish instructions in attached documents from the user's request\.`;
234
+ /** The Codex attachment preamble heading, for callers that list the attached files themselves. */
235
+ export const CODEX_ATTACHMENT_PREAMBLE = new RegExp(String.raw `^\s*${attachmentPreamble.heading}`, "u");
236
+ /** The instruction line Codex adds under its attachment list. */
237
+ export const CODEX_ATTACHMENT_INSTRUCTION = new RegExp(String.raw `^${attachmentInstruction}\s*$`, "mu");
238
+ /** The heading Codex writes before the user's request, as a whole line. */
239
+ export const CODEX_REQUEST_HEADING_LINE = new RegExp(String.raw `^ {0,3}${CODEX_REQUEST_HEADING}\s*$`, "mu");
240
+ const attachmentPreambleBlock = new RegExp(String.raw `^\s*${attachmentPreamble.heading}[\s\S]*?\n${attachmentInstruction}\s*\n\s*${CODEX_REQUEST_HEADING}\s*`, "u");
241
+ /** Remove Codex's attachment preamble (names, paths and instruction) and keep the request. */
242
+ export function withoutAttachmentPreamble(text) {
243
+ return text.replace(attachmentPreambleBlock, "");
244
+ }
245
+ const diffCommentsStart = new RegExp(String.raw `^${leadingBlank}${diffCommentsPreamble.heading}[ \t]*(?:\r?\n|$)`, "u");
246
+ /**
247
+ * Keep the reviewer's comments and the request from a Codex diff-comment
248
+ * prompt; the file, side, line and hunk metadata is the host's framing.
249
+ */
250
+ export function withoutDiffCommentMetadata(text) {
251
+ const start = diffCommentsStart.exec(text);
252
+ if (!start)
253
+ return text;
254
+ const body = text.slice(start[0].length).replace(/\r\n/gu, "\n");
255
+ const headingLine = new RegExp(String.raw `^ {0,3}${CODEX_REQUEST_HEADING}[ \t]*$`, "mu");
256
+ const requestAt = headingLine.exec(body);
257
+ const comments = requestAt ? body.slice(0, requestAt.index) : body;
258
+ const request = requestAt ? body.slice(requestAt.index + requestAt[0].length) : "";
259
+ const parts = comments.split(/^ {0,3}## [^\n]*Comment[^\n]*$/imu).slice(1).map(section => {
260
+ const comment = /(?:^|\n)[ \t]*Comment:[ \t]*\n?([\s\S]*)$/iu.exec(section)?.[1];
261
+ return (comment ?? "").trim();
262
+ }).filter(Boolean);
263
+ const cleaned = [...parts, request.trim()].filter(Boolean).join("\n\n");
264
+ return cleaned || text;
265
+ }
266
+ /**
267
+ * PostgreSQL-portable pattern for a prompt made only of host notices, or a
268
+ * stored title truncated inside one, never a request that quotes one, indents
269
+ * one as code or continues after it. Nested tags close with their own names,
270
+ * so only an outer closing tag followed by whitespace ends the prompt.
271
+ */
272
+ const hostNoticeTag = `(${noticeTags.join("|")})`;
273
+ export const HOST_NOTICE_PROMPT_PATTERN = String.raw `^([ \t]*[\r\n])*[ \t]{0,3}<${hostNoticeTag}(([ \t\r\n][^>]*)?>(.|[\r\n])*(</${hostNoticeTag}>[ \t\r\n]*|…)|[ \t\r\n][^>]*…)$`;
274
+ const hostNoticePrompt = new RegExp(HOST_NOTICE_PROMPT_PATTERN, "i");
275
+ /** Test the recorded prompt itself: display helpers already strip these envelopes. */
276
+ export function isHostNoticePrompt(value) {
277
+ return hostNoticePrompt.test(value);
278
+ }
279
+ /** PostgreSQL-portable optional prefix for Codex's ambient context before an app-generated prompt. */
280
+ export const AMBIENT_CONTEXT_SQL_PREFIX = `(${ambientContexts.map(envelope => String.raw `<${envelope.tag}${envelope.attributes ?? ""}>[\s\S]*?</${envelope.tag}>[ \t\r\n]*` +
281
+ (envelope.requestHeading ? String.raw `(${envelope.requestHeading}[ \t\r\n]*)?` : "")).join("|")})?`;
282
+ //# sourceMappingURL=host-envelopes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-envelopes.js","sourceRoot":"","sources":["../src/host-envelopes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAuCH,yEAAyE;AACzE,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,GAAG,CAAA,gBAAgB,CAAC;AAEhE,MAAM,CAAC,MAAM,cAAc,GAA4B;IACrD,6EAA6E;IAC7E,yEAAyE;IACzE,EAAE,EAAE,EAAE,wBAAwB,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,iBAAiB;QACzF,WAAW,EAAE,oGAAoG,EAAE;IACrH,EAAE,EAAE,EAAE,4BAA4B,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,qBAAqB;QACjG,WAAW,EAAE,4CAA4C,EAAE;IAC7D,EAAE,EAAE,EAAE,yBAAyB,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,kBAAkB;QAC3F,WAAW,EAAE,6FAA6F,EAAE;IAC9G,EAAE,EAAE,EAAE,0BAA0B,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,mBA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G,IAAI,MAAM,CAAC,0BAA0B,EAAE,GAAG,CAAC,CAAC;AAErE,sFAAsF;AACtF,MAAM,UAAU,kBAAkB,CAAC,KAAa;IAC9C,OAAO,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACtC,CAAC;AAED,sGAAsG;AACtG,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAI,eAAe,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAC3E,MAAM,CAAC,GAAG,CAAA,IAAI,QAAQ,CAAC,GAAG,GAAG,QAAQ,CAAC,UAAU,IAAI,EAAE,cAAc,QAAQ,CAAC,GAAG,aAAa;IAC7F,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAA,IAAI,QAAQ,CAAC,cAAc,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,CACrF,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC"}
@@ -1,6 +1,12 @@
1
- import { type InsertMemoryResult, type ListMemoriesDto, type ListMemoriesResponse, type Memory, type MemoryConflict, type MemoryScope, type MemoryUpdate, type ProposalMetadata, type ProposalRecord, type ProposeMemoryResult, type ReviewProposalDto, type ReviewProposalResponse, type UpdateWorkspaceLearningPolicy, type WorkspaceLearningPolicy } from "./schemas.js";
1
+ import { type InsertMemoryResult, type ListMemoriesDto, type ListMemoriesResponse, type Memory, type MemoryConflict, type MemoryScope, type MemoryUpdate, type ProposalMetadata, type ProposalRecord, type ProposeMemoryResult, type ReviewProposalDto, type ReviewProposalResponse, type DeclineStaleProposalsCommand, type DeclineStaleProposalsResponse, type UpdateWorkspaceLearningPolicy, type WorkspaceLearningPolicy } from "./schemas.js";
2
2
  import type { FindActiveCandidatesOptions, InsertMemoryConflictResult, MemoryRepository, RepositoryContext, SupersedeMemoryResult, WorkspaceRepositoryContext } from "./ports.js";
3
3
  export declare function memoryScopeAppliesTo(memoryScope: MemoryScope, taskScope: MemoryScope): boolean;
4
+ /**
5
+ * List filters match stored scope values exactly, except `repo`: a
6
+ * per-repository list also includes workspace-wide learnings (no repo), the
7
+ * same knowledge retrieval delivers for that repository.
8
+ */
9
+ export declare function listScopeMatches(filter: MemoryScope, memoryScope: MemoryScope): boolean;
4
10
  export declare class InMemoryMemoryRepository implements MemoryRepository {
5
11
  #private;
6
12
  constructor(initialMemories?: readonly Memory[]);
@@ -10,6 +16,7 @@ export declare class InMemoryMemoryRepository implements MemoryRepository {
10
16
  getProposal(memoryId: string, context?: RepositoryContext): Promise<ProposalRecord | null>;
11
17
  addProposalConflict(conflictInput: MemoryConflict, context: WorkspaceRepositoryContext): Promise<InsertMemoryConflictResult>;
12
18
  reviewProposal(inputValue: ReviewProposalDto, context: WorkspaceRepositoryContext): Promise<ReviewProposalResponse>;
19
+ declineStaleProposals(inputValue: DeclineStaleProposalsCommand, context: WorkspaceRepositoryContext): Promise<DeclineStaleProposalsResponse>;
13
20
  getRepositoryPolicy(workspaceId: string): Promise<{
14
21
  repositories: string[];
15
22
  mode: "all" | "selected";
@@ -1 +1 @@
1
- {"version":3,"file":"in-memory-repository.d.ts","sourceRoot":"","sources":["../src/in-memory-repository.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,MAAM,EACX,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAC3B,KAAK,6BAA6B,EAClC,KAAK,uBAAuB,EAC7B,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EACV,2BAA2B,EAC3B,0BAA0B,EAC1B,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACrB,0BAA0B,EAC3B,MAAM,YAAY,CAAC;AAmDpB,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,WAAW,EACxB,SAAS,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CAAC,MAAM,GAAG,IAAI,CAAC;IAqEnB,UAAU,CACd,EAAE,EAAE,MAAM,EACV,SAAS,SAA2B,EACpC,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAyBnB,yBAAyB,CAC7B,KAAK,EAAE,WAAW,EAClB,OAAO,GAAE,2BAAgC,GACxC,OAAO,CAAC,MAAM,EAAE,CAAC;IA8Dd,SAAS,CACb,QAAQ,EAAE,MAAM,EAChB,gBAAgB,EAAE,MAAM,EACxB,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,qBAAqB,CAAC;CAqElC"}
1
+ {"version":3,"file":"in-memory-repository.d.ts","sourceRoot":"","sources":["../src/in-memory-repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAUL,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,MAAM,EACX,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAC3B,KAAK,4BAA4B,EACjC,KAAK,6BAA6B,EAClC,KAAK,6BAA6B,EAClC,KAAK,uBAAuB,EAC7B,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EACV,2BAA2B,EAC3B,0BAA0B,EAC1B,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACrB,0BAA0B,EAC3B,MAAM,YAAY,CAAC;AAoDpB,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,WAAW,GACrB,OAAO,CAST;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,WAAW,EACnB,WAAW,EAAE,WAAW,GACvB,OAAO,CAaT;AAMD,qBAAa,wBAAyB,YAAW,gBAAgB;;gBAQnD,eAAe,GAAE,SAAS,MAAM,EAAO;IAkB7C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M,GAAG,IAAI,CAAC;IAqEnB,UAAU,CACd,EAAE,EAAE,MAAM,EACV,SAAS,SAA2B,EACpC,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAyBnB,yBAAyB,CAC7B,KAAK,EAAE,WAAW,EAClB,OAAO,GAAE,2BAAgC,GACxC,OAAO,CAAC,MAAM,EAAE,CAAC;IA8Dd,SAAS,CACb,QAAQ,EAAE,MAAM,EAChB,gBAAgB,EAAE,MAAM,EACxB,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,qBAAqB,CAAC;CAqElC"}
@@ -1,6 +1,7 @@
1
- import { ListMemoriesDtoSchema, MemoryConflictSchema, MemorySchema, MemoryUpdateSchema, ProposalMetadataSchema, ReviewProposalDtoSchema, UpdateWorkspaceLearningPolicySchema, WorkspaceLearningPolicySchema, } from "./schemas.js";
1
+ import { DeclineStaleProposalsCommandSchema, ListMemoriesDtoSchema, MemoryConflictSchema, MemorySchema, MemoryUpdateSchema, ProposalMetadataSchema, ReviewProposalDtoSchema, UpdateWorkspaceLearningPolicySchema, WorkspaceLearningPolicySchema, } from "./schemas.js";
2
2
  import { createMemoryFingerprint } from "./engine.js";
3
3
  import { candidateKeywordScore, memoryNeedsReview } from "./knowledge-quality.js";
4
+ import { repositoryAllowed } from "./repository-policy.js";
4
5
  import { isLearningImprovement, assertImprovementTarget, assertProposalReviewReason, assertWorkspaceWideReview, WorkspaceWideReviewError } from "./learning-governance.js";
5
6
  function copyMemory(memory) {
6
7
  return structuredClone(memory);
@@ -42,6 +43,22 @@ export function memoryScopeAppliesTo(memoryScope, taskScope) {
42
43
  scopeValueMatches(memoryScope.path, taskScope.path) &&
43
44
  scopeValueMatches(memoryScope.component, taskScope.component));
44
45
  }
46
+ /**
47
+ * List filters match stored scope values exactly, except `repo`: a
48
+ * per-repository list also includes workspace-wide learnings (no repo), the
49
+ * same knowledge retrieval delivers for that repository.
50
+ */
51
+ export function listScopeMatches(filter, memoryScope) {
52
+ const exact = (key) => filter[key] === undefined || filter[key] === memoryScope[key];
53
+ return (exact("agent") &&
54
+ exact("organization") &&
55
+ exact("project") &&
56
+ exact("path") &&
57
+ exact("component") &&
58
+ (filter.repo === undefined ||
59
+ memoryScope.repo === undefined ||
60
+ memoryScope.repo === filter.repo));
61
+ }
45
62
  function toArray(value) {
46
63
  return value === undefined ? undefined : Array.isArray(value) ? value : [value];
47
64
  }
@@ -330,6 +347,35 @@ export class InMemoryMemoryRepository {
330
347
  supersededMemory: supersededMemory === null ? null : copyMemory(supersededMemory),
331
348
  };
332
349
  }
350
+ async declineStaleProposals(inputValue, context) {
351
+ const input = DeclineStaleProposalsCommandSchema.parse(inputValue);
352
+ if (context.allowWorkspaceWideReview === false)
353
+ throw new WorkspaceWideReviewError();
354
+ const policy = await this.getRepositoryPolicy(context.workspaceId);
355
+ const cutoff = Date.parse(input.olderThan);
356
+ const decidedAt = new Date().toISOString();
357
+ let declined = 0;
358
+ for (const current of this.#memories.values()) {
359
+ const metadata = this.#proposalMetadata.get(current.id);
360
+ if (current.status !== "proposed" || metadata === undefined || metadata.decision !== null ||
361
+ memoryWorkspaceId(current) !== context.workspaceId || Date.parse(current.createdAt) >= cutoff ||
362
+ !repositoryAllowed(policy, current.scope.repo))
363
+ continue;
364
+ const next = MemorySchema.parse({ ...current, status: "deleted", updatedAt: decidedAt, suppressedAt: null, deletedAt: decidedAt });
365
+ if (reservesFingerprint(current))
366
+ this.#fingerprints.delete(fingerprintKey(current));
367
+ this.#memories.set(next.id, copyMemory(next));
368
+ this.#proposalMetadata.set(next.id, copyProposalMetadata(ProposalMetadataSchema.parse({
369
+ ...metadata, decision: "reject", reviewerId: input.reviewerId, decisionReason: input.reason, decidedAt, decisionTargetMemoryId: null,
370
+ })));
371
+ for (const conflict of this.#proposalConflicts(next.id)) {
372
+ if (conflict.resolution === null)
373
+ this.#conflicts.set(conflict.id, copyConflict(MemoryConflictSchema.parse({ ...conflict, resolution: "reject", resolvedAt: decidedAt })));
374
+ }
375
+ declined += 1;
376
+ }
377
+ return { declined, olderThan: new Date(cutoff).toISOString() };
378
+ }
333
379
  #repositoryPolicies = new Map();
334
380
  async getRepositoryPolicy(workspaceId) {
335
381
  return structuredClone(this.#repositoryPolicies.get(workspaceId) ?? { mode: "all", repositories: [] });
@@ -415,7 +461,7 @@ export class InMemoryMemoryRepository {
415
461
  return false;
416
462
  }
417
463
  if (filters.scope !== undefined &&
418
- !memoryScopeAppliesTo(filters.scope, memory.scope)) {
464
+ !listScopeMatches(filters.scope, memory.scope)) {
419
465
  return false;
420
466
  }
421
467
  if (categories !== undefined &&
@@ -531,7 +577,7 @@ export class InMemoryMemoryRepository {
531
577
  memory.scope.organization === scope.organization &&
532
578
  (options.includeAllAgents === true || scopeValueMatches(memory.scope.agent, scope.agent)) &&
533
579
  scopeValueMatches(memory.scope.project, scope.project) &&
534
- scopeValueMatches(memory.scope.repo, scope.repo) &&
580
+ (options.allRepositories === true || scopeValueMatches(memory.scope.repo, scope.repo)) &&
535
581
  (memory.scope.path === undefined ||
536
582
  paths.some((path) => path === memory.scope.path ||
537
583
  path.startsWith(`${memory.scope.path}/`))) &&