dsh-cross-memory 0.0.0-stage → 0.2.1

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 (152) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +253 -2
  3. package/cordis.patch.yml +27 -0
  4. package/docs/DETAIL.md +13 -0
  5. package/docs/DETAIL.zh.md +17 -0
  6. package/icon.svg +1 -0
  7. package/lib/backfill.js +273 -0
  8. package/lib/citations.js +305 -0
  9. package/lib/client.js +1660 -0
  10. package/lib/config.js +736 -0
  11. package/lib/consolidate.js +1119 -0
  12. package/lib/extract.js +570 -0
  13. package/lib/gate.js +137 -0
  14. package/lib/git-origin.js +224 -0
  15. package/lib/index.js +4482 -0
  16. package/lib/log.js +260 -0
  17. package/lib/loops.js +186 -0
  18. package/lib/notices.js +195 -0
  19. package/lib/notify.js +33 -0
  20. package/lib/persona.js +163 -0
  21. package/lib/query.js +93 -0
  22. package/lib/raw-recall.js +286 -0
  23. package/lib/reflection.js +291 -0
  24. package/lib/remote.js +490 -0
  25. package/lib/render.js +678 -0
  26. package/lib/retention.js +64 -0
  27. package/lib/schedule.js +245 -0
  28. package/lib/search.js +1068 -0
  29. package/lib/skills.js +220 -0
  30. package/lib/state.js +701 -0
  31. package/lib/storage.js +1424 -0
  32. package/lib/sync-runtime.js +268 -0
  33. package/lib/sync.js +620 -0
  34. package/lib/test/activity.test.js +74 -0
  35. package/lib/test/archive.test.js +182 -0
  36. package/lib/test/backfill.test.js +144 -0
  37. package/lib/test/citations.test.js +91 -0
  38. package/lib/test/client-wiring.test.js +134 -0
  39. package/lib/test/consolidate-job.test.js +95 -0
  40. package/lib/test/consolidate.test.js +430 -0
  41. package/lib/test/consolidation-selection.test.js +152 -0
  42. package/lib/test/dedupe-keys.test.js +230 -0
  43. package/lib/test/delta.test.js +93 -0
  44. package/lib/test/derived.test.js +110 -0
  45. package/lib/test/disputes-panel.test.js +341 -0
  46. package/lib/test/eval.test.js +171 -0
  47. package/lib/test/expand.test.js +164 -0
  48. package/lib/test/extract.test.js +1020 -0
  49. package/lib/test/git-origin.test.js +189 -0
  50. package/lib/test/injection.test.js +440 -0
  51. package/lib/test/kind-filter.test.js +49 -0
  52. package/lib/test/legacy-state.test.js +69 -0
  53. package/lib/test/log.test.js +156 -0
  54. package/lib/test/loops.test.js +86 -0
  55. package/lib/test/memory.test.js +855 -0
  56. package/lib/test/notices.test.js +142 -0
  57. package/lib/test/persona.test.js +86 -0
  58. package/lib/test/prefilter.test.js +73 -0
  59. package/lib/test/preset.test.js +77 -0
  60. package/lib/test/raw-recall.test.js +186 -0
  61. package/lib/test/recall.test.js +433 -0
  62. package/lib/test/reflection.test.js +64 -0
  63. package/lib/test/remote.test.js +238 -0
  64. package/lib/test/retention.test.js +117 -0
  65. package/lib/test/retrieval.test.js +142 -0
  66. package/lib/test/rotation.test.js +228 -0
  67. package/lib/test/schedule.test.js +112 -0
  68. package/lib/test/settings-card.test.js +58 -0
  69. package/lib/test/skills.test.js +129 -0
  70. package/lib/test/state.test.js +212 -0
  71. package/lib/test/subagent-contract.test.js +139 -0
  72. package/lib/test/sweep.test.js +159 -0
  73. package/lib/test/sync.test.js +314 -0
  74. package/lib/test/time.test.js +171 -0
  75. package/lib/time.js +303 -0
  76. package/lib/tool.js +330 -0
  77. package/lib/types/backfill.d.ts +96 -0
  78. package/lib/types/citations.d.ts +105 -0
  79. package/lib/types/config.d.ts +811 -0
  80. package/lib/types/consolidate.d.ts +742 -0
  81. package/lib/types/extract.d.ts +352 -0
  82. package/lib/types/gate.d.ts +83 -0
  83. package/lib/types/git-origin.d.ts +23 -0
  84. package/lib/types/index.d.ts +1316 -0
  85. package/lib/types/log.d.ts +144 -0
  86. package/lib/types/loops.d.ts +82 -0
  87. package/lib/types/notices.d.ts +117 -0
  88. package/lib/types/notify.d.ts +12 -0
  89. package/lib/types/persona.d.ts +76 -0
  90. package/lib/types/query.d.ts +45 -0
  91. package/lib/types/raw-recall.d.ts +84 -0
  92. package/lib/types/reflection.d.ts +122 -0
  93. package/lib/types/remote.d.ts +246 -0
  94. package/lib/types/render.d.ts +286 -0
  95. package/lib/types/retention.d.ts +66 -0
  96. package/lib/types/schedule.d.ts +116 -0
  97. package/lib/types/search.d.ts +583 -0
  98. package/lib/types/skills.d.ts +71 -0
  99. package/lib/types/state.d.ts +294 -0
  100. package/lib/types/storage.d.ts +458 -0
  101. package/lib/types/sync-runtime.d.ts +103 -0
  102. package/lib/types/sync.d.ts +222 -0
  103. package/lib/types/test/activity.test.d.ts +1 -0
  104. package/lib/types/test/archive.test.d.ts +1 -0
  105. package/lib/types/test/backfill.test.d.ts +1 -0
  106. package/lib/types/test/citations.test.d.ts +1 -0
  107. package/lib/types/test/client-wiring.test.d.ts +1 -0
  108. package/lib/types/test/consolidate-job.test.d.ts +1 -0
  109. package/lib/types/test/consolidate.test.d.ts +1 -0
  110. package/lib/types/test/consolidation-selection.test.d.ts +1 -0
  111. package/lib/types/test/dedupe-keys.test.d.ts +1 -0
  112. package/lib/types/test/delta.test.d.ts +1 -0
  113. package/lib/types/test/derived.test.d.ts +1 -0
  114. package/lib/types/test/disputes-panel.test.d.ts +1 -0
  115. package/lib/types/test/eval.test.d.ts +1 -0
  116. package/lib/types/test/expand.test.d.ts +1 -0
  117. package/lib/types/test/extract.test.d.ts +1 -0
  118. package/lib/types/test/git-origin.test.d.ts +1 -0
  119. package/lib/types/test/injection.test.d.ts +1 -0
  120. package/lib/types/test/kind-filter.test.d.ts +1 -0
  121. package/lib/types/test/legacy-state.test.d.ts +1 -0
  122. package/lib/types/test/log.test.d.ts +1 -0
  123. package/lib/types/test/loops.test.d.ts +1 -0
  124. package/lib/types/test/memory.test.d.ts +1 -0
  125. package/lib/types/test/notices.test.d.ts +1 -0
  126. package/lib/types/test/persona.test.d.ts +1 -0
  127. package/lib/types/test/prefilter.test.d.ts +1 -0
  128. package/lib/types/test/preset.test.d.ts +1 -0
  129. package/lib/types/test/raw-recall.test.d.ts +1 -0
  130. package/lib/types/test/recall.test.d.ts +1 -0
  131. package/lib/types/test/reflection.test.d.ts +1 -0
  132. package/lib/types/test/remote.test.d.ts +1 -0
  133. package/lib/types/test/retention.test.d.ts +1 -0
  134. package/lib/types/test/retrieval.test.d.ts +1 -0
  135. package/lib/types/test/rotation.test.d.ts +1 -0
  136. package/lib/types/test/schedule.test.d.ts +1 -0
  137. package/lib/types/test/settings-card.test.d.ts +1 -0
  138. package/lib/types/test/skills.test.d.ts +1 -0
  139. package/lib/types/test/state.test.d.ts +1 -0
  140. package/lib/types/test/subagent-contract.test.d.ts +1 -0
  141. package/lib/types/test/sweep.test.d.ts +1 -0
  142. package/lib/types/test/sync.test.d.ts +1 -0
  143. package/lib/types/test/time.test.d.ts +1 -0
  144. package/lib/types/time.d.ts +67 -0
  145. package/lib/types/tool.d.ts +9 -0
  146. package/lib/types/types.d.ts +374 -0
  147. package/lib/types/workspace.d.ts +20 -0
  148. package/lib/types.js +47 -0
  149. package/lib/workspace.js +65 -0
  150. package/locale/en.json +7 -0
  151. package/locale/zh.json +7 -0
  152. package/package.json +126 -4
