@facthouse/mcp 0.26.0 → 0.28.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/LICENSE +21 -21
- package/README.md +622 -611
- package/dist/cli/index.d.ts +4 -9
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +50 -48
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/init-backfill.d.ts +23 -4
- package/dist/cli/init-backfill.d.ts.map +1 -1
- package/dist/cli/init-backfill.js +33 -12
- package/dist/cli/init-backfill.js.map +1 -1
- package/dist/cli/init-knobs.d.ts +20 -11
- package/dist/cli/init-knobs.d.ts.map +1 -1
- package/dist/cli/init-knobs.js +62 -32
- package/dist/cli/init-knobs.js.map +1 -1
- package/dist/cli/init-wizard.d.ts +2 -0
- package/dist/cli/init-wizard.d.ts.map +1 -1
- package/dist/cli/init-wizard.js +7 -5
- package/dist/cli/init-wizard.js.map +1 -1
- package/dist/cli/init.d.ts +4 -1
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +8 -6
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/inspect-html.js +460 -460
- package/dist/cli/inspect-intelligence.js +70 -70
- package/dist/cli/inspect-payload.js +39 -39
- package/dist/cli/inspect-theme.js +18 -18
- package/dist/cli/query.js +4 -4
- package/dist/cli/settings.d.ts.map +1 -1
- package/dist/cli/settings.js +3 -3
- package/dist/cli/settings.js.map +1 -1
- package/dist/cli/spend-dashboard.js +4 -4
- package/dist/cli/stats-html.js +674 -674
- package/dist/cli/web.d.ts.map +1 -1
- package/dist/cli/web.js +91 -96
- package/dist/cli/web.js.map +1 -1
- package/dist/db/consolidation-lock.js +2 -2
- package/dist/db/consolidations.js +15 -15
- package/dist/db/embeddings.js +10 -10
- package/dist/db/entities.js +26 -26
- package/dist/db/extract-watermarks.js +79 -79
- package/dist/db/facts.js +39 -39
- package/dist/db/inferences.js +8 -8
- package/dist/db/intelligence-runs.js +5 -5
- package/dist/db/postgres-schema.js +323 -323
- package/dist/db/prune.js +17 -17
- package/dist/db/schema.js +530 -530
- package/dist/db/session-facts.js +26 -26
- package/dist/db/sessions.js +10 -10
- package/dist/db/sources.js +1 -1
- package/dist/db/stats.js +10 -10
- package/dist/db/watermarks.js +7 -7
- package/dist/identity.d.ts +7 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +13 -0
- package/dist/identity.js.map +1 -1
- package/dist/index.d.ts +1 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/intelligence/consolidate.d.ts +7 -1
- package/dist/intelligence/consolidate.d.ts.map +1 -1
- package/dist/intelligence/consolidate.js +54 -40
- package/dist/intelligence/consolidate.js.map +1 -1
- package/dist/intelligence/extract-prompt.js +26 -26
- package/dist/intelligence/token-budget.d.ts +2 -0
- package/dist/intelligence/token-budget.d.ts.map +1 -1
- package/dist/intelligence/token-budget.js +1 -1
- package/dist/intelligence/token-budget.js.map +1 -1
- package/dist/search/episodes.js +14 -14
- package/dist/search/key-facts.js +3 -3
- package/dist/suppress-sqlite-warning.d.ts +2 -0
- package/dist/suppress-sqlite-warning.d.ts.map +1 -0
- package/dist/suppress-sqlite-warning.js +17 -0
- package/dist/suppress-sqlite-warning.js.map +1 -0
- package/dist/tools/fact-manager.d.ts.map +1 -1
- package/dist/tools/fact-manager.js +9 -11
- package/dist/tools/fact-manager.js.map +1 -1
- package/dist/tools/read-tools.js +4 -4
- package/dist/tools/resources.js +3 -3
- package/dist/tools/resources.js.map +1 -1
- package/dist/types/config.d.ts +5 -3
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/config.js +7 -1
- package/dist/types/config.js.map +1 -1
- package/package.json +62 -62
- package/dist/cli/log-event.d.ts +0 -55
- package/dist/cli/log-event.d.ts.map +0 -1
- package/dist/cli/log-event.js +0 -149
- package/dist/cli/log-event.js.map +0 -1
- package/dist/db/scheduler-signal.d.ts +0 -20
- package/dist/db/scheduler-signal.d.ts.map +0 -1
- package/dist/db/scheduler-signal.js +0 -32
- package/dist/db/scheduler-signal.js.map +0 -1
- package/dist/schemas/starter-vocabulary.d.ts +0 -34
- package/dist/schemas/starter-vocabulary.d.ts.map +0 -1
- package/dist/schemas/starter-vocabulary.js +0 -91
- package/dist/schemas/starter-vocabulary.js.map +0 -1
- package/dist/search/profile.d.ts +0 -31
- package/dist/search/profile.d.ts.map +0 -1
- package/dist/search/profile.js +0 -43
- package/dist/search/profile.js.map +0 -1
- package/dist/sources/jsonl-ingest.d.ts +0 -58
- package/dist/sources/jsonl-ingest.d.ts.map +0 -1
- package/dist/sources/jsonl-ingest.js +0 -195
- package/dist/sources/jsonl-ingest.js.map +0 -1
- package/dist/sources/pull.d.ts +0 -85
- package/dist/sources/pull.d.ts.map +0 -1
- package/dist/sources/pull.js +0 -145
- package/dist/sources/pull.js.map +0 -1
- package/dist/types.d.ts +0 -115
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -6
- package/dist/types.js.map +0 -1
- package/dist/warnings.d.ts.map +0 -1
- package/dist/warnings.js.map +0 -1
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A starting vocabulary, written into the user's `config.json` at init.
|
|
3
|
-
*
|
|
4
|
-
* **This is not a core, and the engine does not know these names.** It is data:
|
|
5
|
-
* seeded once into a file the user owns, then read back like any other config.
|
|
6
|
-
* Delete it, rename it, replace it wholesale — nothing in `src/` refers to
|
|
7
|
-
* `medical` or `preferences`, and nothing breaks if they are gone. The only
|
|
8
|
-
* domain the engine knows is `general`, the fallback.
|
|
9
|
-
*
|
|
10
|
-
* It is personal-flavoured because personal is the use case OpenMemory is
|
|
11
|
-
* best at, and an empty vocabulary gives a classifier nothing to be consistent
|
|
12
|
-
* with on day one. It is *not* a claim about what domains are. A corporate store
|
|
13
|
-
* replaces this with clients, incidents, contracts, suppliers; a research store
|
|
14
|
-
* with papers, experiments, datasets. Both are equally correct, and the engine
|
|
15
|
-
* cannot tell the difference — which is the point.
|
|
16
|
-
*
|
|
17
|
-
* Each domain carries its own:
|
|
18
|
-
* - `description` — shown to a classifier so it routes on meaning, not a guess
|
|
19
|
-
* at what a bare name implies.
|
|
20
|
-
* - `patterns` — for the fallback classifier, when no LLM is available. These
|
|
21
|
-
* are the most obviously non-universal part: "allergic" and "partner" are
|
|
22
|
-
* noise in a corporate store, and "SLA" and "incident" would be noise here.
|
|
23
|
-
* - `importance` — because a missed allergy is the costliest error in a
|
|
24
|
-
* personal store, and a missed SLA breach in a corporate one.
|
|
25
|
-
*
|
|
26
|
-
* Patterns match how facts are actually written. `capture_fact` is called by an
|
|
27
|
-
* assistant recording a fact *about* its user, so content arrives in the third
|
|
28
|
-
* person ("The user prefers dark roast"), not the first ("I prefer dark roast").
|
|
29
|
-
* Verbs therefore need their -s form: `prefers?`, not `prefer` — `\bprefer\b`
|
|
30
|
-
* does not match "prefers".
|
|
31
|
-
*/
|
|
32
|
-
export const STARTER_VOCABULARY = [
|
|
33
|
-
{
|
|
34
|
-
// First: health information takes priority, and a false positive here is
|
|
35
|
-
// safer than a miss. Order is precedence — the fallback stops at the first
|
|
36
|
-
// match.
|
|
37
|
-
name: "medical",
|
|
38
|
-
description: "health conditions, allergies, medication, treatment",
|
|
39
|
-
subdomains: [],
|
|
40
|
-
patterns: [
|
|
41
|
-
"\\b(allerg|medicat|doctor|diagnosis|condition|symptom|treatment|prescription|health|hospital|clinic|vaccine|blood|surgery|therapy|illness|disease)",
|
|
42
|
-
],
|
|
43
|
-
importance: 0.9,
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
name: "profile",
|
|
47
|
-
description: "core identity — name, demographics, location, occupation",
|
|
48
|
-
subdomains: [],
|
|
49
|
-
patterns: [
|
|
50
|
-
// First person, as a user states it.
|
|
51
|
-
"\\b(my name is|i am|i'm|born|nationality|age|birthday|occupation|job title)\\b",
|
|
52
|
-
"\\bi (live|lives) in\\b",
|
|
53
|
-
// Third person, as an assistant records it about its user.
|
|
54
|
-
"\\bthe user('s)? (is|was|has been)? ?(called|named)\\b",
|
|
55
|
-
"\\bthe user's (name|age|birthday|nationality|occupation|job title)\\b",
|
|
56
|
-
"\\b(the user|they) (lives?|moved|grew up|was born)\\b",
|
|
57
|
-
],
|
|
58
|
-
importance: 0.85,
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
// Ahead of preferences: a relationship noun says who a fact is about, which
|
|
62
|
-
// outranks a preference verb saying what it mentions. "My partner Robin
|
|
63
|
-
// loves sushi" is a fact about Robin.
|
|
64
|
-
name: "people",
|
|
65
|
-
description: "relationships and the people in the user's life",
|
|
66
|
-
subdomains: [],
|
|
67
|
-
patterns: [
|
|
68
|
-
"\\b(partner|wife|husband|friend|colleague|boss|sister|brother|mother|father|son|daughter|neighbour|neighbor)\\b",
|
|
69
|
-
],
|
|
70
|
-
importance: 0.6,
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
name: "work",
|
|
74
|
-
description: "employment, projects, teams, deadlines",
|
|
75
|
-
subdomains: [],
|
|
76
|
-
patterns: [
|
|
77
|
-
"\\b(project|sprint|deploy|meeting|team|company|client|deadline|standup|release|merge|repository|codebase)\\b",
|
|
78
|
-
],
|
|
79
|
-
importance: 0.6,
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
name: "preferences",
|
|
83
|
-
description: "likes, dislikes, favourites, habits",
|
|
84
|
-
subdomains: [],
|
|
85
|
-
patterns: [
|
|
86
|
-
"\\b(prefers?|favourites?|favorites?|likes?|loves?|hates?|dislikes?|enjoys?|can't stand|would rather|rather)\\b",
|
|
87
|
-
],
|
|
88
|
-
importance: 0.4,
|
|
89
|
-
},
|
|
90
|
-
];
|
|
91
|
-
//# sourceMappingURL=starter-vocabulary.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"starter-vocabulary.js","sourceRoot":"","sources":["../../src/schemas/starter-vocabulary.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAIH,MAAM,CAAC,MAAM,kBAAkB,GAAgB;IAC7C;QACE,yEAAyE;QACzE,2EAA2E;QAC3E,SAAS;QACT,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,qDAAqD;QAClE,UAAU,EAAE,EAAE;QACd,QAAQ,EAAE;YACR,oJAAoJ;SACrJ;QACD,UAAU,EAAE,GAAG;KAChB;IACD;QACE,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,0DAA0D;QACvE,UAAU,EAAE,EAAE;QACd,QAAQ,EAAE;YACR,qCAAqC;YACrC,gFAAgF;YAChF,yBAAyB;YACzB,2DAA2D;YAC3D,wDAAwD;YACxD,uEAAuE;YACvE,uDAAuD;SACxD;QACD,UAAU,EAAE,IAAI;KACjB;IACD;QACE,4EAA4E;QAC5E,wEAAwE;QACxE,sCAAsC;QACtC,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,iDAAiD;QAC9D,UAAU,EAAE,EAAE;QACd,QAAQ,EAAE;YACR,iHAAiH;SAClH;QACD,UAAU,EAAE,GAAG;KAChB;IACD;QACE,IAAI,EAAE,MAAM;QACZ,WAAW,EAAE,wCAAwC;QACrD,UAAU,EAAE,EAAE;QACd,QAAQ,EAAE;YACR,8GAA8G;SAC/G;QACD,UAAU,EAAE,GAAG;KAChB;IACD;QACE,IAAI,EAAE,aAAa;QACnB,WAAW,EAAE,qCAAqC;QAClD,UAAU,EAAE,EAAE;QACd,QAAQ,EAAE;YACR,gHAAgH;SACjH;QACD,UAAU,EAAE,GAAG;KAChB;CACF,CAAC"}
|
package/dist/search/profile.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The user's identity facts — one definition, shared by every surface that
|
|
3
|
-
* claims to return "the profile".
|
|
4
|
-
*
|
|
5
|
-
* There were two. `get_profile` ran `structuredSearch(db, { domain: "profile" })`,
|
|
6
|
-
* which defaults to 20 and orders by `created_at DESC`; `memory://profile`
|
|
7
|
-
* fetched 200 and sorted by importance. So the tool returned the 20 *newest*
|
|
8
|
-
* profile facts and never consulted importance — and identity facts are the
|
|
9
|
-
* earliest captured and the most important. Past 20 profile facts, the tool
|
|
10
|
-
* whose description promises "core identity — name, demographics" silently
|
|
11
|
-
* dropped the user's name while the resource still showed it.
|
|
12
|
-
*
|
|
13
|
-
* Ranked by importance because that is what the spec asks for: `memory://profile`
|
|
14
|
-
* is specified as "user identity facts (high importance, is_latest=1)". Recency
|
|
15
|
-
* is the wrong axis for identity — a name does not become less true for being
|
|
16
|
-
* old, and a fact captured today is not more who you are.
|
|
17
|
-
*
|
|
18
|
-
* Known limitation, deliberately left: this still selects on `domain = 'profile'`,
|
|
19
|
-
* which is an exact match against a label a stochastic classifier assigned — the
|
|
20
|
-
* cue/encoding mismatch that `hybridSearch` was fixed to stop doing. A fact
|
|
21
|
-
* misfiled into `general` is invisible here. The fix is a subject anchor rather
|
|
22
|
-
* than a topical folder ("profile" is not a topic; it means "this fact is about
|
|
23
|
-
* the user"), which needs the entity model to carry a subject. Tracked in
|
|
24
|
-
* docs/design/data-model.md § Domains. This function exists so that when that
|
|
25
|
-
* lands, there is one place to change.
|
|
26
|
-
*/
|
|
27
|
-
import type { Db } from "../db/connection.js";
|
|
28
|
-
import type { Fact } from "../types/data.js";
|
|
29
|
-
/** The user's identity facts, most important first. */
|
|
30
|
-
export declare function profileFacts(db: Db, limit?: number): Fact[];
|
|
31
|
-
//# sourceMappingURL=profile.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../../src/search/profile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAa7C,uDAAuD;AACvD,wBAAgB,YAAY,CAAC,EAAE,EAAE,EAAE,EAAE,KAAK,GAAE,MAAwB,GAAG,IAAI,EAAE,CAI5E"}
|
package/dist/search/profile.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The user's identity facts — one definition, shared by every surface that
|
|
3
|
-
* claims to return "the profile".
|
|
4
|
-
*
|
|
5
|
-
* There were two. `get_profile` ran `structuredSearch(db, { domain: "profile" })`,
|
|
6
|
-
* which defaults to 20 and orders by `created_at DESC`; `memory://profile`
|
|
7
|
-
* fetched 200 and sorted by importance. So the tool returned the 20 *newest*
|
|
8
|
-
* profile facts and never consulted importance — and identity facts are the
|
|
9
|
-
* earliest captured and the most important. Past 20 profile facts, the tool
|
|
10
|
-
* whose description promises "core identity — name, demographics" silently
|
|
11
|
-
* dropped the user's name while the resource still showed it.
|
|
12
|
-
*
|
|
13
|
-
* Ranked by importance because that is what the spec asks for: `memory://profile`
|
|
14
|
-
* is specified as "user identity facts (high importance, is_latest=1)". Recency
|
|
15
|
-
* is the wrong axis for identity — a name does not become less true for being
|
|
16
|
-
* old, and a fact captured today is not more who you are.
|
|
17
|
-
*
|
|
18
|
-
* Known limitation, deliberately left: this still selects on `domain = 'profile'`,
|
|
19
|
-
* which is an exact match against a label a stochastic classifier assigned — the
|
|
20
|
-
* cue/encoding mismatch that `hybridSearch` was fixed to stop doing. A fact
|
|
21
|
-
* misfiled into `general` is invisible here. The fix is a subject anchor rather
|
|
22
|
-
* than a topical folder ("profile" is not a topic; it means "this fact is about
|
|
23
|
-
* the user"), which needs the entity model to carry a subject. Tracked in
|
|
24
|
-
* docs/design/data-model.md § Domains. This function exists so that when that
|
|
25
|
-
* lands, there is one place to change.
|
|
26
|
-
*/
|
|
27
|
-
import { structuredSearch } from "./index.js";
|
|
28
|
-
/**
|
|
29
|
-
* How many profile facts to consider before ranking.
|
|
30
|
-
*
|
|
31
|
-
* Deliberately far above any plausible profile size: the point is to rank the
|
|
32
|
-
* whole set by importance, not to rank an arbitrary 20 of it. Under-fetching
|
|
33
|
-
* here is what caused the bug this module exists to fix — it is cheap against a
|
|
34
|
-
* local index and expensive to get wrong.
|
|
35
|
-
*/
|
|
36
|
-
const CANDIDATE_LIMIT = 200;
|
|
37
|
-
/** The user's identity facts, most important first. */
|
|
38
|
-
export function profileFacts(db, limit = CANDIDATE_LIMIT) {
|
|
39
|
-
return structuredSearch(db, { domain: "profile", limit: CANDIDATE_LIMIT })
|
|
40
|
-
.sort((a, b) => b.importance - a.importance)
|
|
41
|
-
.slice(0, limit);
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=profile.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"profile.js","sourceRoot":"","sources":["../../src/search/profile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAIH,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C;;;;;;;GAOG;AACH,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B,uDAAuD;AACvD,MAAM,UAAU,YAAY,CAAC,EAAM,EAAE,QAAgB,eAAe;IAClE,OAAO,gBAAgB,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,CAAC;SACvE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU,CAAC;SAC3C,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AACrB,CAAC"}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared JSONL tail: watermark, fingerprint, insert.
|
|
3
|
-
*
|
|
4
|
-
* Adapters discover files and map lines. This module is the one ingest
|
|
5
|
-
* path so a crash cannot duplicate a line, regardless of which client
|
|
6
|
-
* wrote the transcript.
|
|
7
|
-
*/
|
|
8
|
-
import type { Db } from "../db/connection.js";
|
|
9
|
-
import type { NewSessionEvent } from "../db/sessions.js";
|
|
10
|
-
export interface JsonlFilePull {
|
|
11
|
-
path: string;
|
|
12
|
-
inserted: number;
|
|
13
|
-
skipped: number;
|
|
14
|
-
}
|
|
15
|
-
export type MapTranscriptLine = (raw: string, fallbackSessionId: string, filePath: string, lineNumber: number, sourceTool: string) => NewSessionEvent[];
|
|
16
|
-
export interface JsonlIngestOptions {
|
|
17
|
-
sourceTool: string;
|
|
18
|
-
mapLine: MapTranscriptLine;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Tail one JSONL file into session_events from its watermark. Inserts and the
|
|
22
|
-
* watermark update share a transaction so a crash cannot duplicate a line.
|
|
23
|
-
*/
|
|
24
|
-
export declare function ingestJsonlFile(db: Db, filePath: string, opts: JsonlIngestOptions): Promise<JsonlFilePull>;
|
|
25
|
-
export declare function isDir(p: string): boolean;
|
|
26
|
-
export declare function listJsonl(dir: string): string[];
|
|
27
|
-
export declare function sessionIdFromPath(filePath: string): string;
|
|
28
|
-
/**
|
|
29
|
-
* On-disk group under `home/projects/<group>/`.
|
|
30
|
-
* That encoded name is the provenance we store on `sessions.project` —
|
|
31
|
-
* not a tenant, and not a decoded filesystem path (encoding is lossy).
|
|
32
|
-
*/
|
|
33
|
-
export declare function encodedProjectGroupFromPath(filePath: string): string | null;
|
|
34
|
-
export interface FileFingerprint {
|
|
35
|
-
prefix: string;
|
|
36
|
-
suffix: string;
|
|
37
|
-
size: number;
|
|
38
|
-
encoded: string;
|
|
39
|
-
}
|
|
40
|
-
/** Prefix + suffix + size. Compaction that keeps a stable header still
|
|
41
|
-
* changes the tail or the length, so the watermark resets. */
|
|
42
|
-
export declare function fileFingerprint(fd: number, size: number): FileFingerprint;
|
|
43
|
-
export declare function parseFingerprint(encoded: string): {
|
|
44
|
-
prefix: string;
|
|
45
|
-
suffix: string;
|
|
46
|
-
size: number;
|
|
47
|
-
} | null;
|
|
48
|
-
/**
|
|
49
|
-
* Unchanged file: resume. Append (header still in place, grew, old tail
|
|
50
|
-
* still at the previous end): resume. Anything else — including a compacted
|
|
51
|
-
* body behind the same header — reset.
|
|
52
|
-
*
|
|
53
|
-
* Do not compare `current.prefix` to `prev.prefix` when the file is shorter
|
|
54
|
-
* than the fingerprint window: that hash covers the whole file, so a one-byte
|
|
55
|
-
* append changes the prefix and looks like a rewrite.
|
|
56
|
-
*/
|
|
57
|
-
export declare function shouldResumeFromWatermark(fd: number, stored: string, byteOffset: number, current: FileFingerprint): boolean;
|
|
58
|
-
//# sourceMappingURL=jsonl-ingest.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jsonl-ingest.d.ts","sourceRoot":"","sources":["../../src/sources/jsonl-ingest.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAcH,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,qBAAqB,CAAC;AAE9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAOzD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,iBAAiB,GAAG,CAC9B,GAAG,EAAE,MAAM,EACX,iBAAiB,EAAE,MAAM,EACzB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,KACf,eAAe,EAAE,CAAC;AAEvB,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,iBAAiB,CAAC;CAC5B;AAED;;;GAGG;AACH,wBAAsB,eAAe,CACnC,EAAE,EAAE,EAAE,EACN,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,aAAa,CAAC,CAwExB;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAMxC;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAK/C;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAK3E;AAMD,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAQD;+DAC+D;AAC/D,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,eAAe,CAKzE;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,IAAI,CAMP;AAED;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CACvC,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,eAAe,GACvB,OAAO,CAYT"}
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared JSONL tail: watermark, fingerprint, insert.
|
|
3
|
-
*
|
|
4
|
-
* Adapters discover files and map lines. This module is the one ingest
|
|
5
|
-
* path so a crash cannot duplicate a line, regardless of which client
|
|
6
|
-
* wrote the transcript.
|
|
7
|
-
*/
|
|
8
|
-
import { createHash } from "node:crypto";
|
|
9
|
-
import { closeSync, existsSync, fstatSync, openSync, readSync, readdirSync, statSync, } from "node:fs";
|
|
10
|
-
import path from "node:path";
|
|
11
|
-
import { withTransaction } from "../db/connection.js";
|
|
12
|
-
import { ensureSession, insertEvent } from "../db/sessions.js";
|
|
13
|
-
import { getWatermark, upsertWatermark } from "../db/watermarks.js";
|
|
14
|
-
/** Window hashed at each end of the file. Prefix alone misses a rewrite
|
|
15
|
-
* (compaction) that keeps the same header. */
|
|
16
|
-
const FINGERPRINT_BYTES = 256;
|
|
17
|
-
/**
|
|
18
|
-
* Tail one JSONL file into session_events from its watermark. Inserts and the
|
|
19
|
-
* watermark update share a transaction so a crash cannot duplicate a line.
|
|
20
|
-
*/
|
|
21
|
-
export async function ingestJsonlFile(db, filePath, opts) {
|
|
22
|
-
const abs = path.resolve(filePath);
|
|
23
|
-
const fd = openSync(abs, "r");
|
|
24
|
-
try {
|
|
25
|
-
const size = fstatSync(fd).size;
|
|
26
|
-
const current = fileFingerprint(fd, size);
|
|
27
|
-
const existing = await getWatermark(db, abs);
|
|
28
|
-
const resume = existing &&
|
|
29
|
-
existing.byte_offset <= size &&
|
|
30
|
-
shouldResumeFromWatermark(fd, existing.fingerprint, existing.byte_offset, current)
|
|
31
|
-
? existing
|
|
32
|
-
: null;
|
|
33
|
-
const fingerprint = current.encoded;
|
|
34
|
-
const startOffset = resume?.byte_offset ?? 0;
|
|
35
|
-
const startLine = resume?.line_number ?? 0;
|
|
36
|
-
const { lines, endOffset } = readCompleteLines(fd, startOffset, size);
|
|
37
|
-
const sessionId = sessionIdFromPath(abs);
|
|
38
|
-
const project = encodedProjectGroupFromPath(abs);
|
|
39
|
-
if (lines.length === 0 && resume) {
|
|
40
|
-
// File unchanged, or only an incomplete last line past the watermark.
|
|
41
|
-
// Leave the watermark where it is: a later append that completes the
|
|
42
|
-
// line is detected as growth and resumed from this offset.
|
|
43
|
-
// Still record the conversation's project so a store that was pulled
|
|
44
|
-
// before sessions.project was written gets provenance on the next pull.
|
|
45
|
-
await ensureSession(db, {
|
|
46
|
-
id: sessionId,
|
|
47
|
-
source_tool: opts.sourceTool,
|
|
48
|
-
project,
|
|
49
|
-
});
|
|
50
|
-
return { path: abs, inserted: 0, skipped: 0 };
|
|
51
|
-
}
|
|
52
|
-
let inserted = 0;
|
|
53
|
-
let skipped = 0;
|
|
54
|
-
let lineNumber = startLine;
|
|
55
|
-
await withTransaction(db, async () => {
|
|
56
|
-
const seen = new Set();
|
|
57
|
-
for (const line of lines) {
|
|
58
|
-
lineNumber += 1;
|
|
59
|
-
const mapped = opts.mapLine(line, sessionId, abs, lineNumber, opts.sourceTool);
|
|
60
|
-
if (mapped.length === 0) {
|
|
61
|
-
skipped += 1;
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
for (const event of mapped) {
|
|
65
|
-
const conversation = event.client_session_id || sessionId;
|
|
66
|
-
if (!seen.has(conversation)) {
|
|
67
|
-
seen.add(conversation);
|
|
68
|
-
await ensureSession(db, {
|
|
69
|
-
id: conversation,
|
|
70
|
-
source_tool: opts.sourceTool,
|
|
71
|
-
project,
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
await insertEvent(db, event);
|
|
75
|
-
inserted += 1;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
await upsertWatermark(db, {
|
|
79
|
-
path: abs,
|
|
80
|
-
byte_offset: endOffset,
|
|
81
|
-
line_number: lineNumber,
|
|
82
|
-
fingerprint,
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
return { path: abs, inserted, skipped };
|
|
86
|
-
}
|
|
87
|
-
finally {
|
|
88
|
-
closeSync(fd);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
export function isDir(p) {
|
|
92
|
-
try {
|
|
93
|
-
return existsSync(p) && statSync(p).isDirectory();
|
|
94
|
-
}
|
|
95
|
-
catch {
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
export function listJsonl(dir) {
|
|
100
|
-
if (!isDir(dir))
|
|
101
|
-
return [];
|
|
102
|
-
return readdirSync(dir, { withFileTypes: true })
|
|
103
|
-
.filter((entry) => entry.isFile() && entry.name.endsWith(".jsonl"))
|
|
104
|
-
.map((entry) => path.join(dir, entry.name));
|
|
105
|
-
}
|
|
106
|
-
export function sessionIdFromPath(filePath) {
|
|
107
|
-
return path.basename(filePath, ".jsonl");
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* On-disk group under `home/projects/<group>/`.
|
|
111
|
-
* That encoded name is the provenance we store on `sessions.project` —
|
|
112
|
-
* not a tenant, and not a decoded filesystem path (encoding is lossy).
|
|
113
|
-
*/
|
|
114
|
-
export function encodedProjectGroupFromPath(filePath) {
|
|
115
|
-
const parts = path.normalize(filePath).split(path.sep);
|
|
116
|
-
const i = parts.lastIndexOf("projects");
|
|
117
|
-
if (i < 0 || i + 1 >= parts.length)
|
|
118
|
-
return null;
|
|
119
|
-
return parts[i + 1] || null;
|
|
120
|
-
}
|
|
121
|
-
function hashWindow(fd, position, length) {
|
|
122
|
-
const buf = Buffer.alloc(length);
|
|
123
|
-
if (length > 0)
|
|
124
|
-
readSync(fd, buf, 0, length, position);
|
|
125
|
-
return createHash("sha256").update(buf).digest("hex");
|
|
126
|
-
}
|
|
127
|
-
/** Prefix + suffix + size. Compaction that keeps a stable header still
|
|
128
|
-
* changes the tail or the length, so the watermark resets. */
|
|
129
|
-
export function fileFingerprint(fd, size) {
|
|
130
|
-
const n = Math.min(FINGERPRINT_BYTES, size);
|
|
131
|
-
const prefix = hashWindow(fd, 0, n);
|
|
132
|
-
const suffix = hashWindow(fd, Math.max(0, size - n), n);
|
|
133
|
-
return { prefix, suffix, size, encoded: `${prefix}:${suffix}:${size}` };
|
|
134
|
-
}
|
|
135
|
-
export function parseFingerprint(encoded) {
|
|
136
|
-
const parts = encoded.split(":");
|
|
137
|
-
if (parts.length !== 3)
|
|
138
|
-
return null;
|
|
139
|
-
const size = Number(parts[2]);
|
|
140
|
-
if (!Number.isFinite(size))
|
|
141
|
-
return null;
|
|
142
|
-
return { prefix: parts[0], suffix: parts[1], size };
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Unchanged file: resume. Append (header still in place, grew, old tail
|
|
146
|
-
* still at the previous end): resume. Anything else — including a compacted
|
|
147
|
-
* body behind the same header — reset.
|
|
148
|
-
*
|
|
149
|
-
* Do not compare `current.prefix` to `prev.prefix` when the file is shorter
|
|
150
|
-
* than the fingerprint window: that hash covers the whole file, so a one-byte
|
|
151
|
-
* append changes the prefix and looks like a rewrite.
|
|
152
|
-
*/
|
|
153
|
-
export function shouldResumeFromWatermark(fd, stored, byteOffset, current) {
|
|
154
|
-
if (stored === current.encoded && byteOffset <= current.size)
|
|
155
|
-
return true;
|
|
156
|
-
const prev = parseFingerprint(stored);
|
|
157
|
-
if (!prev)
|
|
158
|
-
return false;
|
|
159
|
-
if (current.size < prev.size || byteOffset > current.size)
|
|
160
|
-
return false;
|
|
161
|
-
const prefixLen = Math.min(FINGERPRINT_BYTES, prev.size);
|
|
162
|
-
if (hashWindow(fd, 0, prefixLen) !== prev.prefix)
|
|
163
|
-
return false;
|
|
164
|
-
if (current.size === prev.size)
|
|
165
|
-
return prev.suffix === current.suffix;
|
|
166
|
-
// Grew: only treat as an append if the previous tail is still where it was.
|
|
167
|
-
const oldWindow = Math.min(FINGERPRINT_BYTES, prev.size);
|
|
168
|
-
const stillThere = hashWindow(fd, Math.max(0, prev.size - oldWindow), oldWindow);
|
|
169
|
-
return stillThere === prev.suffix;
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Read from `startOffset` to EOF and return only complete lines (those
|
|
173
|
-
* terminated by `\\n`). The returned `endOffset` is the byte position after
|
|
174
|
-
* the last complete line, so a file still being written is not consumed past
|
|
175
|
-
* a partial line.
|
|
176
|
-
*/
|
|
177
|
-
function readCompleteLines(fd, startOffset, size) {
|
|
178
|
-
const remaining = size - startOffset;
|
|
179
|
-
if (remaining <= 0)
|
|
180
|
-
return { lines: [], endOffset: startOffset };
|
|
181
|
-
const buf = Buffer.alloc(remaining);
|
|
182
|
-
const bytesRead = readSync(fd, buf, 0, remaining, startOffset);
|
|
183
|
-
const slice = buf.subarray(0, bytesRead);
|
|
184
|
-
const lastNl = slice.lastIndexOf(0x0a);
|
|
185
|
-
if (lastNl === -1)
|
|
186
|
-
return { lines: [], endOffset: startOffset };
|
|
187
|
-
const complete = slice.subarray(0, lastNl + 1);
|
|
188
|
-
const text = complete.toString("utf8");
|
|
189
|
-
const lines = text.split("\n");
|
|
190
|
-
// split() after a trailing newline yields a final empty string — drop it.
|
|
191
|
-
if (lines.length > 0 && lines[lines.length - 1] === "")
|
|
192
|
-
lines.pop();
|
|
193
|
-
return { lines, endOffset: startOffset + complete.length };
|
|
194
|
-
}
|
|
195
|
-
//# sourceMappingURL=jsonl-ingest.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jsonl-ingest.js","sourceRoot":"","sources":["../../src/sources/jsonl-ingest.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,SAAS,EACT,UAAU,EACV,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,QAAQ,GACT,MAAM,SAAS,CAAC;AACjB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE/D,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEpE;+CAC+C;AAC/C,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAqB9B;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,EAAM,EACN,QAAgB,EAChB,IAAwB;IAExB,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACnC,MAAM,EAAE,GAAG,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC9B,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,SAAS,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC;QAChC,MAAM,OAAO,GAAG,eAAe,CAAC,EAAE,EAAE,IAAI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AAE,CAAC;IAEjE,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IACpC,MAAM,SAAS,GAAG,QAAQ,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;IAC/D,MAAM,KAAK,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;IACzC,MAAM,MAAM,GAAG,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACvC,IAAI,MAAM,KAAK,CAAC,CAAC;QAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;IAEhE,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC;IAC/C,MAAM,IAAI,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACvC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/B,0EAA0E;IAC1E,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE;QAAE,KAAK,CAAC,GAAG,EAAE,CAAC;IACpE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC;AAC7D,CAAC"}
|
package/dist/sources/pull.d.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pull named capture sources into session_events.
|
|
3
|
-
*
|
|
4
|
-
* This is the single entry for client-agnostic capture. `factmem pull`
|
|
5
|
-
* is the documented command; the MCP server calls the same function at
|
|
6
|
-
* session start and, on a named-source store, again at the start of a
|
|
7
|
-
* tool or resource read when the files have grown. Empty `sources` is a
|
|
8
|
-
* successful no-op — pull is off, and the heartbeat never walks a client
|
|
9
|
-
* home.
|
|
10
|
-
*/
|
|
11
|
-
import type { Db } from "../db/connection.js";
|
|
12
|
-
export interface PullResult {
|
|
13
|
-
/** How many configured sources were resolved and walked. */
|
|
14
|
-
sources: number;
|
|
15
|
-
/** Transcript files discovered across those sources. */
|
|
16
|
-
files: number;
|
|
17
|
-
/** New session_events inserted this run. */
|
|
18
|
-
events_inserted: number;
|
|
19
|
-
/** Complete lines that could not be mapped honestly (system/meta/empty). */
|
|
20
|
-
events_skipped: number;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* A first pull of a whole Claude home can insert thousands of events.
|
|
24
|
-
* Flushing those at session_start would spawn `claude -p` on the lot.
|
|
25
|
-
* Incremental pulls of a handful of new lines still match session_start
|
|
26
|
-
* intent and may run extract-then-graduate. Zero inserts keep leftover
|
|
27
|
-
* recovery (scheduler.full()).
|
|
28
|
-
*/
|
|
29
|
-
export declare const SESSION_START_FLUSH_MAX_INSERTED = 50;
|
|
30
|
-
/** Whether session_start should call scheduler.full() after this pull. */
|
|
31
|
-
export declare function shouldFlushAfterSessionStartPull(eventsInserted: number, threshold?: number): boolean;
|
|
32
|
-
/**
|
|
33
|
-
* Whether the CLI pull should wake a running server with `tick`.
|
|
34
|
-
*
|
|
35
|
-
* Same band as session_start: a handful of new lines may extract
|
|
36
|
-
* (threshold permitting). A first-run backfill above the cap must not.
|
|
37
|
-
* Zero inserts send nothing — leftovers are session_start's job.
|
|
38
|
-
*
|
|
39
|
-
* `tick` is D→I, not I→K: it honours the consolidation threshold so a
|
|
40
|
-
* frequent incremental pull does not spawn `claude -p` on every reply.
|
|
41
|
-
* A pull with no server listening cannot tick; the CLI then tells the
|
|
42
|
-
* user to run `factmem consolidate`.
|
|
43
|
-
*/
|
|
44
|
-
export declare function shouldTickAfterCliPull(eventsInserted: number, threshold?: number): boolean;
|
|
45
|
-
/** In-process throttle for MCP-call tails. Not a product timer. */
|
|
46
|
-
export declare const PULL_HEARTBEAT_DEBOUNCE_MS = 2000;
|
|
47
|
-
export type PullFollowUp = "tick" | "flush" | "none";
|
|
48
|
-
/**
|
|
49
|
-
* What the CLI does after copying D. `--flush` is compact wake-up
|
|
50
|
-
* (graduate, not extract). `--no-tick` copies only. Default still ticks
|
|
51
|
-
* a handful of new lines when a server is listening.
|
|
52
|
-
*/
|
|
53
|
-
export declare function pullFollowUp(opts: {
|
|
54
|
-
flush: boolean;
|
|
55
|
-
noTick: boolean;
|
|
56
|
-
eventsInserted: number;
|
|
57
|
-
}): PullFollowUp;
|
|
58
|
-
export interface PullHeartbeat {
|
|
59
|
-
/** Copy new JSONL lines if files grew. Never extracts. */
|
|
60
|
-
pullIfGrown(): Promise<PullResult>;
|
|
61
|
-
}
|
|
62
|
-
export interface PullHeartbeatOpts {
|
|
63
|
-
db: Db;
|
|
64
|
-
sources: unknown;
|
|
65
|
-
debounceMs?: number;
|
|
66
|
-
now?: () => number;
|
|
67
|
-
/** Override for tests. Production uses `pullSources`. */
|
|
68
|
-
pull?: (db: Db, sources: unknown) => Promise<PullResult>;
|
|
69
|
-
onPulled?: (result: PullResult) => void;
|
|
70
|
-
onError?: (err: Error) => void;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* In-process JSONL tail for a live MCP server. Empty `sources` never
|
|
74
|
-
* discovers files (so a record store does not open `~/.claude`). A burst
|
|
75
|
-
* of tool calls in one turn shares one walk.
|
|
76
|
-
*/
|
|
77
|
-
export declare function createPullHeartbeat(opts: PullHeartbeatOpts): PullHeartbeat;
|
|
78
|
-
/**
|
|
79
|
-
* Resolve `config.sources` and ingest every new transcript line.
|
|
80
|
-
*
|
|
81
|
-
* Throws on an unknown kind or a malformed source — a typo must not look
|
|
82
|
-
* like "nothing to pull". An empty list returns zeros and inserts nothing.
|
|
83
|
-
*/
|
|
84
|
-
export declare function pullSources(db: Db, sources: unknown): Promise<PullResult>;
|
|
85
|
-
//# sourceMappingURL=pull.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-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