@chenhw7/dsh-memory 0.5.1 → 0.7.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.
- package/README.md +16 -8
- package/README.zh-CN.md +15 -8
- package/cordis.patch.yml +5 -3
- package/lib/client/index.js +10 -22
- package/lib/context/index.d.ts +2 -6
- package/lib/context/index.d.ts.map +1 -1
- package/lib/context/index.js +17 -20
- package/lib/context/index.js.map +1 -1
- package/lib/context/policy.d.ts +5 -5
- package/lib/context/policy.d.ts.map +1 -1
- package/lib/context/policy.js +5 -5
- package/lib/context/policy.js.map +1 -1
- package/lib/notes/cleanup.d.ts +42 -0
- package/lib/notes/cleanup.d.ts.map +1 -0
- package/lib/notes/cleanup.js +93 -0
- package/lib/notes/cleanup.js.map +1 -0
- package/lib/notes/index.d.ts +21 -23
- package/lib/notes/index.d.ts.map +1 -1
- package/lib/notes/index.js +32 -130
- package/lib/notes/index.js.map +1 -1
- package/lib/notes/render.d.ts +13 -13
- package/lib/notes/render.d.ts.map +1 -1
- package/lib/notes/render.js +13 -13
- package/lib/notes/render.js.map +1 -1
- package/lib/notes/scope.d.ts +7 -6
- package/lib/notes/scope.d.ts.map +1 -1
- package/lib/notes/scope.js +7 -6
- package/lib/notes/scope.js.map +1 -1
- package/lib/notes/settings.d.ts +9 -20
- package/lib/notes/settings.d.ts.map +1 -1
- package/lib/notes/settings.js +9 -27
- package/lib/notes/settings.js.map +1 -1
- package/lib/review/accumulator.d.ts +4 -4
- package/lib/review/accumulator.d.ts.map +1 -1
- package/lib/review/accumulator.js +2 -2
- package/lib/review/accumulator.js.map +1 -1
- package/lib/review/index.d.ts.map +1 -1
- package/lib/review/index.js +14 -12
- package/lib/review/index.js.map +1 -1
- package/lib/tool/index.d.ts.map +1 -1
- package/lib/tool/index.js +2 -3
- package/lib/tool/index.js.map +1 -1
- package/package.json +30 -30
- package/lib/notes/writer.d.ts +0 -65
- package/lib/notes/writer.d.ts.map +0 -1
- package/lib/notes/writer.js +0 -131
- package/lib/notes/writer.js.map +0 -1
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One-time cleanup of legacy on-repo artifacts from the file-export era
|
|
3
|
+
* (≤ 0.5.x): the rendered notes files and the managed AGENTS.md pointer
|
|
4
|
+
* block. dsh-memory 0.6+ never writes into the user's project; this module
|
|
5
|
+
* only REMOVES what earlier versions left behind, under conservative rules:
|
|
6
|
+
*
|
|
7
|
+
* - AGENTS.md: only the managed marker block is stripped — every byte outside
|
|
8
|
+
* the markers is preserved. When nothing but the block (plus whitespace)
|
|
9
|
+
* remains, the file is deleted: it was the pointer-only file we created.
|
|
10
|
+
* - Notes directory (≤0.5.x default `docs/agent-memory`): only the files we
|
|
11
|
+
* generated — `CONVENTIONS.md`, `PITFALLS.md`, and their `.bak.<ts>` drift
|
|
12
|
+
* backups — are deleted; foreign files keep the directory alive.
|
|
13
|
+
*
|
|
14
|
+
* Best-effort by design: every failure is swallowed, every action is logged
|
|
15
|
+
* once. Idempotent — a second run finds nothing to do. The user's
|
|
16
|
+
* `.gitignore` is never touched.
|
|
17
|
+
*
|
|
18
|
+
* @module @chenhw7/dsh-memory/notes/cleanup
|
|
19
|
+
*/
|
|
20
|
+
import { readdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
21
|
+
import path from 'node:path';
|
|
22
|
+
/** Marker opening the managed pointer block a ≤0.5.x install wrote into AGENTS.md. */
|
|
23
|
+
export const AGENTS_POINTER_BEGIN = '<!-- dsh-memory:begin -->';
|
|
24
|
+
/** Marker closing the managed pointer block. */
|
|
25
|
+
export const AGENTS_POINTER_END = '<!-- dsh-memory:end -->';
|
|
26
|
+
/** The default notes dir location ≤0.5.x exported to (custom notesDir values are not recoverable here). */
|
|
27
|
+
export const LEGACY_NOTES_DIR = path.join('docs', 'agent-memory');
|
|
28
|
+
/** Files a ≤0.5.x install generated into the notes dir (name, not path). */
|
|
29
|
+
const GENERATED_FILE = /^(CONVENTIONS|PITFALLS)\.md(\.bak\.\d+)?$/;
|
|
30
|
+
/**
|
|
31
|
+
* Strip the managed pointer block from AGENTS.md content. Everything outside
|
|
32
|
+
* the markers is returned untouched; content without a complete marker pair
|
|
33
|
+
* is returned unchanged.
|
|
34
|
+
* @param content - the AGENTS.md text.
|
|
35
|
+
* @returns the text without the managed block.
|
|
36
|
+
*/
|
|
37
|
+
export function stripAgentsPointerBlock(content) {
|
|
38
|
+
const begin = content.indexOf(AGENTS_POINTER_BEGIN);
|
|
39
|
+
if (begin < 0)
|
|
40
|
+
return content;
|
|
41
|
+
const end = content.indexOf(AGENTS_POINTER_END, begin);
|
|
42
|
+
if (end < 0)
|
|
43
|
+
return content;
|
|
44
|
+
return content.slice(0, begin) + content.slice(end + AGENTS_POINTER_END.length);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Remove the repo artifacts a ≤0.5.x install left in one project: the managed
|
|
48
|
+
* AGENTS.md pointer block and the generated files under the default notes
|
|
49
|
+
* dir. Idempotent, best-effort, and chatty (one log line per action) — see
|
|
50
|
+
* the module docs for the exact safety rules.
|
|
51
|
+
* @param projectRoot - absolute path of the project root (session cwd).
|
|
52
|
+
*/
|
|
53
|
+
export async function cleanupLegacyNotesArtifacts(projectRoot) {
|
|
54
|
+
await cleanupAgentsPointer(projectRoot);
|
|
55
|
+
await cleanupNotesDir(projectRoot);
|
|
56
|
+
}
|
|
57
|
+
/** Strip (or delete) the legacy AGENTS.md pointer block in one project root. */
|
|
58
|
+
async function cleanupAgentsPointer(projectRoot) {
|
|
59
|
+
const agentsPath = path.join(projectRoot, 'AGENTS.md');
|
|
60
|
+
const existing = await readFile(agentsPath, 'utf8').catch(() => undefined);
|
|
61
|
+
if (existing === undefined || !existing.includes(AGENTS_POINTER_BEGIN))
|
|
62
|
+
return;
|
|
63
|
+
const stripped = stripAgentsPointerBlock(existing);
|
|
64
|
+
if (stripped.trim().length === 0) {
|
|
65
|
+
await rm(agentsPath).catch(() => { });
|
|
66
|
+
console.log('[dsh-memory] removed the pointer-only AGENTS.md left by ≤0.5.x in this project (memory is now managed in the host store + Memory UI only).');
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
await writeFile(agentsPath, stripped, 'utf8').catch(() => { });
|
|
70
|
+
console.log('[dsh-memory] stripped the managed dsh-memory pointer block from AGENTS.md (other content untouched).');
|
|
71
|
+
}
|
|
72
|
+
/** Delete the generated files (only those) under the legacy notes dir. */
|
|
73
|
+
async function cleanupNotesDir(projectRoot) {
|
|
74
|
+
const notesDir = path.join(projectRoot, LEGACY_NOTES_DIR);
|
|
75
|
+
const names = await readdir(notesDir).catch(() => undefined);
|
|
76
|
+
if (names === undefined)
|
|
77
|
+
return;
|
|
78
|
+
let removed = 0;
|
|
79
|
+
for (const name of names) {
|
|
80
|
+
if (!GENERATED_FILE.test(name))
|
|
81
|
+
continue;
|
|
82
|
+
await rm(path.join(notesDir, name), { force: true }).catch(() => { });
|
|
83
|
+
removed++;
|
|
84
|
+
}
|
|
85
|
+
const rest = await readdir(notesDir).catch(() => []);
|
|
86
|
+
if (rest.length === 0) {
|
|
87
|
+
await rm(notesDir, { recursive: true, force: true }).catch(() => { });
|
|
88
|
+
}
|
|
89
|
+
if (removed > 0) {
|
|
90
|
+
console.log(`[dsh-memory] removed ${removed} generated notes file(s) under ${LEGACY_NOTES_DIR}/ left by ≤0.5.x (the memory store remains the source of truth).`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=cleanup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cleanup.js","sourceRoot":"","sources":["../../src/notes/cleanup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACnE,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,sFAAsF;AACtF,MAAM,CAAC,MAAM,oB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A;IACpD,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,MAAM,EAAE,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;IACtE,CAAC;IACD,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;QAChB,OAAO,CAAC,GAAG,CAAC,wBAAwB,OAAO,kCAAkC,gBAAgB,kEAAkE,CAAC,CAAA;IAClK,CAAC;AACH,CAAC"}
|
package/lib/notes/index.d.ts
CHANGED
|
@@ -1,51 +1,49 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `@chenhw7/dsh-memory/notes`: the project-notes
|
|
2
|
+
* `@chenhw7/dsh-memory/notes`: the project-notes projection (docs/PROJECT_NOTES.zh-CN.md).
|
|
3
3
|
* A function plugin that renders habit/convention/pitfall entries from the
|
|
4
|
-
* memory store into
|
|
5
|
-
*
|
|
4
|
+
* memory store into the `project-notes` system-prompt section. Since 0.6 it
|
|
5
|
+
* writes NOTHING into the user's project — the store is the sole source of
|
|
6
|
+
* truth, the Memory settings UI is the management surface, and the one-time
|
|
7
|
+
* `cleanup` pass removes artifacts left by ≤0.5.x file exports.
|
|
6
8
|
*
|
|
7
|
-
* The store is the source of truth; the files are a read-only rendered view.
|
|
8
9
|
* Rendering is synchronous from the store's in-memory state — the same text
|
|
9
|
-
*
|
|
10
|
-
* into its per-session prompt snapshot, so prompt and files can never drift.
|
|
11
|
-
* Persistence is skipped when nothing changed since the last render.
|
|
10
|
+
* `memory-context` freezes into its per-session prompt snapshot.
|
|
12
11
|
*
|
|
13
12
|
* @module @chenhw7/dsh-memory/notes
|
|
14
13
|
*/
|
|
15
14
|
import type { Context } from '@deepseek-ai/cordis';
|
|
16
15
|
export { isRenderedEntry } from './scope.ts';
|
|
17
16
|
export { renderConventions, renderPitfalls } from './render.ts';
|
|
18
|
-
export {
|
|
19
|
-
export { resolveNotesSettings, DEFAULT_NOTES_ENABLED,
|
|
17
|
+
export { cleanupLegacyNotesArtifacts, stripAgentsPointerBlock, AGENTS_POINTER_BEGIN, AGENTS_POINTER_END, LEGACY_NOTES_DIR } from './cleanup.ts';
|
|
18
|
+
export { resolveNotesSettings, DEFAULT_NOTES_ENABLED, DEFAULT_NOTES_CHAR_LIMIT, DEFAULT_NOTES_MAX_ENTRIES_PER_FILE } from './settings.ts';
|
|
20
19
|
export type { NotesSettings } from './settings.ts';
|
|
21
20
|
/** Cordis plugin name. */
|
|
22
21
|
export declare const name = "memory-notes";
|
|
23
22
|
/** Nothing is required: `memory` and `settings` are accessed optionally. */
|
|
24
23
|
export declare const inject: string[];
|
|
25
24
|
/**
|
|
26
|
-
* Frozen project-notes content for one project root: the rendered
|
|
27
|
-
* Empty strings mean "nothing to
|
|
28
|
-
*
|
|
25
|
+
* Frozen project-notes content for one project root: the rendered section
|
|
26
|
+
* texts, injected into the system prompt. Empty strings mean "nothing to
|
|
27
|
+
* inject" (disabled or no store); without a cwd the project-scope slice is
|
|
28
|
+
* absent but the global/user slices still render.
|
|
29
29
|
*/
|
|
30
30
|
export interface ProjectNotesSnapshot {
|
|
31
|
-
/** Rendered
|
|
31
|
+
/** Rendered conventions section (possibly only the header). */
|
|
32
32
|
readonly conventions: string;
|
|
33
|
-
/** Rendered
|
|
33
|
+
/** Rendered pitfalls section (possibly only the header). */
|
|
34
34
|
readonly pitfalls: string;
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* The project-notes service, registered on `ctx.projectNotes` by this plugin.
|
|
38
|
-
* Consumers (memory-context and
|
|
39
|
-
* read through it.
|
|
38
|
+
* Consumers (memory-context) render and read through it. Pure — no I/O.
|
|
40
39
|
*/
|
|
41
40
|
export declare abstract class ProjectNotesService {
|
|
42
41
|
constructor();
|
|
43
42
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* nothing is persisted, but the global/user slices still render.
|
|
43
|
+
* Render and return the notes snapshot for a project root from the store.
|
|
44
|
+
* Idempotent and side-effect free. An undefined `cwd` means "no current
|
|
45
|
+
* project": project-scope entries drop out of the snapshot, but the
|
|
46
|
+
* global/user slices still render.
|
|
49
47
|
* @param cwd - the session working directory (project root), or undefined.
|
|
50
48
|
* @returns the rendered snapshot; empty strings when disabled or unavailable.
|
|
51
49
|
*/
|
|
@@ -58,8 +56,8 @@ declare module '@deepseek-ai/cordis' {
|
|
|
58
56
|
}
|
|
59
57
|
/**
|
|
60
58
|
* Install the memory-notes plugin: register the `projectNotes` service and
|
|
61
|
-
* the
|
|
62
|
-
*
|
|
59
|
+
* the one-time legacy-artifact cleanup on `session/created` (≤0.5.x wrote
|
|
60
|
+
* rendered files + an AGENTS.md pointer into the repo; 0.6 removes them).
|
|
63
61
|
* @param ctx - Cordis context.
|
|
64
62
|
*/
|
|
65
63
|
export declare function apply(ctx: Context): void;
|
package/lib/notes/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/notes/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/notes/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAYlD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAC5C,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC/D,OAAO,EAAE,2BAA2B,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/I,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,kCAAkC,EAAE,MAAM,eAAe,CAAA;AACzI,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAElD,0BAA0B;AAC1B,eAAO,MAAM,IAAI,iBAAiB,CAAA;AAElC,4EAA4E;AAC5E,eAAO,MAAM,MAAM,EAAE,MAAM,EAAO,CAAA;AAKlC;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC,+DAA+D;IAC/D,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,4DAA4D;IAC5D,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAC1B;AAKD;;;GAGG;AACH,8BAAsB,mBAAmB;IACvC,cAIC;IAED;;;;;;;OAOG;IACH,QAAQ,CAAC,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,oBAAoB,CAAA;CACpE;AAED,OAAO,QAAQ,qBAAqB,CAAC;IACnC,UAAU,OAAO;QACf,YAAY,EAAE,mBAAmB,CAAA;KAClC;CACF;AAsDD;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAqBxC"}
|
package/lib/notes/index.js
CHANGED
|
@@ -1,42 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `@chenhw7/dsh-memory/notes`: the project-notes
|
|
2
|
+
* `@chenhw7/dsh-memory/notes`: the project-notes projection (docs/PROJECT_NOTES.zh-CN.md).
|
|
3
3
|
* A function plugin that renders habit/convention/pitfall entries from the
|
|
4
|
-
* memory store into
|
|
5
|
-
*
|
|
4
|
+
* memory store into the `project-notes` system-prompt section. Since 0.6 it
|
|
5
|
+
* writes NOTHING into the user's project — the store is the sole source of
|
|
6
|
+
* truth, the Memory settings UI is the management surface, and the one-time
|
|
7
|
+
* `cleanup` pass removes artifacts left by ≤0.5.x file exports.
|
|
6
8
|
*
|
|
7
|
-
* The store is the source of truth; the files are a read-only rendered view.
|
|
8
9
|
* Rendering is synchronous from the store's in-memory state — the same text
|
|
9
|
-
*
|
|
10
|
-
* into its per-session prompt snapshot, so prompt and files can never drift.
|
|
11
|
-
* Persistence is skipped when nothing changed since the last render.
|
|
10
|
+
* `memory-context` freezes into its per-session prompt snapshot.
|
|
12
11
|
*
|
|
13
12
|
* @module @chenhw7/dsh-memory/notes
|
|
14
13
|
*/
|
|
15
|
-
import { settingsNamespace } from '@deepseek-ai/dsh-settings';
|
|
16
|
-
import path from 'node:path';
|
|
17
14
|
import { scanContent } from '../scanner.js';
|
|
18
15
|
import { isRenderedEntry } from './scope.js';
|
|
19
16
|
import { renderConventions, renderPitfalls } from './render.js';
|
|
20
|
-
import {
|
|
21
|
-
import { resolveNotesSettings
|
|
17
|
+
import { cleanupLegacyNotesArtifacts } from './cleanup.js';
|
|
18
|
+
import { resolveNotesSettings } from './settings.js';
|
|
22
19
|
export { isRenderedEntry } from './scope.js';
|
|
23
20
|
export { renderConventions, renderPitfalls } from './render.js';
|
|
24
|
-
export {
|
|
25
|
-
export { resolveNotesSettings, DEFAULT_NOTES_ENABLED,
|
|
21
|
+
export { cleanupLegacyNotesArtifacts, stripAgentsPointerBlock, AGENTS_POINTER_BEGIN, AGENTS_POINTER_END, LEGACY_NOTES_DIR } from './cleanup.js';
|
|
22
|
+
export { resolveNotesSettings, DEFAULT_NOTES_ENABLED, DEFAULT_NOTES_CHAR_LIMIT, DEFAULT_NOTES_MAX_ENTRIES_PER_FILE } from './settings.js';
|
|
26
23
|
/** Cordis plugin name. */
|
|
27
24
|
export const name = 'memory-notes';
|
|
28
25
|
/** Nothing is required: `memory` and `settings` are accessed optionally. */
|
|
29
26
|
export const inject = [];
|
|
30
27
|
/** The settings namespace owned by `memory-context`, read here defensively. */
|
|
31
|
-
const MEMORY_NS =
|
|
32
|
-
/** Debounce window for activity-triggered re-renders, in milliseconds. */
|
|
33
|
-
const RENDER_DEBOUNCE_MS = 2_000;
|
|
28
|
+
const MEMORY_NS = 'memory';
|
|
34
29
|
/** The empty snapshot. */
|
|
35
30
|
const EMPTY_SNAPSHOT = { conventions: '', pitfalls: '' };
|
|
36
31
|
/**
|
|
37
32
|
* The project-notes service, registered on `ctx.projectNotes` by this plugin.
|
|
38
|
-
* Consumers (memory-context and
|
|
39
|
-
* read through it.
|
|
33
|
+
* Consumers (memory-context) render and read through it. Pure — no I/O.
|
|
40
34
|
*/
|
|
41
35
|
export class ProjectNotesService {
|
|
42
36
|
constructor() {
|
|
@@ -54,16 +48,6 @@ function projectNameOf(cwd) {
|
|
|
54
48
|
class ProjectNotesServiceImpl extends ProjectNotesService {
|
|
55
49
|
ctx;
|
|
56
50
|
settings;
|
|
57
|
-
/** Last persisted file texts per notes dir, for skip-if-unchanged and drift detection. */
|
|
58
|
-
persisted = new Map();
|
|
59
|
-
/** Set to true when a drift error was already reported for this dir (log-once). */
|
|
60
|
-
driftReported = new Set();
|
|
61
|
-
/** Last store health timestamp already rendered, for the dirty check. */
|
|
62
|
-
renderedHealthTs;
|
|
63
|
-
/** notesDir values already reported as escaping the project root (log-once). */
|
|
64
|
-
traversalReported = new Set();
|
|
65
|
-
/** Debounce timer for activity-triggered re-renders. */
|
|
66
|
-
timer;
|
|
67
51
|
constructor(ctx, settings) {
|
|
68
52
|
super();
|
|
69
53
|
this.ctx = ctx;
|
|
@@ -77,20 +61,19 @@ class ProjectNotesServiceImpl extends ProjectNotesService {
|
|
|
77
61
|
return EMPTY_SNAPSHOT;
|
|
78
62
|
}
|
|
79
63
|
// No cwd → there is no current project, so project-scope entries drop
|
|
80
|
-
// out, but the global/user slices still render
|
|
81
|
-
// (there is no project root to write the files into).
|
|
64
|
+
// out, but the global/user slices still render.
|
|
82
65
|
const projectName = cwd === undefined || cwd.length === 0 ? undefined : projectNameOf(cwd);
|
|
83
66
|
const conventions = [];
|
|
84
67
|
const pitfalls = [];
|
|
85
68
|
for (const entry of memory.list()) {
|
|
86
69
|
// Load-time guard: entries that fail the scanner never reach the
|
|
87
|
-
// exported
|
|
88
|
-
//
|
|
89
|
-
//
|
|
90
|
-
//
|
|
70
|
+
// exported section (which feeds future injections). Unlike the prompt
|
|
71
|
+
// surfaces there is no placeholder here — an omitted section entry is
|
|
72
|
+
// simply absent; the store keeps the original for user inspection and
|
|
73
|
+
// removal.
|
|
91
74
|
if (!scanContent(entry.content).allowed)
|
|
92
75
|
continue;
|
|
93
|
-
// Soft-decayed entries drop out of every standing view,
|
|
76
|
+
// Soft-decayed entries drop out of every standing view, this one included.
|
|
94
77
|
if (entry.staleSince !== undefined)
|
|
95
78
|
continue;
|
|
96
79
|
const kind = isRenderedEntry(entry, projectName);
|
|
@@ -99,103 +82,20 @@ class ProjectNotesServiceImpl extends ProjectNotesService {
|
|
|
99
82
|
else if (kind === 'pitfalls')
|
|
100
83
|
pitfalls.push(entry);
|
|
101
84
|
}
|
|
102
|
-
|
|
85
|
+
return {
|
|
103
86
|
conventions: renderConventions(conventions, settings.notesMaxEntriesPerFile),
|
|
104
87
|
pitfalls: renderPitfalls(pitfalls, settings.notesMaxEntriesPerFile),
|
|
105
88
|
};
|
|
106
|
-
if (cwd !== undefined && cwd.length > 0)
|
|
107
|
-
this.persist(cwd, snapshot, settings);
|
|
108
|
-
this.renderedHealthTs = memory.health().lastActivityTs;
|
|
109
|
-
return snapshot;
|
|
110
89
|
}
|
|
111
90
|
catch {
|
|
112
91
|
return EMPTY_SNAPSHOT;
|
|
113
92
|
}
|
|
114
93
|
}
|
|
115
|
-
/** Render + persist only when the store changed since the last render. */
|
|
116
|
-
reconcileIfStale(cwd) {
|
|
117
|
-
const memory = this.ctx.get('memory');
|
|
118
|
-
if (memory === undefined)
|
|
119
|
-
return;
|
|
120
|
-
const ts = memory.health().lastActivityTs;
|
|
121
|
-
if (ts === undefined || ts === this.renderedHealthTs)
|
|
122
|
-
return;
|
|
123
|
-
if (this.timer !== undefined)
|
|
124
|
-
clearTimeout(this.timer);
|
|
125
|
-
this.timer = setTimeout(() => {
|
|
126
|
-
this.timer = undefined;
|
|
127
|
-
try {
|
|
128
|
-
this.snapshotFor(cwd);
|
|
129
|
-
}
|
|
130
|
-
catch {
|
|
131
|
-
// Best-effort: a re-render failure never propagates.
|
|
132
|
-
}
|
|
133
|
-
}, RENDER_DEBOUNCE_MS);
|
|
134
|
-
}
|
|
135
|
-
/** Persist the snapshot atomically when it differs from the last write. */
|
|
136
|
-
persist(cwd, snapshot, settings) {
|
|
137
|
-
const dir = resolveNotesDir(cwd, settings.notesDir);
|
|
138
|
-
if (dir === undefined) {
|
|
139
|
-
// Containment: an escaping notesDir must never direct writes outside
|
|
140
|
-
// the project. Rendered snapshots keep flowing to the prompt; only the
|
|
141
|
-
// file persistence is skipped.
|
|
142
|
-
if (!this.traversalReported.has(settings.notesDir)) {
|
|
143
|
-
this.traversalReported.add(settings.notesDir);
|
|
144
|
-
console.warn(`[dsh-memory] notesDir "${settings.notesDir}" resolves outside the project root; skipping notes persistence for it.`);
|
|
145
|
-
}
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
const previous = this.persisted.get(dir);
|
|
149
|
-
if (previous !== undefined && previous.conventions === snapshot.conventions && previous.pitfalls === snapshot.pitfalls) {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
void (async () => {
|
|
153
|
-
try {
|
|
154
|
-
await writeNotesFile(path.join(dir, 'CONVENTIONS.md'), snapshot.conventions, previous?.conventions);
|
|
155
|
-
await writeNotesFile(path.join(dir, 'PITFALLS.md'), snapshot.pitfalls, previous?.pitfalls);
|
|
156
|
-
if (settings.notesAgentsPointer) {
|
|
157
|
-
await ensureAgentsPointer(path.join(cwd, 'AGENTS.md'), settings.notesDir);
|
|
158
|
-
}
|
|
159
|
-
// Only after a successful write: record this snapshot as the drift
|
|
160
|
-
// baseline so the next write can detect external modifications.
|
|
161
|
-
this.persisted.set(dir, snapshot);
|
|
162
|
-
}
|
|
163
|
-
catch (error) {
|
|
164
|
-
if (error instanceof DriftError) {
|
|
165
|
-
// Drift: external modification was backed up to `.bak.<ts>`;
|
|
166
|
-
// the store remains the source of truth and the in-memory
|
|
167
|
-
// snapshot continues to be served. Update the baseline to the
|
|
168
|
-
// drifted on-disk content so the NEXT persist attempt can write
|
|
169
|
-
// fresh content (the drift has been "absorbed" as the new base).
|
|
170
|
-
try {
|
|
171
|
-
const { readFile } = await import('node:fs/promises');
|
|
172
|
-
const driftedConventions = await readFile(path.join(dir, 'CONVENTIONS.md'), 'utf8').catch(() => undefined);
|
|
173
|
-
const driftedPitfalls = await readFile(path.join(dir, 'PITFALLS.md'), 'utf8').catch(() => undefined);
|
|
174
|
-
if (driftedConventions !== undefined || driftedPitfalls !== undefined) {
|
|
175
|
-
this.persisted.set(dir, {
|
|
176
|
-
conventions: driftedConventions ?? previous?.conventions ?? '',
|
|
177
|
-
pitfalls: driftedPitfalls ?? previous?.pitfalls ?? '',
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
catch { /* best-effort */ }
|
|
182
|
-
// Report once per notes dir so the log is not spammed on every
|
|
183
|
-
// reconcile cycle; the user should reconcile the .bak file.
|
|
184
|
-
if (!this.driftReported.has(dir)) {
|
|
185
|
-
this.driftReported.add(dir);
|
|
186
|
-
console.warn(`[dsh-memory] ${error.message}. The in-memory snapshot continues to be served; resolve the drift by reviewing the .bak file and re-saving via memory tools.`);
|
|
187
|
-
}
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
// Best-effort: persistence failures never surface to the session.
|
|
191
|
-
}
|
|
192
|
-
})();
|
|
193
|
-
}
|
|
194
94
|
}
|
|
195
95
|
/**
|
|
196
96
|
* Install the memory-notes plugin: register the `projectNotes` service and
|
|
197
|
-
* the
|
|
198
|
-
*
|
|
97
|
+
* the one-time legacy-artifact cleanup on `session/created` (≤0.5.x wrote
|
|
98
|
+
* rendered files + an AGENTS.md pointer into the repo; 0.6 removes them).
|
|
199
99
|
* @param ctx - Cordis context.
|
|
200
100
|
*/
|
|
201
101
|
export function apply(ctx) {
|
|
@@ -209,14 +109,16 @@ export function apply(ctx) {
|
|
|
209
109
|
};
|
|
210
110
|
const service = new ProjectNotesServiceImpl(ctx, settings);
|
|
211
111
|
ctx.provide('projectNotes', service);
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
112
|
+
// One-time migration: strip the file-export artifacts a ≤0.5.x install
|
|
113
|
+
// left in this project (marker-managed AGENTS.md block, generated notes
|
|
114
|
+
// files). Once per project root per process; idempotent, best-effort.
|
|
115
|
+
const cleanedRoots = new Set();
|
|
116
|
+
ctx.on('session/created', (session) => {
|
|
117
|
+
const cwd = session.header?.cwd;
|
|
118
|
+
if (cwd === undefined || cwd.length === 0 || cleanedRoots.has(cwd))
|
|
119
|
+
return;
|
|
120
|
+
cleanedRoots.add(cwd);
|
|
121
|
+
void cleanupLegacyNotesArtifacts(cwd).catch(() => { });
|
|
122
|
+
}, { global: true });
|
|
221
123
|
}
|
|
222
124
|
//# sourceMappingURL=index.js.map
|
package/lib/notes/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/notes/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/notes/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAOH,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAC5C,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC/D,OAAO,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAA;AAC1D,OAAO,EAAE,oBAAoB,EAAsB,MAAM,eAAe,CAAA;AAExE,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAC5C,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC/D,OAAO,EAAE,2BAA2B,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE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IACH,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAC,GAAY;IAChC,MAAM,QAAQ,GAAG,GAAkB,EAAE;QACnC,IAAI,CAAC;YACH,OAAO,oBAAoB,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAA;QAC1D,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,oBAAoB,CAAC,SAAS,CAAC,CAAA;QACxC,CAAC;IACH,CAAC,CAAA;IACD,MAAM,OAAO,GAAG,IAAI,uBAAuB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;IAC1D,GAAG,CAAC,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC,CAAA;IAEpC,uEAAuE;IACvE,wEAAwE;IACxE,sEAAsE;IACtE,MAAM,YAAY,GAAG,IAAI,GAAG,EAAU,CAAA;IACtC,GAAG,CAAC,EAAE,CAAC,iBAAiB,EAAE,CAAC,OAAgB,EAAE,EAAE;QAC7C,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,CAAA;QAC/B,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,IAAI,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,OAAM;QAC1E,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QACrB,KAAK,2BAA2B,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;IACvD,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAA;AACtB,CAAC"}
|
package/lib/notes/render.d.ts
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Markdown renderers for the project-notes
|
|
3
|
-
* through {@link isRenderedEntry}) become
|
|
4
|
-
*
|
|
2
|
+
* Markdown renderers for the project-notes prompt section: store entries
|
|
3
|
+
* (pre-filtered through {@link isRenderedEntry}) become the conventions /
|
|
4
|
+
* pitfalls texts injected into the system prompt. Pure functions — no I/O.
|
|
5
5
|
*
|
|
6
6
|
* Section order doubles as the precedence hint (project > global > personal);
|
|
7
7
|
* the injected system-prompt wrapper states it explicitly. Section headings
|
|
8
|
-
* are English regardless of entry language — the
|
|
8
|
+
* are English regardless of entry language — the notes surface is English.
|
|
9
9
|
*
|
|
10
10
|
* @module @chenhw7/dsh-memory/notes/render
|
|
11
11
|
*/
|
|
12
12
|
import type { MemoryEntry } from '../types.ts';
|
|
13
|
-
/** The
|
|
14
|
-
export declare const AUTO_HEADER = "
|
|
13
|
+
/** The provenance line stamped under every rendered section title. */
|
|
14
|
+
export declare const AUTO_HEADER = "Managed by dsh-memory (auto-generated from the memory store) \u2014 correct outdated entries via the memory tools or the Memory UI.";
|
|
15
15
|
/**
|
|
16
|
-
* Render
|
|
17
|
-
* `## Personal habits` (empty sections omitted).
|
|
16
|
+
* Render the conventions text: `## Project conventions` / `## Global
|
|
17
|
+
* practices` / `## Personal habits` (empty sections omitted).
|
|
18
18
|
* @param entries - convention-kind entries (already filtered).
|
|
19
19
|
* @param cap - max total entries (`notesMaxEntriesPerFile`); `0` = unlimited.
|
|
20
|
-
* @returns the full
|
|
20
|
+
* @returns the full section text.
|
|
21
21
|
*/
|
|
22
22
|
export declare function renderConventions(entries: readonly MemoryEntry[], cap: number): string;
|
|
23
23
|
/**
|
|
24
|
-
* Render
|
|
25
|
-
* pitfalls` (empty sections omitted). Entry content is emitted
|
|
26
|
-
* pitfall extraction prompt guarantees the structured wording.
|
|
24
|
+
* Render the pitfalls text: `## Project pitfalls` / `## Environment &
|
|
25
|
+
* cross-project pitfalls` (empty sections omitted). Entry content is emitted
|
|
26
|
+
* verbatim — the pitfall extraction prompt guarantees the structured wording.
|
|
27
27
|
* @param entries - pitfall-kind entries (already filtered).
|
|
28
28
|
* @param cap - max total entries (`notesMaxEntriesPerFile`); `0` = unlimited.
|
|
29
|
-
* @returns the full
|
|
29
|
+
* @returns the full section text.
|
|
30
30
|
*/
|
|
31
31
|
export declare function renderPitfalls(entries: readonly MemoryEntry[], cap: number): string;
|
|
32
32
|
//# sourceMappingURL=render.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/notes/render.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAe,MAAM,aAAa,CAAA;AAE3D,
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/notes/render.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAe,MAAM,aAAa,CAAA;AAE3D,sEAAsE;AACtE,eAAO,MAAM,WAAW,wIAAmI,CAAA;AA4B3J;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,SAAS,WAAW,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAQtF;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,SAAS,WAAW,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAOnF"}
|
package/lib/notes/render.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Markdown renderers for the project-notes
|
|
3
|
-
* through {@link isRenderedEntry}) become
|
|
4
|
-
*
|
|
2
|
+
* Markdown renderers for the project-notes prompt section: store entries
|
|
3
|
+
* (pre-filtered through {@link isRenderedEntry}) become the conventions /
|
|
4
|
+
* pitfalls texts injected into the system prompt. Pure functions — no I/O.
|
|
5
5
|
*
|
|
6
6
|
* Section order doubles as the precedence hint (project > global > personal);
|
|
7
7
|
* the injected system-prompt wrapper states it explicitly. Section headings
|
|
8
|
-
* are English regardless of entry language — the
|
|
8
|
+
* are English regardless of entry language — the notes surface is English.
|
|
9
9
|
*
|
|
10
10
|
* @module @chenhw7/dsh-memory/notes/render
|
|
11
11
|
*/
|
|
12
|
-
/** The
|
|
13
|
-
export const AUTO_HEADER = '
|
|
12
|
+
/** The provenance line stamped under every rendered section title. */
|
|
13
|
+
export const AUTO_HEADER = 'Managed by dsh-memory (auto-generated from the memory store) — correct outdated entries via the memory tools or the Memory UI.';
|
|
14
14
|
/** Format an epoch-ms timestamp as `YYYY-MM-DD`. */
|
|
15
15
|
function isoDate(ts) {
|
|
16
16
|
return new Date(ts).toISOString().slice(0, 10);
|
|
@@ -34,11 +34,11 @@ function byScope(entries, scope) {
|
|
|
34
34
|
return entries.filter(entry => entry.scope === scope);
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
|
-
* Render
|
|
38
|
-
* `## Personal habits` (empty sections omitted).
|
|
37
|
+
* Render the conventions text: `## Project conventions` / `## Global
|
|
38
|
+
* practices` / `## Personal habits` (empty sections omitted).
|
|
39
39
|
* @param entries - convention-kind entries (already filtered).
|
|
40
40
|
* @param cap - max total entries (`notesMaxEntriesPerFile`); `0` = unlimited.
|
|
41
|
-
* @returns the full
|
|
41
|
+
* @returns the full section text.
|
|
42
42
|
*/
|
|
43
43
|
export function renderConventions(entries, cap) {
|
|
44
44
|
const capped = capEntries(entries, cap);
|
|
@@ -50,12 +50,12 @@ export function renderConventions(entries, cap) {
|
|
|
50
50
|
return `# Conventions\n\n${AUTO_HEADER}\n\n${parts.join('\n\n')}\n`;
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
|
-
* Render
|
|
54
|
-
* pitfalls` (empty sections omitted). Entry content is emitted
|
|
55
|
-
* pitfall extraction prompt guarantees the structured wording.
|
|
53
|
+
* Render the pitfalls text: `## Project pitfalls` / `## Environment &
|
|
54
|
+
* cross-project pitfalls` (empty sections omitted). Entry content is emitted
|
|
55
|
+
* verbatim — the pitfall extraction prompt guarantees the structured wording.
|
|
56
56
|
* @param entries - pitfall-kind entries (already filtered).
|
|
57
57
|
* @param cap - max total entries (`notesMaxEntriesPerFile`); `0` = unlimited.
|
|
58
|
-
* @returns the full
|
|
58
|
+
* @returns the full section text.
|
|
59
59
|
*/
|
|
60
60
|
export function renderPitfalls(entries, cap) {
|
|
61
61
|
const capped = capEntries(entries, cap);
|
package/lib/notes/render.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../src/notes/render.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../src/notes/render.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,sEAAsE;AACtE,MAAM,CAAC,MAAM,WAAW,GAAG,gIAAgI,CAAA;AAE3J,oDAAoD;AACpD,SAAS,OAAO,CAAC,EAAU;IACzB,OAAO,IAAI,IAAI,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;AAChD,CAAC;AAED,0CAA0C;AAC1C,SAAS,MAAM,CAAC,KAAkB;IAChC,OAAO,MAAM,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,KAAK,CAAC,OAAO,EAAE,CAAA;AAC3D,CAAC;AAED,sEAAsE;AACtE,SAAS,OAAO,CAAC,KAAa,EAAE,OAA+B;IAC7D,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAA;IACnC,OAAO,MAAM,KAAK,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAA;AAC3D,CAAC;AAED,uEAAuE;AACvE,SAAS,UAAU,CAAC,OAA+B,EAAE,GAAW;IAC9D,MAAM,MAAM,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC,CAAA;IACrE,OAAO,GAAG,GAAG,C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AAA;IACjC,OAAO,iBAAiB,WAAW,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAA;AAClE,CAAC"}
|
package/lib/notes/scope.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The scope×category render matrix for project notes (§4 of
|
|
3
|
-
* docs/PROJECT_NOTES.zh-CN.md): which store entries land in the
|
|
4
|
-
* Pure functions, zero host imports — shared
|
|
5
|
-
* `memory-context` (which excludes the same set
|
|
6
|
-
* injection so content never appears twice in
|
|
3
|
+
* docs/PROJECT_NOTES.zh-CN.md): which store entries land in the
|
|
4
|
+
* `project-notes` prompt section. Pure functions, zero host imports — shared
|
|
5
|
+
* by the notes renderer and by `memory-context` (which excludes the same set
|
|
6
|
+
* from its own snapshot/index injection so content never appears twice in
|
|
7
|
+
* the prompt).
|
|
7
8
|
*
|
|
8
9
|
* @module @chenhw7/dsh-memory/notes/scope
|
|
9
10
|
*/
|
|
10
11
|
import type { MemoryCategory, MemoryEntry } from '../types.ts';
|
|
11
|
-
/** Categories rendered
|
|
12
|
+
/** Categories rendered as conventions. */
|
|
12
13
|
export declare const NOTES_CONVENTION_CATEGORIES: readonly MemoryCategory[];
|
|
13
|
-
/** Categories rendered
|
|
14
|
+
/** Categories rendered as pitfalls (project- and global-scoped only). */
|
|
14
15
|
export declare const NOTES_PITFALL_CATEGORIES: readonly MemoryCategory[];
|
|
15
16
|
/** The minimal entry shape the matrix needs. */
|
|
16
17
|
export type RenderableEntry = Pick<MemoryEntry, 'scope' | 'category' | 'projectName'>;
|
package/lib/notes/scope.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../../src/notes/scope.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../../src/notes/scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9D,0CAA0C;AAC1C,eAAO,MAAM,2BAA2B,EAAE,SAAS,cAAc,EAAiC,CAAA;AAElG,yEAAyE;AACzE,eAAO,MAAM,wBAAwB,EAAE,SAAS,cAAc,EAA2C,CAAA;AAEzG,gDAAgD;AAChD,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,WAAW,EAAE,OAAO,GAAG,UAAU,GAAG,aAAa,CAAC,CAAA;AAErF,wDAAwD;AACxD,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,UAAU,CAAA;AAElD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAY9G"}
|