@j0hanz/thinkseq-mcp 1.0.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 (51) hide show
  1. package/README.md +38 -0
  2. package/dist/app.d.ts +43 -0
  3. package/dist/app.d.ts.map +1 -0
  4. package/dist/app.js +111 -0
  5. package/dist/app.js.map +1 -0
  6. package/dist/engine.d.ts +12 -0
  7. package/dist/engine.d.ts.map +1 -0
  8. package/dist/engine.js +165 -0
  9. package/dist/engine.js.map +1 -0
  10. package/dist/index.d.ts +3 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +9 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/lib/diagnostics.d.ts +37 -0
  15. package/dist/lib/diagnostics.d.ts.map +1 -0
  16. package/dist/lib/diagnostics.js +24 -0
  17. package/dist/lib/diagnostics.js.map +1 -0
  18. package/dist/lib/errors.d.ts +18 -0
  19. package/dist/lib/errors.d.ts.map +1 -0
  20. package/dist/lib/errors.js +21 -0
  21. package/dist/lib/errors.js.map +1 -0
  22. package/dist/lib/package.d.ts +15 -0
  23. package/dist/lib/package.d.ts.map +1 -0
  24. package/dist/lib/package.js +41 -0
  25. package/dist/lib/package.js.map +1 -0
  26. package/dist/lib/protocolGuards.d.ts +2 -0
  27. package/dist/lib/protocolGuards.d.ts.map +1 -0
  28. package/dist/lib/protocolGuards.js +80 -0
  29. package/dist/lib/protocolGuards.js.map +1 -0
  30. package/dist/lib/stdioGuards.d.ts +3 -0
  31. package/dist/lib/stdioGuards.d.ts.map +1 -0
  32. package/dist/lib/stdioGuards.js +57 -0
  33. package/dist/lib/stdioGuards.js.map +1 -0
  34. package/dist/lib/types.d.ts +44 -0
  35. package/dist/lib/types.d.ts.map +1 -0
  36. package/dist/lib/types.js +2 -0
  37. package/dist/lib/types.js.map +1 -0
  38. package/dist/schemas/inputs.d.ts +19 -0
  39. package/dist/schemas/inputs.d.ts.map +1 -0
  40. package/dist/schemas/inputs.js +41 -0
  41. package/dist/schemas/inputs.js.map +1 -0
  42. package/dist/schemas/outputs.d.ts +33 -0
  43. package/dist/schemas/outputs.d.ts.map +1 -0
  44. package/dist/schemas/outputs.js +42 -0
  45. package/dist/schemas/outputs.js.map +1 -0
  46. package/dist/tools/thinkseq.d.ts +7 -0
  47. package/dist/tools/thinkseq.d.ts.map +1 -0
  48. package/dist/tools/thinkseq.js +84 -0
  49. package/dist/tools/thinkseq.js.map +1 -0
  50. package/dist/tsconfig.tsbuildinfo +1 -0
  51. package/package.json +69 -0
