@attentionform/astra-mcp-server 0.4.2 → 0.5.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.
@@ -1,3 +1,5 @@
1
+ import { handleExportOriginalDocument, handleRestoreOriginalDocument } from './original';
2
+ import { type OriginalInfo } from '@attentionform/astra-engine';
1
3
  import type { McpSessionStore } from '../../session-store';
2
4
  import type { McpErrorShape } from '../errors';
3
5
  import type { ChangedValue, DiscardedUnsavedSummary } from '../diff';
@@ -24,6 +26,7 @@ export declare function handleGetDocumentHistory(store: McpSessionStore, input:
24
26
  history: HistoryEntry[];
25
27
  /** R-6 sidecar-removal warning (string when a regenerated chain replaced recorded history, else null). Additive, never a failure. */
26
28
  warning: string | null;
29
+ original: OriginalInfo;
27
30
  } | McpErrorShape>;
28
31
  export declare function handleRevertDocument(store: McpSessionStore, input: unknown): Promise<{
29
32
  ok: true;
@@ -94,6 +97,8 @@ export declare function handlePreviewRevert(store: McpSessionStore, input: unkno
94
97
  } | McpErrorShape>;
95
98
  /** Git-history dispatch table (registered alongside lean-6 in index.ts). */
96
99
  export declare const GIT_HISTORY_HANDLERS: {
100
+ readonly export_original_document: typeof handleExportOriginalDocument;
101
+ readonly restore_original_document: typeof handleRestoreOriginalDocument;
97
102
  readonly get_document_history: typeof handleGetDocumentHistory;
98
103
  readonly preview_revert: typeof handlePreviewRevert;
99
104
  readonly revert_document: typeof handleRevertDocument;
@@ -17,6 +17,8 @@ export declare function handleOpenDocument(store: McpSessionStore, input: unknow
17
17
  evicted: string[];
18
18
  pendingNormalizations: string[];
19
19
  validation: OpenValidationField;
20
+ original?: import('@attentionform/astra-engine').OriginalInfo;
21
+ originalWarning?: string;
20
22
  } | McpErrorShape>;
21
23
  /**
22
24
  * Phase C-2: docs rendering under ~2000 tokens return the full TOON
@@ -0,0 +1,25 @@
1
+ import type { McpSessionStore } from '../../session-store';
2
+ /** Read-only export with respect to the live session. Overwriting its own path is deliberately refused. */
3
+ export declare function handleExportOriginalDocument(store: McpSessionStore, input: unknown): Promise<import("../errors").McpErrorShape | {
4
+ ok: true;
5
+ sessionId: string;
6
+ path: string;
7
+ original: import("@attentionform/astra-engine").OriginalInfo;
8
+ }>;
9
+ /** Exact-byte restore. Candidate session is staged separately; normal serialization never overwrites the result. */
10
+ export declare function handleRestoreOriginalDocument(store: McpSessionStore, input: unknown): Promise<import("../errors").McpErrorShape | {
11
+ warning?: string | undefined;
12
+ durabilityUnconfirmed?: boolean | undefined;
13
+ ok: true;
14
+ sessionId: string;
15
+ path: string;
16
+ revision: number;
17
+ dirty: false;
18
+ commitOid: string;
19
+ original: {
20
+ available: true;
21
+ sha256: string;
22
+ bytes: number;
23
+ capturedAt: string;
24
+ };
25
+ }>;
@@ -971,3 +971,13 @@ export type GetStatsInput = z.infer<typeof GetStatsSchema>;
971
971
  export type SanitizeDocumentInput = z.infer<typeof SanitizeDocumentSchema>;
972
972
  export type NormalizeDocumentInput = z.infer<typeof NormalizeDocumentSchema>;
973
973
  export type ImportDocumentInput = z.infer<typeof ImportDocumentSchema>;
974
+ /** Exact retained-input recovery. These paths never serialize the exported original. */
975
+ export declare const ExportOriginalDocumentSchema: z.ZodObject<{
976
+ sessionId: z.ZodString;
977
+ outPath: z.ZodString;
978
+ overwrite: z.ZodOptional<z.ZodBoolean>;
979
+ }, z.core.$strict>;
980
+ export declare const RestoreOriginalDocumentSchema: z.ZodObject<{
981
+ sessionId: z.ZodString;
982
+ discard: z.ZodOptional<z.ZodBoolean>;
983
+ }, z.core.$strict>;
@@ -6,7 +6,7 @@ export declare const LEAN6_TOOL_NAMES: readonly ["open_document", "inspect_docum
6
6
  export type Lean6ToolName = (typeof LEAN6_TOOL_NAMES)[number];
7
7
  export declare function getLean6ToolNames(): Lean6ToolName[];
8
8
  /** Git-history tool names (history browsing + preview + revert + redo; registered alongside lean-6). */
9
- export declare const GIT_HISTORY_TOOL_NAMES: readonly ["get_document_history", "preview_revert", "revert_document", "redo_document"];
9
+ export declare const GIT_HISTORY_TOOL_NAMES: readonly ["get_document_history", "export_original_document", "restore_original_document", "preview_revert", "revert_document", "redo_document"];
10
10
  export type GitHistoryToolName = (typeof GIT_HISTORY_TOOL_NAMES)[number];
11
11
  export declare function getGitHistoryToolNames(): GitHistoryToolName[];
12
12
  /** Document-audit tool names (read-only preflight + census + scrub + canonical repair + file ingest). */
@@ -10,3 +10,4 @@ export * from './mcp/handlers/save-close';
10
10
  export * from './mcp/handlers/history';
11
11
  export * from './mcp/handlers/export-audit';
12
12
  export * from './mcp/registry';
13
+ export * from './mcp/handlers/original';
@@ -1,4 +1,4 @@
1
- import { type DocumentAST, type DocxParserMacroOptions, DocxParser, OperationEngine, ToonGenerator, canonicalizeForAsset as canonicalizeForMcp, type StyleGuideConfig, type ValidationBaseline } from '@attentionform/astra-engine';
1
+ import { type DocumentAST, type DocxParserMacroOptions, DocxParser, OperationEngine, ToonGenerator, canonicalizeForAsset as canonicalizeForMcp, type OriginalInfo, type StyleGuideConfig, type ValidationBaseline } from '@attentionform/astra-engine';
2
2
  /**
3
3
  * Sprint-2 Muse session store (MCP Lean-6 backing).
4
4
  *
@@ -146,6 +146,22 @@ export interface DocHandle {
146
146
  openBaseline?: ValidationBaseline | null;
147
147
  /** sha256 of the file bytes read at open, to tell whether the file on disk is still the opened one. */
148
148
  openSha256?: string;
149
+ /** Fingerprint of the last bytes read or successfully written by ASTra. */
150
+ lastWrittenSha256?: string;
151
+ /** Status of the retained original as this session last learned it. Read it through `resolveSessionOriginal`. */
152
+ originalInfo?: OriginalInfo;
153
+ /**
154
+ * What this session pinned about the retained original, so a later check cannot hand it another history's
155
+ * original: `retained` is the SHA-256 of the verified retained original read at open; `input` is the SHA-256 of
156
+ * the file this session opened, for a session that opened while history initialization was still running.
157
+ * No pin: this session has no claim on any original.
158
+ */
159
+ originalPin?: {
160
+ kind: 'retained' | 'input';
161
+ sha256: string;
162
+ };
163
+ originalWarning?: string;
164
+ macroPolicy?: DocxParserMacroOptions;
149
165
  }
150
166
  /**
151
167
  * Per-commit audit metadata recorded alongside each history commit.
@@ -290,6 +306,9 @@ export declare function validateOpenBufferLabel(rawLabel: unknown): string;
290
306
  * Collects the versioned package extras (media/rels/styles/headers) for git.
291
307
  * document.xml is committed separately; everything matching
292
308
  * isTrackedPackageFile is snapshotted alongside it.
309
+ *
310
+ * Throws when the package snapshot cannot be collected. An empty record would be committed as a complete
311
+ * snapshot with no package parts, and a later revert would then remove the real parts as if that were intended.
293
312
  */
294
313
  export declare function collectTrackedExtrasForGit(parser: DocxParser): Record<string, Buffer>;
295
314
  /**
@@ -299,7 +318,18 @@ export declare function collectTrackedExtrasForGit(parser: DocxParser): Record<s
299
318
  * Best-effort at open (callers swallow failures so open semantics never
300
319
  * change); hard requirement before commitChange at save/revert/redo.
301
320
  */
302
- export declare function ensureGitRepo(docPath: string, xml: string, extras: Record<string, Buffer>): Promise<boolean>;
321
+ export declare function ensureGitRepo(docPath: string, xml: string, extras: Record<string, Buffer>, originalBytes?: Buffer): Promise<boolean>;
322
+ /**
323
+ * The retained original's status for this session, checked now. A session pins one hash when it opens (see
324
+ * `DocHandle.originalPin`); the working document's own bytes are never compared with the original, because an
325
+ * edited document legitimately differs from it.
326
+ * - `retained` pin: the stored original must still verify and still have the pinned SHA-256.
327
+ * - `input` pin (the session opened while another process was initializing the history): the session becomes
328
+ * eligible only once that initialization is complete and the verified original has the SHA-256 of the file
329
+ * this session opened. Until then it reports `initializing`; a different original never upgrades it.
330
+ * - no pin: the status recorded at open stands.
331
+ */
332
+ export declare function resolveSessionOriginal(handle: DocHandle): Promise<OriginalInfo>;
303
333
  /** Outcome of McpSessionStore.closeDocument (dirty state read under the delete lock). */
304
334
  export interface CloseDocumentOutcome {
305
335
  closed: boolean;
@@ -389,7 +419,7 @@ export declare class McpSessionStore {
389
419
  * Macro/active content refuses by default (E_VALIDATION naming the parts);
390
420
  * pass {allowMacros:true} to preserve or {stripMacros:true} to strip.
391
421
  */
392
- openDocument(filePath: string, sessionId?: string, macroOpts?: DocxParserMacroOptions): Promise<DocHandle>;
422
+ openDocument(filePath: string, sessionId?: string, macroOpts?: DocxParserMacroOptions, captureInput?: boolean): Promise<DocHandle>;
393
423
  /**
394
424
  * Opens a document from an in-memory buffer (tests / headless flows).
395
425
  * `labelPath` is the display path recorded on the handle. L4: absolute
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@attentionform/astra-mcp-server",
3
3
  "mcpName": "com.attentionform/astra-mcp-server",
4
- "version": "0.4.2",
4
+ "version": "0.5.0",
5
5
  "description": "Official Model Context Protocol (MCP) server for ASTra document IDE",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -42,8 +42,8 @@
42
42
  "adm-zip-gate": "node ../../scripts/check-adm-zip-imports.mjs"
43
43
  },
44
44
  "dependencies": {
45
- "@attentionform/astra-engine": "^0.4.2",
46
- "@attentionform/ooxml-validator": "^0.4.2",
45
+ "@attentionform/astra-engine": "^0.5.0",
46
+ "@attentionform/ooxml-validator": "^0.5.0",
47
47
  "@modelcontextprotocol/sdk": "^1.32.2",
48
48
  "@xmldom/xmldom": "0.8.15",
49
49
  "adm-zip": "0.6.1",