@@ -0,0 +1,96 @@
1
+ /** One prose message recovered from a session log. */
2
+ export interface BackfillMessage {
3
+ /** Surface sequence the message was logged at. */
4
+ readonly seq: number;
5
+ readonly role: 'user' | 'assistant';
6
+ readonly text: string;
7
+ }
8
+ /** One persisted session, as far as backfill needs to know it. */
9
+ export interface BackfillLog {
10
+ readonly sessionId: string;
11
+ readonly file: string;
12
+ readonly modifiedAt: number;
13
+ /** Workspace the session was opened in, when the log recorded one. */
14
+ readonly cwd?: string;
15
+ /** The route the session's last request used, so a backfill call can reuse it. */
16
+ readonly route?: {
17
+ readonly provider: string;
18
+ readonly model: string;
19
+ readonly reasoningEffort?: string;
20
+ };
21
+ readonly messages: readonly BackfillMessage[];
22
+ /** Highest surface sequence in the log. */
23
+ readonly maxSeq: number;
24
+ }
25
+ /** One extraction window cut from a recovered transcript. */
26
+ export interface BackfillWindow {
27
+ readonly text: string;
28
+ readonly firstSeq: number;
29
+ readonly lastSeq: number;
30
+ readonly messages: number;
31
+ /** Message bodies behind `text`, for the extraction quote check. */
32
+ readonly sources: readonly {
33
+ readonly seq: number;
34
+ readonly text: string;
35
+ }[];
36
+ }
37
+ /** Whether this Node build can decompress zstd at all. */
38
+ export declare function zstdAvailable(): boolean;
39
+ /**
40
+ * Decompress one concatenated-frame session log.
41
+ *
42
+ * A session log is an append-only series of independent zstd frames, so a
43
+ * single-shot decode stops at the first frame and hides the conversation. Every
44
+ * frame boundary is decoded and joined; a candidate offset that is not a frame
45
+ * start simply fails to decode and is skipped.
46
+ *
47
+ * @param buffer - raw file bytes.
48
+ * @returns the joined log text.
49
+ * @throws when the Node build has no zstd support.
50
+ */
51
+ export declare function decodeSessionLog(buffer: Buffer): string;
52
+ /**
53
+ * Parse one decoded session log.
54
+ *
55
+ * Only `user/message` events authored by the user and `assistant/message`
56
+ * events are kept: tool results are bulky and rarely the durable lesson, and
57
+ * plugin-authored user messages (a memory block, a recall delta) are skipped so
58
+ * backfill never feeds memory its own summaries.
59
+ *
60
+ * @param text - decoded log text (one JSON event per line).
61
+ * @param file - the log's path, used for a fallback session id.
62
+ * @param modifiedAt - the file's mtime, carried through for reporting.
63
+ * @returns the recovered session, or `undefined` when the log has no prose.
64
+ */
65
+ export declare function parseSessionLog(text: string, file: string, modifiedAt: number): BackfillLog | undefined;
66
+ /**
67
+ * Cut a recovered transcript into bounded extraction windows.
68
+ *
69
+ * The message count and the character budget are separate limits on purpose:
70
+ * a few very long turns and many short ones are both real, and either alone
71
+ * produces a window the extractor cannot afford.
72
+ *
73
+ * @param messages - the recovered transcript, oldest first.
74
+ * @param maxMessages - model-facing message cap for one window.
75
+ * @param maxChars - character budget for one window.
76
+ * @returns the windows, in order.
77
+ */
78
+ export declare function planWindows(messages: readonly BackfillMessage[], maxMessages: number, maxChars: number): BackfillWindow[];
79
+ /**
80
+ * Every persisted session log under one harness home's `sessions` directory.
81
+ *
82
+ * @param sessionsDir - absolute `<dshHome>/sessions` path.
83
+ * @returns log paths with their mtimes, newest first; unreadable directories are skipped.
84
+ */
85
+ export declare function findSessionLogs(sessionsDir: string): Promise<{
86
+ file: string;
87
+ modifiedAt: number;
88
+ }[]>;
89
+ /**
90
+ * Read and parse one log file in one step.
91
+ *
92
+ * @param file - absolute log path.
93
+ * @param modifiedAt - mtime the caller already observed.
94
+ * @returns the parsed session, or `undefined` when the log has no prose.
95
+ */
96
+ export declare function readSessionLog(file: string, modifiedAt: number): Promise<BackfillLog | undefined>;
@@ -0,0 +1,105 @@
1
+ /** Whether a path exists. Injected so the rule can be tested without a filesystem. */
2
+ export type PathProbe = (path: string) => boolean;
3
+ /** The default probe: the real filesystem. */
4
+ export declare const fileProbe: PathProbe;
5
+ /**
6
+ * Relative paths a body cites.
7
+ *
8
+ * Only things with a directory component and a file extension are considered:
9
+ * a bare `index.js` names a file in a dozen packages, so it cannot be checked,
10
+ * and prose like `and/or` should never be mistaken for a path.
11
+ *
12
+ * @param text - the entry body.
13
+ * @returns unique relative paths, in first-seen order.
14
+ */
15
+ export declare function extractCitations(text: string): string[];
16
+ /**
17
+ * Citations in one body that no longer resolve under any known root.
18
+ *
19
+ * @param body - the entry body.
20
+ * @param roots - checkout roots (project roots, the harness home, package dirs).
21
+ * @param probe - filesystem probe, for tests.
22
+ * @param options - extra rules; `isIgnored` suppresses a path the repository
23
+ * itself generates (see {@link isIgnoredPath}).
24
+ * @returns the paths that look deleted or moved.
25
+ */
26
+ export declare function missingCitations(body: string, roots: readonly string[], probe?: PathProbe, options?: {
27
+ readonly isIgnored?: (relativePath: string) => boolean;
28
+ }): string[];
29
+ /** One parsed `.gitignore` rule. */
30
+ export interface IgnoreRule {
31
+ /** Pattern text, without the leading `!` or the trailing `/`. */
32
+ readonly pattern: string;
33
+ /** Whether this rule re-includes a path an earlier rule excluded. */
34
+ readonly negated: boolean;
35
+ /** Whether the pattern is anchored to the ignore file's own directory. */
36
+ readonly anchored: boolean;
37
+ /** Whether the pattern names a directory rather than a file. */
38
+ readonly directory: boolean;
39
+ }
40
+ /**
41
+ * Parse one `.gitignore` body.
42
+ *
43
+ * Only the subset that decides "is this path generated" is supported: comments,
44
+ * blank lines, negation, a leading or embedded slash for anchoring, a trailing
45
+ * slash for directories, and `*` / `**` / `?` globs. Character classes and
46
+ * escaped leading `#`/`!` are treated literally, which can only make the check
47
+ * miss an exclusion — never invent one.
48
+ *
49
+ * @param text - the file's contents.
50
+ * @returns the rules, in file order (git gives the last match the last word).
51
+ */
52
+ export declare function parseGitignore(text: string): IgnoreRule[];
53
+ /**
54
+ * Read the ignore rules that govern paths relative to one root.
55
+ *
56
+ * Deliberately one file: the root's own `.gitignore`. Parent directories and
57
+ * global excludes are not consulted, so a path covered only by those is still
58
+ * reported — the conservative direction for a check whose job is to warn.
59
+ *
60
+ * @param root - repository root.
61
+ * @returns the rules, or an empty list when there is no readable `.gitignore`.
62
+ */
63
+ export declare function readGitignore(root: string): IgnoreRule[];
64
+ /**
65
+ * Whether a repository's own ignore rules cover this relative path.
66
+ *
67
+ * The last matching rule decides, exactly as git does, so a `!` re-inclusion is
68
+ * honoured.
69
+ *
70
+ * @param relativePath - the cited path, relative to the root the rules came from.
71
+ * @param rules - rules from {@link parseGitignore} / {@link readGitignore}.
72
+ * @returns true when the path is one the repository generates.
73
+ */
74
+ export declare function isIgnoredPath(relativePath: string, rules: readonly IgnoreRule[]): boolean;
75
+ /**
76
+ * A predicate that suppresses generated paths under one root.
77
+ *
78
+ * @param root - repository root whose `.gitignore` applies.
79
+ * @returns a predicate for {@link missingCitations}.
80
+ */
81
+ export declare function ignoredUnder(root: string): (relativePath: string) => boolean;
82
+ /**
83
+ * Roots worth checking a project's memories against.
84
+ *
85
+ * A memory cites files relative to the repository it is about, so its own project
86
+ * root comes first; the harness home covers memories about profiles and
87
+ * settings, and one level of `node_modules` covers citations that name installed
88
+ * package sources.
89
+ *
90
+ * @param projectRoot - the owning workspace root, when there is one.
91
+ * @param extra - further roots the caller knows about (e.g. the harness home).
92
+ * @returns roots to search, most specific first.
93
+ */
94
+ export declare function citationRoots(projectRoot: string | undefined, extra?: readonly string[]): string[];
95
+ /**
96
+ * The marker appended to a summary bullet whose citations no longer resolve.
97
+ *
98
+ * @param missing - the paths that could not be found.
99
+ * @returns one short clause, or an empty string.
100
+ */
101
+ export declare function citationWarning(missing: readonly string[]): string;
102
+ /** Whether a path is inside a root (used by callers that filter roots). */
103
+ export declare function isInside(root: string, path: string): boolean;
104
+ /** Whether a path is an existing directory. */
105
+ export declare function isDirectory(path: string): boolean;