package/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # ThinkSeq MCP Server
2
+
3
+ <img src="docs/logo.png" alt="Filesystem Context MCP Server Logo" width="175">
4
+
5
+ An MCP implementation for advanced reasoning and thinking sequences.
6
+
7
+ ## Features
8
+
9
+ - **Smart Context**: Returns optimized context to the LLM (last 5 thoughts + branch info).
10
+ - **Structured Output**: Full Zod schema validation.
11
+ - **Zero Dependencies**: Only uses standard MCP SDK.
12
+ - **Branching & Revision**: Full support for non-linear thinking.
13
+
14
+ ## Usage
15
+
16
+ This server provides one tool: `thinkseq`.
17
+
18
+ ### Input Parameters
19
+
20
+ - `thought`: The thinking step content.
21
+ - `thoughtNumber`: Current step (1-indexed).
22
+ - `totalThoughts`: Estimated total steps.
23
+ - `nextThoughtNeeded`: Boolean.
24
+ - `thoughtType`: (Optional) "analysis", "hypothesis", "verification", etc.
25
+
26
+ ## Development
27
+
28
+ ```bash
29
+ npm install
30
+ npm run build
31
+ npm start
32
+ ```
33
+
34
+ ## Testing
35
+
36
+ ```bash
37
+ npm test
38
+ ```
package/dist/app.d.ts ADDED
@@ -0,0 +1,43 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
3
+ import { ThinkingEngine } from './engine.js';
4
+ import type { LifecycleEvent } from './lib/diagnostics.js';
5
+ import type { PackageInfo } from './lib/package.js';
6
+ interface Closeable extends Record<string, unknown> {
7
+ close?: () => Promise<void> | void;
8
+ }
9
+ interface ProcessLike {
10
+ on: (event: string, listener: (...args: unknown[]) => void) => void;
11
+ exit: (code: number) => void;
12
+ }
13
+ type ServerLike = Pick<McpServer, 'connect' | 'registerTool'>;
14
+ type TransportLike = Pick<StdioServerTransport, 'close'>;
15
+ type EngineLike = Pick<ThinkingEngine, 'processThought'>;
16
+ export interface ProcessErrorHandlerDeps {
17
+ processLike?: ProcessLike;
18
+ logError?: (message: string) => void;
19
+ exit?: (code: number) => void;
20
+ }
21
+ interface ShutdownDependencies {
22
+ processLike?: ProcessLike;
23
+ server: Closeable;
24
+ transport: Closeable;
25
+ publishLifecycleEvent?: (event: LifecycleEvent) => void;
26
+ now?: () => number;
27
+ }
28
+ export interface RunDependencies {
29
+ processLike?: ProcessLike;
30
+ packageReadTimeoutMs?: number;
31
+ readPackageJson?: (signal?: AbortSignal) => Promise<PackageInfo>;
32
+ publishLifecycleEvent?: (event: LifecycleEvent) => void;
33
+ createServer?: (name: string, version: string) => ServerLike;
34
+ connectServer?: (server: ServerLike) => Promise<TransportLike>;
35
+ registerTool?: (server: ServerLike, engine: EngineLike) => void;
36
+ engineFactory?: () => EngineLike;
37
+ installShutdownHandlers?: (deps: ShutdownDependencies) => void;
38
+ now?: () => number;
39
+ }
40
+ export declare function installProcessErrorHandlers(deps?: ProcessErrorHandlerDeps): void;
41
+ export declare function run(deps?: RunDependencies): Promise<void>;
42
+ export {};
43
+ //# sourceMappingURL=app.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAEjF,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CA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AAO,CAAC,WAAW,CAAC,CAAC;IACjE,qBAAqB,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;IACxD,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,UAAU,CAAC;IAC7D,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;IAC/D,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;IAChE,aAAa,CAAC,EAAE,MAAM,UAAU,CAAC;IACjC,uBAAuB,CAAC,EAAE,CAAC,IAAI,EAAE,oBAAoB,KAAK,IAAI,CAAC;IAC/D,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAID,wBAAgB,2BAA2B,CACzC,IAAI,GAAE,uBAA4B,GACjC,IAAI,CAkBN;AA8ED,wBAAsB,GAAG,CAAC,IAAI,GAAE,eAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CA8BnE"}
package/dist/app.js ADDED
@@ -0,0 +1,111 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
3
+ import { ThinkingEngine } from './engine.js';
4
+ import { publishLifecycleEvent } from './lib/diagnostics.js';
5
+ import { readSelfPackageJson } from './lib/package.js';
6
+ import { installInitializationGuards } from './lib/protocolGuards.js';
7
+ import { installStdioInvalidMessageGuards, installStdioParseErrorResponder, } from './lib/stdioGuards.js';
8
+ import { registerThinkSeq } from './tools/thinkseq.js';
9
+ const SERVER_INSTRUCTIONS = 'ThinkSeq is a tool for structured, sequential thinking with branching and revision support.';
10
+ const DEFAULT_PACKAGE_READ_TIMEOUT_MS = 2000;
11
+ export function installProcessErrorHandlers(deps = {}) {
12
+ const proc = deps.processLike ?? process;
13
+ const logError = deps.logError ?? console.error;
14
+ const exit = deps.exit ??
15
+ ((code) => {
16
+ proc.exit(code);
17
+ });
18
+ const handlerFor = (label) => (value) => {
19
+ const error = value instanceof Error ? value : new Error(String(value));
20
+ logError(`thinkseq: ${label}: ${error.message}`);
21
+ exit(1);
22
+ };
23
+ proc.on('unhandledRejection', handlerFor('unhandledRejection'));
24
+ proc.on('uncaughtException', handlerFor('uncaughtException'));
25
+ }
26
+ function createServer(name, version) {
27
+ return new McpServer({ name, version }, {
28
+ instructions: SERVER_INSTRUCTIONS,
29
+ capabilities: { logging: {} },
30
+ });
31
+ }
32
+ async function connectServer(server) {
33
+ const transport = new StdioServerTransport();
34
+ await server.connect(transport);
35
+ installStdioInvalidMessageGuards(transport);
36
+ installStdioParseErrorResponder(transport);
37
+ return transport;
38
+ }
39
+ const DEFAULT_RUN_DEPENDENCIES = {
40
+ processLike: process,
41
+ packageReadTimeoutMs: DEFAULT_PACKAGE_READ_TIMEOUT_MS,
42
+ readPackageJson: readSelfPackageJson,
43
+ publishLifecycleEvent,
44
+ createServer,
45
+ connectServer,
46
+ registerTool: registerThinkSeq,
47
+ engineFactory: () => new ThinkingEngine(),
48
+ installShutdownHandlers,
49
+ now: Date.now,
50
+ };
51
+ async function closeSafely(value) {
52
+ try {
53
+ if (typeof value.close === 'function') {
54
+ await value.close();
55
+ }
56
+ }
57
+ catch {
58
+ return;
59
+ }
60
+ }
61
+ function installShutdownHandlers({ processLike, server, transport, publishLifecycleEvent: publishLifecycle, now, }) {
62
+ const proc = processLike ?? process;
63
+ const emit = publishLifecycle ?? publishLifecycleEvent;
64
+ const timestamp = now ?? Date.now;
65
+ let shuttingDown = false;
66
+ const shutdown = async (signal) => {
67
+ if (shuttingDown)
68
+ return;
69
+ shuttingDown = true;
70
+ emit({
71
+ type: 'lifecycle.shutdown',
72
+ ts: timestamp(),
73
+ signal,
74
+ });
75
+ await closeSafely(server);
76
+ await closeSafely(transport);
77
+ proc.exit(0);
78
+ };
79
+ proc.on('SIGTERM', () => {
80
+ void shutdown('SIGTERM');
81
+ });
82
+ proc.on('SIGINT', () => {
83
+ void shutdown('SIGINT');
84
+ });
85
+ }
86
+ export async function run(deps = {}) {
87
+ const resolved = {
88
+ ...DEFAULT_RUN_DEPENDENCIES,
89
+ ...deps,
90
+ };
91
+ const pkg = await resolved.readPackageJson(AbortSignal.timeout(resolved.packageReadTimeoutMs));
92
+ const name = pkg.name ?? 'thinkseq';
93
+ const version = pkg.version ?? '0.0.0';
94
+ resolved.publishLifecycleEvent({
95
+ type: 'lifecycle.started',
96
+ ts: resolved.now(),
97
+ });
98
+ const server = resolved.createServer(name, version);
99
+ const engine = resolved.engineFactory();
100
+ resolved.registerTool(server, engine);
101
+ installInitializationGuards(server);
102
+ const transport = await resolved.connectServer(server);
103
+ resolved.installShutdownHandlers({
104
+ processLike: resolved.processLike,
105
+ server,
106
+ transport,
107
+ publishLifecycleEvent: resolved.publishLifecycleEvent,
108
+ now: resolved.now,
109
+ });
110
+ }
111
+ //# sourceMappingURL=app.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAEjF,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAG7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EACL,gCAAgC,EAChC,+BAA+B,GAChC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,MAAM,mBAAmB,GACvB,6FAA6F,CAAC;AAEhG,MAAM,+BAA+B,GAAG,IAAI,CAAC;AA4C7C,MAAM,UAA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D,GAAG,EAAE,QAAQ,CAAC,GAAG;KAClB,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { ProcessResult, ThoughtData } from './lib/types.js';
2
+ export interface ThinkingEngineOptions {
3
+ maxThoughts?: number;
4
+ maxMemoryBytes?: number;
5
+ estimatedThoughtOverheadBytes?: number;
6
+ }
7
+ export declare class ThinkingEngine {
8
+ #private;
9
+ constructor(options?: ThinkingEngineOptions);
10
+ processThought(input: ThoughtData): ProcessResult;
11
+ }
12
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,aAAa,EAEb,WAAW,EACZ,MAAM,gBAAgB,CAAC;AAOxB,MAAM,WAAW,qBAAqB;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,6BAA6B,CAAC,EAAE,MAAM,CAAC;CACxC;AAWD,qBAAa,cAAc;;gBAWb,OAAO,GAAE,qBAA0B;IAkB/C,cAAc,CAAC,KAAK,EAAE,WAAW,GAAG,aAAa;CAqJlD"}
package/dist/engine.js ADDED
@@ -0,0 +1,165 @@
1
+ import { publishEngineEvent } from './lib/diagnostics.js';
2
+ const DEFAULT_MAX_THOUGHTS = 500;
3
+ const MAX_THOUGHTS_CAP = 10000;
4
+ const MAX_MEMORY_BYTES = 100 * 1024 * 1024;
5
+ const ESTIMATED_THOUGHT_OVERHEAD_BYTES = 200;
6
+ function normalizeInt(value, fallback, options) {
7
+ if (typeof value !== 'number' || !Number.isFinite(value))
8
+ return fallback;
9
+ return Math.max(options.min, Math.min(options.max, Math.trunc(value)));
10
+ }
11
+ export class ThinkingEngine {
12
+ #thoughts = [];
13
+ #branches = new Map();
14
+ #branchIdsCache = [];
15
+ #branchIdsDirty = true;
16
+ #estimatedBytes = 0;
17
+ #revisionCount = 0;
18
+ #maxThoughts;
19
+ #maxMemoryBytes;
20
+ #estimatedThoughtOverheadBytes;
21
+ constructor(options = {}) {
22
+ this.#maxThoughts = normalizeInt(options.maxThoughts, DEFAULT_MAX_THOUGHTS, { min: 1, max: MAX_THOUGHTS_CAP });
23
+ this.#maxMemoryBytes = normalizeInt(options.maxMemoryBytes, MAX_MEMORY_BYTES, { min: 1, max: Number.MAX_SAFE_INTEGER });
24
+ this.#estimatedThoughtOverheadBytes = normalizeInt(options.estimatedThoughtOverheadBytes, ESTIMATED_THOUGHT_OVERHEAD_BYTES, { min: 1, max: Number.MAX_SAFE_INTEGER });
25
+ }
26
+ processThought(input) {
27
+ this.#validateThoughtNumber(input);
28
+ const totalThoughts = Math.max(input.totalThoughts, input.thoughtNumber);
29
+ const stored = {
30
+ ...input,
31
+ totalThoughts,
32
+ timestamp: Date.now(),
33
+ };
34
+ this.#thoughts.push(stored);
35
+ this.#estimatedBytes += this.#estimateThoughtBytes(stored);
36
+ if (stored.isRevision)
37
+ this.#revisionCount += 1;
38
+ if (stored.branchId) {
39
+ const branch = this.#branches.get(stored.branchId);
40
+ if (branch)
41
+ branch.push(stored);
42
+ else {
43
+ this.#branches.set(stored.branchId, [stored]);
44
+ this.#branchIdsDirty = true;
45
+ }
46
+ }
47
+ this.#pruneHistoryIfNeeded();
48
+ const context = this.#buildContextSummary();
49
+ return {
50
+ ok: true,
51
+ result: {
52
+ thoughtNumber: stored.thoughtNumber,
53
+ totalThoughts: stored.totalThoughts,
54
+ nextThoughtNeeded: input.nextThoughtNeeded,
55
+ thoughtHistoryLength: this.#thoughts.length,
56
+ branches: this.#getBranchIds(),
57
+ context,
58
+ },
59
+ };
60
+ }
61
+ #getBranchIds() {
62
+ if (this.#branchIdsDirty) {
63
+ this.#branchIdsCache = Array.from(this.#branches.keys());
64
+ this.#branchIdsDirty = false;
65
+ }
66
+ return this.#branchIdsCache;
67
+ }
68
+ #buildContextSummary() {
69
+ const recent = this.#thoughts.slice(-5);
70
+ const currentBranch = this.#thoughts.at(-1)?.branchId;
71
+ return {
72
+ recentThoughts: recent.map((t) => {
73
+ const base = {
74
+ number: t.thoughtNumber,
75
+ preview: t.thought.slice(0, 100) + (t.thought.length > 100 ? '...' : ''),
76
+ };
77
+ return t.thoughtType ? { ...base, type: t.thoughtType } : base;
78
+ }),
79
+ ...(currentBranch !== undefined ? { currentBranch } : {}),
80
+ hasRevisions: this.#revisionCount > 0,
81
+ };
82
+ }
83
+ #validateThoughtNumber(input) {
84
+ const lastThought = this.#thoughts.at(-1);
85
+ if (!lastThought) {
86
+ this.#ensureFirstThought(input.thoughtNumber);
87
+ return;
88
+ }
89
+ if (this.#isRevisionOrBranch(input))
90
+ return;
91
+ this.#warnOnSequenceGap(lastThought, input.thoughtNumber);
92
+ }
93
+ #ensureFirstThought(thoughtNumber) {
94
+ if (thoughtNumber === 1)
95
+ return;
96
+ throw new Error(`First thought must be number 1, got ${String(thoughtNumber)}`);
97
+ }
98
+ #isRevisionOrBranch(input) {
99
+ return input.isRevision === true || input.branchFromThought !== undefined;
100
+ }
101
+ #warnOnSequenceGap(lastThought, thoughtNumber) {
102
+ if (thoughtNumber === lastThought.thoughtNumber + 1)
103
+ return;
104
+ publishEngineEvent({
105
+ type: 'engine.sequence_gap',
106
+ ts: Date.now(),
107
+ expected: lastThought.thoughtNumber + 1,
108
+ received: thoughtNumber,
109
+ });
110
+ }
111
+ #pruneHistoryIfNeeded() {
112
+ const excess = this.#thoughts.length - this.#maxThoughts;
113
+ if (excess > 0) {
114
+ const batch = Math.max(excess, Math.ceil(this.#maxThoughts * 0.1));
115
+ this.#removeOldest(batch);
116
+ }
117
+ if (this.#estimatedBytes > this.#maxMemoryBytes &&
118
+ this.#thoughts.length > 10) {
119
+ const toRemove = Math.ceil(this.#thoughts.length * 0.2);
120
+ this.#removeOldest(toRemove);
121
+ }
122
+ }
123
+ #estimateThoughtBytes(thought) {
124
+ return thought.thought.length * 2 + this.#estimatedThoughtOverheadBytes;
125
+ }
126
+ #removeOldest(count) {
127
+ if (count <= 0 || this.#thoughts.length === 0)
128
+ return;
129
+ const actual = Math.min(count, this.#thoughts.length);
130
+ const removed = this.#thoughts.splice(0, actual);
131
+ if (removed.length === 0)
132
+ return;
133
+ this.#applyRemoval(removed);
134
+ }
135
+ #applyRemoval(removed) {
136
+ const branchRemovals = this.#collectBranchRemovals(removed);
137
+ for (const [branchId, removeCount] of branchRemovals) {
138
+ this.#trimBranch(branchId, removeCount);
139
+ }
140
+ }
141
+ #collectBranchRemovals(removed) {
142
+ const branchRemovals = new Map();
143
+ for (const thought of removed) {
144
+ this.#estimatedBytes -= this.#estimateThoughtBytes(thought);
145
+ if (thought.isRevision)
146
+ this.#revisionCount -= 1;
147
+ if (!thought.branchId)
148
+ continue;
149
+ branchRemovals.set(thought.branchId, (branchRemovals.get(thought.branchId) ?? 0) + 1);
150
+ }
151
+ return branchRemovals;
152
+ }
153
+ #trimBranch(branchId, removeCount) {
154
+ const branch = this.#branches.get(branchId);
155
+ if (!branch)
156
+ return;
157
+ if (removeCount >= branch.length) {
158
+ this.#branches.delete(branchId);
159
+ this.#branchIdsDirty = true;
160
+ return;
161
+ }
162
+ branch.splice(0, removeCount);
163
+ }
164
+ }
165
+ //# sourceMappingURL=engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAQ1D,MAAM,oBAAoB,GAAG,GAAG,CAAC;AACjC,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAC/B,MAAM,gBAAgB,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;AAC3C,MAAM,gCAAgC,GAAG,GAAG,CAAC;AAQ7C,SAAS,YAAY,CACnB,KAAyB,EACzB,QAAgB,EAChB,OAAqC;IAErC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CA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C,QAAQ,EAChB,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAChD,CAAC;QACJ,CAAC;QACD,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,WAAW,CAAC,QAAgB,EAAE,WAAmB;QAC/C,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC5C,IAAI,CAAC,MAAM;YAAE,OAAO;QACpB,IAAI,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;YACjC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAChC,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;YAC5B,OAAO;QACT,CAAC;QACD,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;IAChC,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ import { installProcessErrorHandlers, run } from './app.js';
3
+ installProcessErrorHandlers();
4
+ run().catch((err) => {
5
+ const message = err instanceof Error ? err.message : String(err);
6
+ console.error(`thinkseq: fatal: ${message}`);
7
+ process.exit(1);
8
+ });
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,2BAA2B,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE5D,2BAA2B,EAAE,CAAC;AAE9B,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;IAC3B,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACjE,OAAO,CAAC,KAAK,CAAC,oBAAoB,OAAO,EAAE,CAAC,CAAC;IAC7C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,37 @@
1
+ export type ToolEvent = {
2
+ type: 'tool.start';
3
+ tool: 'thinkseq';
4
+ ts: number;
5
+ } | {
6
+ type: 'tool.end';
7
+ tool: 'thinkseq';
8
+ ts: number;
9
+ ok: true;
10
+ durationMs?: number;
11
+ } | {
12
+ type: 'tool.end';
13
+ tool: 'thinkseq';
14
+ ts: number;
15
+ ok: false;
16
+ errorCode: string;
17
+ errorMessage: string;
18
+ durationMs?: number;
19
+ };
20
+ export type LifecycleEvent = {
21
+ type: 'lifecycle.started';
22
+ ts: number;
23
+ } | {
24
+ type: 'lifecycle.shutdown';
25
+ ts: number;
26
+ signal: string;
27
+ };
28
+ export interface EngineEvent {
29
+ type: 'engine.sequence_gap';
30
+ ts: number;
31
+ expected: number;
32
+ received: number;
33
+ }
34
+ export declare function publishToolEvent(event: ToolEvent): void;
35
+ export declare function publishLifecycleEvent(event: LifecycleEvent): void;
36
+ export declare function publishEngineEvent(event: EngineEvent): void;
37
+ //# sourceMappingURL=diagnostics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../../src/lib/diagnostics.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,SAAS,GACjB;IACE,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE,UAAU,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;CACZ,GACD;IACE,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,UAAU,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,IAAI,CAAC;IACT,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GACD;IACE,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,UAAU,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,KAAK,CAAC;IACV,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEN,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,mBAAmB,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GACzC;IAAE,IAAI,EAAE,oBAAoB,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/D,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,qBAAqB,CAAC;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAkBD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAEvD;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI,CAEjE;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAE3D"}
@@ -0,0 +1,24 @@
1
+ import diagnostics_channel from 'node:diagnostics_channel';
2
+ const toolChannel = diagnostics_channel.channel('thinkseq:tool');
3
+ const lifecycleChannel = diagnostics_channel.channel('thinkseq:lifecycle');
4
+ const engineChannel = diagnostics_channel.channel('thinkseq:engine');
5
+ function safePublish(channel, message) {
6
+ if (!channel.hasSubscribers)
7
+ return;
8
+ try {
9
+ channel.publish(message);
10
+ }
11
+ catch {
12
+ // Intentional suppression of publication errors
13
+ }
14
+ }
15
+ export function publishToolEvent(event) {
16
+ safePublish(toolChannel, event);
17
+ }
18
+ export function publishLifecycleEvent(event) {
19
+ safePublish(lifecycleChannel, event);
20
+ }
21
+ export function publishEngineEvent(event) {
22
+ safePublish(engineChannel, event);
23
+ }
24
+ //# sourceMappingURL=diagnostics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../../src/lib/diagnostics.ts"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,MAAM,0BAA0B,CAAC;AAoC3D,MAAM,WAAW,GAAG,mBAAmB,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;AACjE,MAAM,gBAAgB,GAAG,mBAAmB,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAC3E,MAAM,aAAa,GAAG,mBAAmB,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAErE,SAAS,WAAW,CAClB,OAAoC,EACpC,OAAgB;IAEhB,IAAI,CAAC,OAAO,CAAC,cAAc;QAAE,OAAO;IACpC,IAAI,CAAC;QACH,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAAC,MAAM,CAAC;QACP,gDAAgD;IAClD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAgB;IAC/C,WAAW,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,KAAqB;IACzD,WAAW,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC;AACvC,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,KAAkB;IACnD,WAAW,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;AACpC,CAAC"}
@@ -0,0 +1,18 @@
1
+ export interface ErrorResponse extends Record<string, unknown> {
2
+ content: {
3
+ type: 'text';
4
+ text: string;
5
+ }[];
6
+ structuredContent: {
7
+ ok: false;
8
+ error: {
9
+ code: string;
10
+ message: string;
11
+ };
12
+ result?: unknown;
13
+ };
14
+ isError: true;
15
+ }
16
+ export declare function getErrorMessage(error: unknown): string;
17
+ export declare function createErrorResponse(code: string, message: string, result?: unknown): ErrorResponse;
18
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAc,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC5D,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC1C,iBAAiB,EAAE;QACjB,EAAE,EAAE,KAAK,CAAC;QACV,KAAK,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAA;SAAE,CAAC;QACzC,MAAM,CAAC,EAAE,OAAO,CAAC;KAClB,CAAC;IACF,OAAO,EAAE,IAAI,CAAC;CACf;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAItD;AAED,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,OAAO,GACf,aAAa,CAYf"}
@@ -0,0 +1,21 @@
1
+ export function getErrorMessage(error) {
2
+ if (error instanceof Error)
3
+ return error.message;
4
+ if (typeof error === 'string' && error.length > 0)
5
+ return error;
6
+ return 'Unknown error';
7
+ }
8
+ export function createErrorResponse(code, message, result) {
9
+ const structured = {
10
+ ok: false,
11
+ error: { code, message },
12
+ ...(result !== undefined && { result }),
13
+ };
14
+ const response = {
15
+ content: [{ type: 'text', text: JSON.stringify(structured) }],
16
+ structuredContent: structured,
17
+ isError: true,
18
+ };
19
+ return response;
20
+ }
21
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AAUA,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,IAAI,KAAK,YAAY,KAAK;QAAE,OAAO,KAAK,CAAC,OAAO,CAAC;IACjD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IAChE,OAAO,eAAe,CAAC;AACzB,CAAC;AAED,MAAM,UAAU,mBAAmB,CACjC,IAAY,EACZ,OAAe,EACf,MAAgB;IAEhB,MAAM,UAAU,GAAuC;QACrD,EAAE,EAAE,KAAK;QACT,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;QACxB,GAAG,CAAC,MAAM,KAAK,SAAS,IAAI,EAAE,MAAM,EAAE,CAAC;KACxC,CAAC;IACF,MAAM,QAAQ,GAAkB;QAC9B,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC;QAC7D,iBAAiB,EAAE,UAAU;QAC7B,OAAO,EAAE,IAAI;KACd,CAAC;IACF,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,15 @@
1
+ export interface PackageInfo {
2
+ name?: string;
3
+ version?: string;
4
+ }
5
+ type ReadFile = (path: string, options: {
6
+ encoding: 'utf8';
7
+ signal?: AbortSignal;
8
+ }) => Promise<string>;
9
+ export interface PackageJsonDependencies {
10
+ readFile?: ReadFile;
11
+ cwd?: () => string;
12
+ }
13
+ export declare function readSelfPackageJson(signal?: AbortSignal, deps?: PackageJsonDependencies): Promise<PackageInfo>;
14
+ export {};
15
+ //# sourceMappingURL=package.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.d.ts","sourceRoot":"","sources":["../../src/lib/package.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,KAAK,QAAQ,GAAG,CACd,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,KAChD,OAAO,CAAC,MAAM,CAAC,CAAC;AAErB,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAiDD,wBAAsB,mBAAmB,CACvC,MAAM,CAAC,EAAE,WAAW,EACpB,IAAI,CAAC,EAAE,uBAAuB,GAC7B,OAAO,CAAC,WAAW,CAAC,CAQtB"}
@@ -0,0 +1,41 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ const defaultReadFile = (path, options) => readFile(path, options);
4
+ const defaultCwd = () => process.cwd();
5
+ function isRecord(value) {
6
+ return typeof value === 'object' && value !== null;
7
+ }
8
+ function readStringProp(record, key) {
9
+ const value = record[key];
10
+ return typeof value === 'string' ? value : undefined;
11
+ }
12
+ function buildPackageInfo(parsed) {
13
+ const name = readStringProp(parsed, 'name');
14
+ const version = readStringProp(parsed, 'version');
15
+ return {
16
+ ...(name !== undefined ? { name } : {}),
17
+ ...(version !== undefined ? { version } : {}),
18
+ };
19
+ }
20
+ function parsePackageJson(raw) {
21
+ const parsed = JSON.parse(raw);
22
+ if (!isRecord(parsed))
23
+ return {};
24
+ return buildPackageInfo(parsed);
25
+ }
26
+ function resolveReadFile(deps) {
27
+ return deps?.readFile ?? defaultReadFile;
28
+ }
29
+ function resolveCwd(deps) {
30
+ return deps?.cwd ?? defaultCwd;
31
+ }
32
+ function buildReadOptions(signal) {
33
+ return signal ? { encoding: 'utf8', signal } : { encoding: 'utf8' };
34
+ }
35
+ export async function readSelfPackageJson(signal, deps) {
36
+ const readFileImpl = resolveReadFile(deps);
37
+ const cwd = resolveCwd(deps);
38
+ const raw = await readFileImpl(join(cwd(), 'package.json'), buildReadOptions(signal));
39
+ return parsePackageJson(raw);
40
+ }
41
+ //# sourceMappingURL=package.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.js","sour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BAAgB,CAAC,MAAM,CAAC,CAAC;AAClC,CAAC;AAED,SAAS,eAAe,CAAC,IAA8B;IACrD,OAAO,IAAI,EAAE,QAAQ,IAAI,eAAe,CAAC;AAC3C,CAAC;AAED,SAAS,UAAU,CAAC,IAA8B;IAChD,OAAO,IAAI,EAAE,GAAG,IAAI,UAAU,CAAC;AACjC,CAAC;AAED,SAAS,gBAAgB,CAAC,MAAoB;IAI5C,OAAO,MAAM,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AACtE,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,MAAoB,EACpB,IAA8B;IAE9B,MAAM,YAAY,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IAC3C,MAAM,GAAG,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IAC7B,MAAM,GAAG,GAAG,MAAM,YAAY,CAC5B,IAAI,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,EAC3B,gBAAgB,CAAC,MAAM,CAAC,CACzB,CAAC;IACF,OAAO,gBAAgB,CAAC,GAAG,CAAC,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function installInitializationGuards(server: unknown): void;
2
+ //# sourceMappingURL=protocolGuards.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocolGuards.d.ts","sourceRoot":"","sources":["../../src/lib/protocolGuards.ts"],"names":[],"mappings":"AA+FA,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAUjE"}