@mmnto/totem 1.34.1 → 1.34.2
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/exporter.d.ts +12 -2
- package/dist/exporter.d.ts.map +1 -1
- package/dist/exporter.js +27 -6
- package/dist/exporter.js.map +1 -1
- package/package.json +1 -1
package/dist/exporter.d.ts
CHANGED
|
@@ -4,8 +4,14 @@ export declare const SENTINEL_END = "<!-- totem:generated:end -->";
|
|
|
4
4
|
/**
|
|
5
5
|
* Format parsed lessons as a markdown block for injection into AI config files.
|
|
6
6
|
* Always generates sentinel markers (even for empty lessons) to preserve idempotency.
|
|
7
|
+
*
|
|
8
|
+
* When `archivedReasonByHash` is provided, lessons whose content-hash is in the
|
|
9
|
+
* map get an `_(archived: <reason>)_` suffix so a reading agent can weight the
|
|
10
|
+
* guidance appropriately. Empty / missing reasons fall back to a plain bullet
|
|
11
|
+
* (Tenet 4 spirit — surface the rule loudly even with degraded metadata).
|
|
12
|
+
* Per mmnto-ai/totem#1873.
|
|
7
13
|
*/
|
|
8
|
-
export declare function formatLessonsAsMarkdown(lessons: ParsedLesson[]): string;
|
|
14
|
+
export declare function formatLessonsAsMarkdown(lessons: ParsedLesson[], archivedReasonByHash?: ReadonlyMap<string, string>): string;
|
|
9
15
|
/**
|
|
10
16
|
* Inject a generated block between sentinel markers in file content.
|
|
11
17
|
* - If sentinels exist: replaces content between them (inclusive)
|
|
@@ -16,6 +22,10 @@ export declare function injectSentinelBlock(existingContent: string, generatedBl
|
|
|
16
22
|
/**
|
|
17
23
|
* Export formatted lessons to a target file path.
|
|
18
24
|
* Creates directories if needed. Uses sentinel-based injection for idempotent updates.
|
|
25
|
+
*
|
|
26
|
+
* When `archivedReasonByHash` is provided, lessons whose content-hash appears
|
|
27
|
+
* in the map render with an `_(archived: <reason>)_` annotation suffix
|
|
28
|
+
* (mmnto-ai/totem#1873).
|
|
19
29
|
*/
|
|
20
|
-
export declare function exportLessons(lessons: ParsedLesson[], targetPath: string): void;
|
|
30
|
+
export declare function exportLessons(lessons: ParsedLesson[], targetPath: string, archivedReasonByHash?: ReadonlyMap<string, string>): void;
|
|
21
31
|
//# sourceMappingURL=exporter.d.ts.map
|
package/dist/exporter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exporter.d.ts","sourceRoot":"","sources":["../src/exporter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"exporter.d.ts","sourceRoot":"","sources":["../src/exporter.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAKxD,eAAO,MAAM,cAAc,mCAAmC,CAAC;AAC/D,eAAO,MAAM,YAAY,iCAAiC,CAAC;AAI3D;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,YAAY,EAAE,EACvB,oBAAoB,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GACjD,MAAM,CA6BR;AAID;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,eAAe,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,CA6B3F;AAID;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,YAAY,EAAE,EACvB,UAAU,EAAE,MAAM,EAClB,oBAAoB,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GACjD,IAAI,CAeN"}
|
package/dist/exporter.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as fs from 'node:fs';
|
|
2
2
|
import * as path from 'node:path';
|
|
3
|
+
import { hashLesson } from './compiler.js';
|
|
3
4
|
import { TotemParseError } from './errors.js';
|
|
4
5
|
// ─── Constants ─────────────────────────────────────────
|
|
5
6
|
export const SENTINEL_START = '<!-- totem:generated:start -->';
|
|
@@ -8,8 +9,14 @@ export const SENTINEL_END = '<!-- totem:generated:end -->';
|
|
|
8
9
|
/**
|
|
9
10
|
* Format parsed lessons as a markdown block for injection into AI config files.
|
|
10
11
|
* Always generates sentinel markers (even for empty lessons) to preserve idempotency.
|
|
12
|
+
*
|
|
13
|
+
* When `archivedReasonByHash` is provided, lessons whose content-hash is in the
|
|
14
|
+
* map get an `_(archived: <reason>)_` suffix so a reading agent can weight the
|
|
15
|
+
* guidance appropriately. Empty / missing reasons fall back to a plain bullet
|
|
16
|
+
* (Tenet 4 spirit — surface the rule loudly even with degraded metadata).
|
|
17
|
+
* Per mmnto-ai/totem#1873.
|
|
11
18
|
*/
|
|
12
|
-
export function formatLessonsAsMarkdown(lessons) {
|
|
19
|
+
export function formatLessonsAsMarkdown(lessons, archivedReasonByHash) {
|
|
13
20
|
const lines = [
|
|
14
21
|
SENTINEL_START,
|
|
15
22
|
'<!-- Auto-generated by `totem compile --export`. Do not edit between these markers. -->',
|
|
@@ -17,12 +24,22 @@ export function formatLessonsAsMarkdown(lessons) {
|
|
|
17
24
|
'## Totem Project Rules',
|
|
18
25
|
'',
|
|
19
26
|
];
|
|
27
|
+
const escapeMarkdown = (s) => s.replace(/[*_]/g, '\\$&');
|
|
28
|
+
// Strip C0 control bytes (incl. CR/LF/TAB) so an archivedReason copied
|
|
29
|
+
// from an operator's terminal session cannot break the bullet shape or
|
|
30
|
+
// bleed across lines. Mirrors the sanitizing discipline applied to
|
|
31
|
+
// lesson body content above (per CR mmnto-ai/totem#1878).
|
|
32
|
+
const sanitizeReason = (s) => escapeMarkdown(s.replace(/[\x00-\x1F\x7F]/g, ' ').trim());
|
|
20
33
|
for (const lesson of lessons) {
|
|
21
|
-
const escapeMarkdown = (s) => s.replace(/[*_]/g, '\\$&');
|
|
22
34
|
const heading = escapeMarkdown(lesson.heading);
|
|
23
35
|
const bodyOneLine = escapeMarkdown(lesson.body.replace(/\n+/g, ' ').trim());
|
|
24
|
-
const
|
|
25
|
-
|
|
36
|
+
const tagSuffix = lesson.tags.length > 0 ? ` _(${lesson.tags.join(', ')})_` : '';
|
|
37
|
+
const rawReason = archivedReasonByHash
|
|
38
|
+
? archivedReasonByHash.get(hashLesson(lesson.heading, lesson.body))
|
|
39
|
+
: undefined;
|
|
40
|
+
const cleanedReason = rawReason ? sanitizeReason(rawReason) : '';
|
|
41
|
+
const archivedSuffix = cleanedReason ? ` _(archived: ${cleanedReason})_` : '';
|
|
42
|
+
lines.push(`- **${heading}** - ` + bodyOneLine + tagSuffix + archivedSuffix);
|
|
26
43
|
}
|
|
27
44
|
lines.push('', SENTINEL_END);
|
|
28
45
|
return lines.join('\n');
|
|
@@ -60,13 +77,17 @@ export function injectSentinelBlock(existingContent, generatedBlock) {
|
|
|
60
77
|
/**
|
|
61
78
|
* Export formatted lessons to a target file path.
|
|
62
79
|
* Creates directories if needed. Uses sentinel-based injection for idempotent updates.
|
|
80
|
+
*
|
|
81
|
+
* When `archivedReasonByHash` is provided, lessons whose content-hash appears
|
|
82
|
+
* in the map render with an `_(archived: <reason>)_` annotation suffix
|
|
83
|
+
* (mmnto-ai/totem#1873).
|
|
63
84
|
*/
|
|
64
|
-
export function exportLessons(lessons, targetPath) {
|
|
85
|
+
export function exportLessons(lessons, targetPath, archivedReasonByHash) {
|
|
65
86
|
const dir = path.dirname(targetPath);
|
|
66
87
|
if (!fs.existsSync(dir)) {
|
|
67
88
|
fs.mkdirSync(dir, { recursive: true });
|
|
68
89
|
}
|
|
69
|
-
const generatedBlock = formatLessonsAsMarkdown(lessons);
|
|
90
|
+
const generatedBlock = formatLessonsAsMarkdown(lessons, archivedReasonByHash);
|
|
70
91
|
if (fs.existsSync(targetPath)) {
|
|
71
92
|
const existing = fs.readFileSync(targetPath, 'utf-8');
|
|
72
93
|
const updated = injectSentinelBlock(existing, generatedBlock);
|
package/dist/exporter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exporter.js","sourceRoot":"","sources":["../src/exporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC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