@gramatr/mcp 0.13.71 → 0.13.74
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/bin/brain.d.ts +103 -22
- package/dist/bin/brain.d.ts.map +1 -1
- package/dist/bin/brain.js +399 -149
- package/dist/bin/brain.js.map +1 -1
- package/dist/hooks/git-gate.d.ts +42 -2
- package/dist/hooks/git-gate.d.ts.map +1 -1
- package/dist/hooks/git-gate.js +333 -16
- package/dist/hooks/git-gate.js.map +1 -1
- package/package.json +1 -1
package/dist/bin/brain.d.ts
CHANGED
|
@@ -1,23 +1,50 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* brain — CLI subcommand for bulk file upload to the grāmatr brain.
|
|
3
3
|
*
|
|
4
|
-
* Reads local files (txt, md, csv, pdf, docx)
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Reads local files (txt, md, csv, pdf, docx) and uploads them to the server
|
|
5
|
+
* via the `bulk_upload` MCP tool. The server is the single source of truth
|
|
6
|
+
* for validation, idempotency (sha256-based dedup), virus scanning (ClamAV),
|
|
7
|
+
* and entity/observation creation. The CLI is a thin wrapper.
|
|
8
|
+
*
|
|
9
|
+
* Migrated in epic #1904 PR 3 from the legacy `create_entity` + `add_observation`
|
|
10
|
+
* chain. The orphan-fix that PR 1 added to `resolveEntityId` is now obsolete:
|
|
11
|
+
* idempotency is enforced server-side via `on_duplicate`.
|
|
8
12
|
*
|
|
9
13
|
* Usage:
|
|
10
|
-
* gramatr brain upload <file>
|
|
11
|
-
* gramatr brain upload --dir <dir>
|
|
12
|
-
* gramatr brain upload --dir <dir> --recursive
|
|
13
|
-
* gramatr brain upload <file> --entity-id <id>
|
|
14
|
-
* gramatr brain upload <file> --entity-name <name>
|
|
14
|
+
* gramatr brain upload <file> [flags]
|
|
15
|
+
* gramatr brain upload --dir <dir> [--recursive] [flags]
|
|
15
16
|
* gramatr brain --help
|
|
17
|
+
*
|
|
18
|
+
* New flags (PR 3):
|
|
19
|
+
* --scope <user|team|org|public> Sharing scope (default: user)
|
|
20
|
+
* --project-id <id> Optional project association
|
|
21
|
+
* --team-id <id> Required when --scope=team
|
|
22
|
+
* --org-id <id> Required when --scope=org
|
|
23
|
+
* --public Shorthand for --scope=public
|
|
24
|
+
* --entity-type <type> Entity type (default: reference)
|
|
25
|
+
* --metadata <k=v> Repeatable. Adds to entity metadata
|
|
26
|
+
* --tags <t1,t2,...> Comma-separated topic tags
|
|
27
|
+
* --on-duplicate <skip|reuse|new-version>
|
|
28
|
+
* Dedup policy (default: reuse)
|
|
29
|
+
*
|
|
30
|
+
* Exit codes:
|
|
31
|
+
* 0 — all files uploaded (or skipped via on-duplicate=skip)
|
|
32
|
+
* 1 — at least one non-validation error (network/server 5xx)
|
|
33
|
+
* 2 — config error (bad flag combination, missing required value)
|
|
34
|
+
* 3 — at least one file rejected by a validator (oversize, av_*, etc.)
|
|
35
|
+
*
|
|
36
|
+
* NOTE: Until ClamAV is deployed in production (n90-co/prod-argocd-v2#409),
|
|
37
|
+
* every CLI upload returns `av_unconfigured` from the server. This is
|
|
38
|
+
* intentional fail-closed behaviour. There is no client-side bypass.
|
|
16
39
|
*/
|
|
17
40
|
export declare const SUPPORTED_EXTENSIONS: Set<string>;
|
|
18
41
|
/**
|
|
19
42
|
* Extract plain text from a file buffer based on its extension.
|
|
20
|
-
* Returns null if the extension is unsupported
|
|
43
|
+
* Returns null if the extension is unsupported.
|
|
44
|
+
*
|
|
45
|
+
* NOTE: as of PR 3, the bulk_upload pipeline ships the raw bytes to the server
|
|
46
|
+
* (which performs its own validation + storage). This helper is preserved for
|
|
47
|
+
* existing callers and unit-test scaffolding only.
|
|
21
48
|
*/
|
|
22
49
|
export declare function extractText(filePath: string, buffer: Buffer): Promise<string | null>;
|
|
23
50
|
/**
|
|
@@ -26,30 +53,84 @@ export declare function extractText(filePath: string, buffer: Buffer): Promise<s
|
|
|
26
53
|
*/
|
|
27
54
|
export declare function deriveEntityName(filePath: string): string;
|
|
28
55
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* 1. --entity-id <id> — use the ID directly (no server call)
|
|
33
|
-
* 2. --entity-name <name> — create_entity with that name
|
|
34
|
-
* 3. fallback — create_entity using the filename (without extension)
|
|
35
|
-
*
|
|
36
|
-
* Returns the entity ID as a string, or throws on failure.
|
|
56
|
+
* Map a server-side `UploadValidationError.reason` to the documented
|
|
57
|
+
* user-friendly CLI message. Reasons not in the table are passed through
|
|
58
|
+
* verbatim so unexpected server errors are still visible.
|
|
37
59
|
*/
|
|
38
|
-
export declare
|
|
60
|
+
export declare const VALIDATION_REASON_MESSAGES: Record<string, string>;
|
|
61
|
+
/**
|
|
62
|
+
* Render the user-friendly message for a validation reason. For `av_infected`
|
|
63
|
+
* the signature is appended when supplied.
|
|
64
|
+
*/
|
|
65
|
+
export declare function formatValidationMessage(reason: string, opts?: {
|
|
66
|
+
signature?: string;
|
|
67
|
+
}): string;
|
|
68
|
+
export interface ParsedArgs {
|
|
69
|
+
positionals: string[];
|
|
70
|
+
entityId?: string;
|
|
71
|
+
entityName?: string;
|
|
72
|
+
dir?: string;
|
|
73
|
+
recursive: boolean;
|
|
74
|
+
dryRun: boolean;
|
|
75
|
+
scope?: string;
|
|
76
|
+
projectId?: string;
|
|
77
|
+
teamId?: string;
|
|
78
|
+
orgId?: string;
|
|
79
|
+
publicShorthand: boolean;
|
|
80
|
+
entityType?: string;
|
|
81
|
+
metadata: string[];
|
|
82
|
+
tags?: string;
|
|
83
|
+
onDuplicate?: string;
|
|
84
|
+
}
|
|
85
|
+
export declare function parseUploadArgs(args: string[]): ParsedArgs;
|
|
86
|
+
export interface ValidatedConfig {
|
|
87
|
+
scope: 'user' | 'team' | 'org' | 'public';
|
|
88
|
+
projectId?: string;
|
|
89
|
+
teamId?: string;
|
|
90
|
+
orgId?: string;
|
|
91
|
+
isPublic: boolean;
|
|
92
|
+
entityType: string;
|
|
93
|
+
metadata: Record<string, string>;
|
|
94
|
+
tags: string[];
|
|
95
|
+
onDuplicate: 'skip' | 'reuse' | 'new-version';
|
|
96
|
+
}
|
|
97
|
+
export interface ValidationFailure {
|
|
98
|
+
ok: false;
|
|
99
|
+
message: string;
|
|
100
|
+
}
|
|
101
|
+
export interface ValidationSuccess {
|
|
102
|
+
ok: true;
|
|
103
|
+
config: ValidatedConfig;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Validate the parsed flag combination. Returns either a normalized config or
|
|
107
|
+
* a structured error message. Pure — does not write to stderr or exit.
|
|
108
|
+
*/
|
|
109
|
+
export declare function validateUploadConfig(parsed: ParsedArgs): ValidationFailure | ValidationSuccess;
|
|
39
110
|
export interface UploadFileOptions {
|
|
40
111
|
entityId?: string;
|
|
41
112
|
entityName?: string;
|
|
113
|
+
config: ValidatedConfig;
|
|
42
114
|
}
|
|
43
115
|
export interface UploadResult {
|
|
44
116
|
file: string;
|
|
45
117
|
entityId?: string;
|
|
118
|
+
observationId?: string;
|
|
119
|
+
wasDuplicate?: boolean;
|
|
46
120
|
error?: string;
|
|
121
|
+
/** True iff the failure was a server-side validation rejection. */
|
|
122
|
+
validationReason?: string;
|
|
47
123
|
skipped?: boolean;
|
|
48
124
|
}
|
|
49
125
|
/**
|
|
50
|
-
*
|
|
126
|
+
* Build the bulk_upload tool input for a given file. Exported so tests can
|
|
127
|
+
* assert the exact shape forwarded to the server.
|
|
128
|
+
*/
|
|
129
|
+
export declare function buildBulkUploadInput(filePath: string, buffer: Buffer, options: UploadFileOptions): Record<string, unknown>;
|
|
130
|
+
/**
|
|
131
|
+
* Upload a single file via the `bulk_upload` MCP tool.
|
|
51
132
|
*/
|
|
52
|
-
export declare function uploadFile(filePath: string, options
|
|
133
|
+
export declare function uploadFile(filePath: string, options: UploadFileOptions): Promise<UploadResult>;
|
|
53
134
|
/**
|
|
54
135
|
* Collect all supported files in a directory.
|
|
55
136
|
* @param dir Absolute or relative path to the directory
|
|
@@ -58,7 +139,7 @@ export declare function uploadFile(filePath: string, options?: UploadFileOptions
|
|
|
58
139
|
export declare function collectFiles(dir: string, recursive: boolean): string[];
|
|
59
140
|
/**
|
|
60
141
|
* runBrain — entry point for `gramatr brain <args>` subcommand.
|
|
61
|
-
* Returns an exit code (0
|
|
142
|
+
* Returns an exit code (0/1/2/3 — see top of file).
|
|
62
143
|
*/
|
|
63
144
|
export declare function runBrain(args: string[]): Promise<number>;
|
|
64
145
|
//# sourceMappingURL=brain.d.ts.map
|
package/dist/bin/brain.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"brain.d.ts","sourceRoot":"","sources":["../../src/bin/brain.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"brain.d.ts","sourceRoot":"","sources":["../../src/bin/brain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAQH,eAAO,MAAM,oBAAoB,aAAoD,CAAC;AAItF;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAC/B,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAoBxB;AAID;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAIzD;AAID;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAc7D,CAAC;AAIF;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5B,MAAM,CAOR;AAyBD,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,GAAG,CAA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