@attentionform/astra-mcp-server 0.0.0-stage → 0.2.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 +206 -0
- package/NOTICE +12 -0
- package/README.md +500 -2
- package/dist/index.d.ts +63 -0
- package/dist/index.js +43889 -0
- package/dist/lib/index.d.ts +10 -0
- package/dist/lib/mcp/baseline-gate.d.ts +71 -0
- package/dist/lib/mcp/descriptions.d.ts +12 -0
- package/dist/lib/mcp/diff.d.ts +220 -0
- package/dist/lib/mcp/errors.d.ts +45 -0
- package/dist/lib/mcp/handlers/export-audit.d.ts +34 -0
- package/dist/lib/mcp/handlers/history.d.ts +93 -0
- package/dist/lib/mcp/handlers/open-inspect.d.ts +71 -0
- package/dist/lib/mcp/handlers/parity.d.ts +127 -0
- package/dist/lib/mcp/handlers/save-close.d.ts +96 -0
- package/dist/lib/mcp/handlers/search-batch.d.ts +55 -0
- package/dist/lib/mcp/normalize-read.d.ts +11 -0
- package/dist/lib/mcp/registry.d.ts +12 -0
- package/dist/lib/mcp/schema-dump.d.ts +24 -0
- package/dist/lib/mcp/schemas.d.ts +953 -0
- package/dist/lib/mcp/tool-names.d.ts +15 -0
- package/dist/lib/mcp-tool-adapter.d.ts +12 -0
- package/dist/lib/session-store.d.ts +432 -0
- package/dist/tools/compose-document.d.ts +124 -0
- package/dist/tools/export.d.ts +53 -0
- package/dist/tools/new-document.d.ts +53 -0
- package/dist/tools/visual.d.ts +161 -0
- package/package.json +69 -4
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { PII_COVERAGE } from '@attentionform/astra-engine';
|
|
2
|
+
import { type McpSessionStore } from '../../session-store';
|
|
3
|
+
import { handleComposeDocument } from '../../../tools/compose-document';
|
|
4
|
+
import type { McpErrorShape } from '../errors';
|
|
5
|
+
export interface AuditValidation {
|
|
6
|
+
valid: boolean;
|
|
7
|
+
errorCount: number;
|
|
8
|
+
errors: Array<{
|
|
9
|
+
description: string;
|
|
10
|
+
xPath?: string;
|
|
11
|
+
}>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* validate_document: strictly read-only preflight ISO audit. The verdict runs
|
|
15
|
+
* on an isolated fork (see serializeSessionFork): revision, dirty flag,
|
|
16
|
+
* normalizer log, disk bytes, and history are all untouched. Never throws —
|
|
17
|
+
* every failure maps to {ok:false,code,remedy}.
|
|
18
|
+
*/
|
|
19
|
+
export declare function handleValidateDocument(store: McpSessionStore, input: unknown): Promise<{
|
|
20
|
+
ok: true;
|
|
21
|
+
sessionId: string;
|
|
22
|
+
revision: number;
|
|
23
|
+
dirty: boolean;
|
|
24
|
+
validation: AuditValidation;
|
|
25
|
+
/** Repairs a save would make (e.g. children put in schema order); absent when none. */
|
|
26
|
+
pendingNormalizations?: string[];
|
|
27
|
+
/** Advice when normalize_document can repair errors in the document. */
|
|
28
|
+
normalizeHint?: string;
|
|
29
|
+
} | McpErrorShape>;
|
|
30
|
+
/**
|
|
31
|
+
* get_stats: token-cheap census over the live AST (pure read: no revision
|
|
32
|
+
* bump, no dirty flip). Counters come from computeDocStats in @attentionform/astra-engine —
|
|
33
|
+
* the same definition CLI stats prints — so the two surfaces cannot drift.
|
|
34
|
+
* Never throws.
|
|
35
|
+
*/
|
|
36
|
+
export declare function handleGetStats(store: McpSessionStore, input: unknown): Promise<{
|
|
37
|
+
ok: true;
|
|
38
|
+
sessionId: string;
|
|
39
|
+
revision: number;
|
|
40
|
+
dirty: boolean;
|
|
41
|
+
words: number;
|
|
42
|
+
paragraphs: number;
|
|
43
|
+
tables: number;
|
|
44
|
+
images: number;
|
|
45
|
+
pages: number;
|
|
46
|
+
} | McpErrorShape>;
|
|
47
|
+
export interface SanitizeDocumentOk {
|
|
48
|
+
ok: true;
|
|
49
|
+
sessionId: string;
|
|
50
|
+
revision: number;
|
|
51
|
+
dirty: boolean;
|
|
52
|
+
removedRSIDs: number;
|
|
53
|
+
purgedAuthors: number;
|
|
54
|
+
strippedExifBytes: number;
|
|
55
|
+
purgedPII: number;
|
|
56
|
+
bodyPII: number;
|
|
57
|
+
piiCoverage: typeof PII_COVERAGE;
|
|
58
|
+
piiNote: string;
|
|
59
|
+
acceptedRevisions: number;
|
|
60
|
+
strippedComments: number;
|
|
61
|
+
strippedMacros: string[];
|
|
62
|
+
macroParts: string[];
|
|
63
|
+
filesTouched: string[];
|
|
64
|
+
droppedRogue: string[];
|
|
65
|
+
revisionsPending: number;
|
|
66
|
+
revisionsRemedy?: string;
|
|
67
|
+
redoCleared?: boolean;
|
|
68
|
+
redoClearedWarning?: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* sanitize_document: scrub the open session through the engine scrub path
|
|
72
|
+
* (validateSanitizeOptionsStrict + sanitizeDocxBuffer — the exact validator
|
|
73
|
+
* and buffer scrub CLI sanitize calls). The sanitized bytes replace the live
|
|
74
|
+
* package (snapshot restore on the same parser, AST refreshed in place), the
|
|
75
|
+
* revision bumps, and the redo chain clears (a fresh edit invalidates redo).
|
|
76
|
+
* Never throws.
|
|
77
|
+
*/
|
|
78
|
+
export declare function handleSanitizeDocument(store: McpSessionStore, input: unknown): Promise<SanitizeDocumentOk | McpErrorShape>;
|
|
79
|
+
/**
|
|
80
|
+
* normalize_document: canonical repair of the open session through the core
|
|
81
|
+
* rezip hook (the hook CLI normalize drives). Heals the live DOM, refreshes
|
|
82
|
+
* the session view, then proves the result with a forked validation verdict.
|
|
83
|
+
* When the package is still invalid afterwards, the pre-run snapshot is
|
|
84
|
+
* restored (revision untouched) and the call fails closed with E_VALIDATION —
|
|
85
|
+
* the in-memory analogue of CLI normalize writing nothing on failure. Output
|
|
86
|
+
* bytes match CLI normalize on the same input. Never throws.
|
|
87
|
+
*/
|
|
88
|
+
export declare function handleNormalizeDocument(store: McpSessionStore, input: unknown): Promise<{
|
|
89
|
+
ok: true;
|
|
90
|
+
sessionId: string;
|
|
91
|
+
revision: number;
|
|
92
|
+
dirty: boolean;
|
|
93
|
+
normalized: string[];
|
|
94
|
+
preStateCommit?: string;
|
|
95
|
+
remaining: number;
|
|
96
|
+
rolledBack: {
|
|
97
|
+
rule: string;
|
|
98
|
+
reason: string;
|
|
99
|
+
}[];
|
|
100
|
+
validation: AuditValidation & {
|
|
101
|
+
tolerated?: true;
|
|
102
|
+
preExistingErrors?: number;
|
|
103
|
+
introducedErrors?: 0;
|
|
104
|
+
};
|
|
105
|
+
revisionsPending: number;
|
|
106
|
+
revisionsRemedy?: string;
|
|
107
|
+
redoCleared?: boolean;
|
|
108
|
+
redoClearedWarning?: string;
|
|
109
|
+
} | McpErrorShape>;
|
|
110
|
+
/**
|
|
111
|
+
* Jailed Markdown read for import_document. Verdict table mirrors the
|
|
112
|
+
* batch image-file read precedent: outside the workspace roots -> E_SANDBOX,
|
|
113
|
+
* missing/unreadable -> E_IO, oversize -> E_LIMIT, unusable -> E_VALIDATION.
|
|
114
|
+
* Symlinks are refused at open (O_NOFOLLOW) with containment re-checked after
|
|
115
|
+
* the read, so a swapped link cannot escape the jail mid-call.
|
|
116
|
+
*/
|
|
117
|
+
export declare function readImportMarkdownFile(rawPath: unknown, roots?: string[]): string;
|
|
118
|
+
/**
|
|
119
|
+
* import_document: jailed file read + the existing compose pipeline, ingested
|
|
120
|
+
* into the OPEN session only (sessionId strictly required, never
|
|
121
|
+
* auto-created). Format table mirrors CLI import: .md/.markdown/.txt read as
|
|
122
|
+
* Markdown; .html/.htm refused with the CLI-identical verdict; .docx refused
|
|
123
|
+
* naming open_document; anything else refused as an unknown format. After the
|
|
124
|
+
* gates, the call delegates to handleComposeDocument itself, so the result is
|
|
125
|
+
* byte-equal to composing the same Markdown inline. Never throws.
|
|
126
|
+
*/
|
|
127
|
+
export declare function handleImportDocument(store: McpSessionStore, input: unknown): Promise<Awaited<ReturnType<typeof handleComposeDocument>>>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { type StyleWarning } from '@attentionform/astra-engine';
|
|
2
|
+
import type { McpSessionStore } from '../../session-store';
|
|
3
|
+
import type { McpErrorShape } from '../errors';
|
|
4
|
+
import type { ChangedValue } from '../diff';
|
|
5
|
+
/**
|
|
6
|
+
* Validating save — throwing core.
|
|
7
|
+
* M2 contract (consistent, tested):
|
|
8
|
+
* - executeSaveDocument THROWS on every failure (invalid input E_VALIDATION,
|
|
9
|
+
* unknown/expired session E_SESSION, sandbox escape E_SANDBOX, invalid
|
|
10
|
+
* package E_VALIDATION, write failure E_IO). All throws carry {code,remedy}.
|
|
11
|
+
* - handleSaveDocument NEVER throws: it wraps this core and maps every throw
|
|
12
|
+
* to the {ok:false,code,remedy} return contract. Tool transport MUST go
|
|
13
|
+
* through handleSaveDocument (single source of truth).
|
|
14
|
+
* Never writes corruption: OOXML validation gates the write, and the save
|
|
15
|
+
* target is jailed (M3) before any mkdir/write.
|
|
16
|
+
*/
|
|
17
|
+
export declare function executeSaveDocument(store: McpSessionStore, input: unknown): Promise<{
|
|
18
|
+
ok: true;
|
|
19
|
+
sessionId: string;
|
|
20
|
+
path: string;
|
|
21
|
+
revision: number;
|
|
22
|
+
commitOid: string;
|
|
23
|
+
commitMessage: string;
|
|
24
|
+
/** Result of the validator gate: clean, or tolerated with the number of errors the file already had. */
|
|
25
|
+
validation: {
|
|
26
|
+
ok: true;
|
|
27
|
+
} | {
|
|
28
|
+
ok: false;
|
|
29
|
+
tolerated: true;
|
|
30
|
+
preExistingErrors: number;
|
|
31
|
+
introducedErrors: 0;
|
|
32
|
+
messages: string[];
|
|
33
|
+
};
|
|
34
|
+
/** R-1: pending tracked revisions (w:ins + w:del) in the saved package. */
|
|
35
|
+
revisionsPending: number;
|
|
36
|
+
/** R-1: accept remedy, present only when revisionsPending > 0. */
|
|
37
|
+
revisionsRemedy?: string;
|
|
38
|
+
/** Advisory old→new value summaries (saved baseline -> live just saved; bounded, see CHANGED_VALUES_MAX). */
|
|
39
|
+
changedValues: ChangedValue[];
|
|
40
|
+
/** True when the count or per-string cap truncated changedValues. */
|
|
41
|
+
changedValuesTruncated: boolean;
|
|
42
|
+
/** Present when no baseline was computable (new target / unreadable bytes). */
|
|
43
|
+
changedValuesReason?: string;
|
|
44
|
+
/** Normalizer rewrites applied by this save (display-only core log). */
|
|
45
|
+
normalized: string[];
|
|
46
|
+
/**
|
|
47
|
+
* Advisory style findings under the session guide (never blocking).
|
|
48
|
+
* Absent when no guide is attached (guide-less saves stay byte-identical).
|
|
49
|
+
*/
|
|
50
|
+
styleWarnings?: StyleWarning[];
|
|
51
|
+
}>;
|
|
52
|
+
/**
|
|
53
|
+
* M2: return-contract wrapper — NEVER throws.
|
|
54
|
+
* Maps every executeSaveDocument throw to {ok:false,code,remedy} so tool
|
|
55
|
+
* transport sees a single consistent shape. Tested: invalid input, sandbox
|
|
56
|
+
* escape, unknown session, and validation failure all return (never throw).
|
|
57
|
+
*/
|
|
58
|
+
export declare function handleSaveDocument(store: McpSessionStore, input: unknown): Promise<{
|
|
59
|
+
ok: true;
|
|
60
|
+
sessionId: string;
|
|
61
|
+
path: string;
|
|
62
|
+
revision: number;
|
|
63
|
+
commitOid: string;
|
|
64
|
+
commitMessage: string;
|
|
65
|
+
/** Result of the validator gate: clean, or tolerated with the number of errors the file already had. */
|
|
66
|
+
validation: {
|
|
67
|
+
ok: true;
|
|
68
|
+
} | {
|
|
69
|
+
ok: false;
|
|
70
|
+
tolerated: true;
|
|
71
|
+
preExistingErrors: number;
|
|
72
|
+
introducedErrors: 0;
|
|
73
|
+
messages: string[];
|
|
74
|
+
};
|
|
75
|
+
/** R-1: pending tracked revisions (w:ins + w:del) in the saved package. */
|
|
76
|
+
revisionsPending: number;
|
|
77
|
+
/** R-1: accept remedy, present only when revisionsPending > 0. */
|
|
78
|
+
revisionsRemedy?: string;
|
|
79
|
+
/** Advisory old→new value summaries (saved baseline -> live just saved; bounded). */
|
|
80
|
+
changedValues: ChangedValue[];
|
|
81
|
+
/** True when the count or per-string cap truncated changedValues. */
|
|
82
|
+
changedValuesTruncated: boolean;
|
|
83
|
+
/** Present when no baseline was computable. */
|
|
84
|
+
changedValuesReason?: string;
|
|
85
|
+
/** Normalizer rewrites applied by this save (display-only core log). */
|
|
86
|
+
normalized: string[];
|
|
87
|
+
/** Advisory style findings under the session guide (absent without a guide). */
|
|
88
|
+
styleWarnings?: StyleWarning[];
|
|
89
|
+
} | McpErrorShape>;
|
|
90
|
+
export declare function handleCloseDocument(store: McpSessionStore, input: unknown): Promise<{
|
|
91
|
+
ok: true;
|
|
92
|
+
sessionId: string;
|
|
93
|
+
dirty: boolean;
|
|
94
|
+
discardedRevisions: number;
|
|
95
|
+
warning?: string;
|
|
96
|
+
} | McpErrorShape>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type McpSessionStore } from '../../session-store';
|
|
2
|
+
import type { McpErrorShape } from '../errors';
|
|
3
|
+
import type { BatchOpCreatedIds } from '../diff';
|
|
4
|
+
/**
|
|
5
|
+
* Phase C-3 bounds: regex patterns longer than this are rejected
|
|
6
|
+
* fail-closed (the base query cap is 500; regex gets a tighter bound).
|
|
7
|
+
*/
|
|
8
|
+
export declare const SEARCH_REGEX_MAX_PATTERN = 200;
|
|
9
|
+
/** Phase C-3: wall-clock budget for one regex evaluation pass over the AST. */
|
|
10
|
+
export declare const SEARCH_REGEX_TIME_BUDGET_MS = 500;
|
|
11
|
+
/** Generic remedy for regex search failures (no pattern echo, no hit hint). */
|
|
12
|
+
export declare const SEARCH_REGEX_GENERIC_REMEDY = "Fix the regular-expression syntax and retry, or omit regex:true for a literal substring search.";
|
|
13
|
+
export declare function handleSearchContent(store: McpSessionStore, input: unknown): Promise<{
|
|
14
|
+
ok: true;
|
|
15
|
+
sessionId: string;
|
|
16
|
+
matches: Array<{
|
|
17
|
+
id: string;
|
|
18
|
+
preview: string;
|
|
19
|
+
cells?: string[];
|
|
20
|
+
}>;
|
|
21
|
+
results: Array<{
|
|
22
|
+
id: string;
|
|
23
|
+
preview: string;
|
|
24
|
+
cells?: string[];
|
|
25
|
+
}>;
|
|
26
|
+
hint?: string;
|
|
27
|
+
} | McpErrorShape>;
|
|
28
|
+
export declare function handleExecuteBatch(store: McpSessionStore, input: unknown): Promise<{
|
|
29
|
+
ok: true;
|
|
30
|
+
sessionId: string;
|
|
31
|
+
appliedCount: number;
|
|
32
|
+
revision: number;
|
|
33
|
+
skippedIds: string[];
|
|
34
|
+
/** Advisory table warnings (additive, never a failure). */
|
|
35
|
+
warnings: string[];
|
|
36
|
+
/** New node ids created by this batch, in post-batch document order. */
|
|
37
|
+
createdNodeIds: string[];
|
|
38
|
+
/** Per-op attribution (client `id` claims are exact; remainder best-effort). */
|
|
39
|
+
results: BatchOpCreatedIds[];
|
|
40
|
+
/** R-1: pending tracked revisions (w:ins + w:del) remaining after the batch. */
|
|
41
|
+
revisionsPending: number;
|
|
42
|
+
/** R-1: accept remedy, present only when revisionsPending > 0. */
|
|
43
|
+
revisionsRemedy?: string;
|
|
44
|
+
/** R-14: advisory chart stale body refs (same shape [{nodeId, preview}]). Additive, never a failure. */
|
|
45
|
+
possiblyStaleBodyRefs: {
|
|
46
|
+
nodeId: string;
|
|
47
|
+
preview: string;
|
|
48
|
+
}[];
|
|
49
|
+
/** Normalizer rewrites reported for this batch (display-only core log). */
|
|
50
|
+
normalized: string[];
|
|
51
|
+
/** True only when this batch dropped a non-empty redo stack (absent otherwise). */
|
|
52
|
+
redoCleared?: boolean;
|
|
53
|
+
/** Names the dropped redo depth (present only when redoCleared). */
|
|
54
|
+
redoClearedWarning?: string;
|
|
55
|
+
} | McpErrorShape>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type NormalizedRewrite = string;
|
|
2
|
+
/** Display-only read of an engine result's `normalized` report ([] when absent). */
|
|
3
|
+
export declare function readEngineNormalized(res: unknown): NormalizedRewrite[];
|
|
4
|
+
/** Display-only read of the core's own normalizer log ([] when absent). */
|
|
5
|
+
export declare function readParserNormalizations(parser: unknown): NormalizedRewrite[];
|
|
6
|
+
/**
|
|
7
|
+
* Merge core logs across the rezips one save performs (gate rezip + save
|
|
8
|
+
* rezip), dropping exact duplicates. The gate's internal rezip already heals
|
|
9
|
+
* and logs, so reading only the final rezip would report a dishonest zero.
|
|
10
|
+
*/
|
|
11
|
+
export declare function mergeNormalized(...lists: string[][]): string[];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { handleOpenDocument, handleInspectDocument } from './handlers/open-inspect';
|
|
2
|
+
import { handleSearchContent, handleExecuteBatch } from './handlers/search-batch';
|
|
3
|
+
import { handleSaveDocument, handleCloseDocument } from './handlers/save-close';
|
|
4
|
+
/** Lean-6 dispatch table (handlers above; research intentionally absent). */
|
|
5
|
+
export declare const LEAN6_HANDLERS: {
|
|
6
|
+
readonly open_document: typeof handleOpenDocument;
|
|
7
|
+
readonly inspect_document: typeof handleInspectDocument;
|
|
8
|
+
readonly search_content: typeof handleSearchContent;
|
|
9
|
+
readonly execute_batch: typeof handleExecuteBatch;
|
|
10
|
+
readonly save_document: typeof handleSaveDocument;
|
|
11
|
+
readonly close_document: typeof handleCloseDocument;
|
|
12
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const SCHEMA_STAMP_KEY = "x-generated-from";
|
|
2
|
+
export declare function getServerVersion(): string;
|
|
3
|
+
export interface ToolDefinition {
|
|
4
|
+
name: string;
|
|
5
|
+
description: string;
|
|
6
|
+
schema: unknown;
|
|
7
|
+
}
|
|
8
|
+
export declare function getToolDefinitions(): ToolDefinition[];
|
|
9
|
+
export declare function buildStamp(version: string): string;
|
|
10
|
+
export declare function generateSchemasToDir(targetDir: string, version?: string): {
|
|
11
|
+
written: string[];
|
|
12
|
+
count: number;
|
|
13
|
+
};
|
|
14
|
+
export interface SchemaMismatch {
|
|
15
|
+
file: string;
|
|
16
|
+
stamped: string;
|
|
17
|
+
expected: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function checkSchemasInDir(dir: string, expectedVersion?: string): {
|
|
20
|
+
ok: boolean;
|
|
21
|
+
mismatches: SchemaMismatch[];
|
|
22
|
+
checked: number;
|
|
23
|
+
};
|
|
24
|
+
export declare function formatMismatchWarning(mismatches: SchemaMismatch[]): string;
|