@j0hanz/thinkseq-mcp 1.0.5 → 1.1.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.
Files changed (96) hide show
  1. package/README.md +161 -71
  2. package/dist/app.d.ts +2 -36
  3. package/dist/app.d.ts.map +1 -1
  4. package/dist/app.js +13 -99
  5. package/dist/app.js.map +1 -1
  6. package/dist/appConfig/runDependencies.d.ts +36 -0
  7. package/dist/appConfig/runDependencies.d.ts.map +1 -0
  8. package/dist/appConfig/runDependencies.js +65 -0
  9. package/dist/appConfig/runDependencies.js.map +1 -0
  10. package/dist/appConfig/shutdown.d.ts +19 -0
  11. package/dist/appConfig/shutdown.d.ts.map +1 -0
  12. package/dist/appConfig/shutdown.js +65 -0
  13. package/dist/appConfig/shutdown.js.map +1 -0
  14. package/dist/appConfig/types.d.ts +10 -0
  15. package/dist/appConfig/types.d.ts.map +1 -0
  16. package/dist/appConfig/types.js +2 -0
  17. package/dist/appConfig/types.js.map +1 -0
  18. package/dist/appConfig.d.ts +5 -0
  19. package/dist/appConfig.d.ts.map +1 -0
  20. package/dist/appConfig.js +3 -0
  21. package/dist/appConfig.js.map +1 -0
  22. package/dist/engine/pruning.d.ts +3 -0
  23. package/dist/engine/pruning.d.ts.map +1 -0
  24. package/dist/engine/pruning.js +11 -0
  25. package/dist/engine/pruning.js.map +1 -0
  26. package/dist/engine/revision.d.ts +9 -0
  27. package/dist/engine/revision.d.ts.map +1 -0
  28. package/dist/engine/revision.js +38 -0
  29. package/dist/engine/revision.js.map +1 -0
  30. package/dist/engine/thoughtQueries.d.ts +3 -0
  31. package/dist/engine/thoughtQueries.d.ts.map +1 -0
  32. package/dist/engine/thoughtQueries.js +18 -0
  33. package/dist/engine/thoughtQueries.js.map +1 -0
  34. package/dist/engine/thoughtStore.d.ts +22 -0
  35. package/dist/engine/thoughtStore.d.ts.map +1 -0
  36. package/dist/engine/thoughtStore.js +151 -0
  37. package/dist/engine/thoughtStore.js.map +1 -0
  38. package/dist/engine.d.ts.map +1 -1
  39. package/dist/engine.js +64 -158
  40. package/dist/engine.js.map +1 -1
  41. package/dist/engineConfig.d.ts +11 -0
  42. package/dist/engineConfig.d.ts.map +1 -0
  43. package/dist/engineConfig.js +12 -0
  44. package/dist/engineConfig.js.map +1 -0
  45. package/dist/index.js +35 -2
  46. package/dist/index.js.map +1 -1
  47. package/dist/lib/cli.d.ts +14 -0
  48. package/dist/lib/cli.d.ts.map +1 -0
  49. package/dist/lib/cli.js +71 -0
  50. package/dist/lib/cli.js.map +1 -0
  51. package/dist/lib/context.d.ts +7 -0
  52. package/dist/lib/context.d.ts.map +1 -0
  53. package/dist/lib/context.js +15 -0
  54. package/dist/lib/context.js.map +1 -0
  55. package/dist/lib/diagnostics.d.ts +9 -8
  56. package/dist/lib/diagnostics.d.ts.map +1 -1
  57. package/dist/lib/diagnostics.js +18 -8
  58. package/dist/lib/diagnostics.js.map +1 -1
  59. package/dist/lib/engineWorkerHandler.d.ts +12 -0
  60. package/dist/lib/engineWorkerHandler.d.ts.map +1 -0
  61. package/dist/lib/engineWorkerHandler.js +44 -0
  62. package/dist/lib/engineWorkerHandler.js.map +1 -0
  63. package/dist/lib/protocolGuards.d.ts.map +1 -1
  64. package/dist/lib/protocolGuards.js +8 -5
  65. package/dist/lib/protocolGuards.js.map +1 -1
  66. package/dist/lib/stdioGuards.d.ts.map +1 -1
  67. package/dist/lib/stdioGuards.js +23 -12
  68. package/dist/lib/stdioGuards.js.map +1 -1
  69. package/dist/lib/types.d.ts +13 -12
  70. package/dist/lib/types.d.ts.map +1 -1
  71. package/dist/lib/workerEngineClient.d.ts +23 -0
  72. package/dist/lib/workerEngineClient.d.ts.map +1 -0
  73. package/dist/lib/workerEngineClient.js +144 -0
  74. package/dist/lib/workerEngineClient.js.map +1 -0
  75. package/dist/lib/workerProtocol.d.ts +21 -0
  76. package/dist/lib/workerProtocol.d.ts.map +1 -0
  77. package/dist/lib/workerProtocol.js +22 -0
  78. package/dist/lib/workerProtocol.js.map +1 -0
  79. package/dist/schemas/inputs.d.ts +1 -13
  80. package/dist/schemas/inputs.d.ts.map +1 -1
  81. package/dist/schemas/inputs.js +5 -29
  82. package/dist/schemas/inputs.js.map +1 -1
  83. package/dist/schemas/outputs.d.ts +13 -16
  84. package/dist/schemas/outputs.d.ts.map +1 -1
  85. package/dist/schemas/outputs.js +46 -59
  86. package/dist/schemas/outputs.js.map +1 -1
  87. package/dist/tools/thinkseq.d.ts +7 -2
  88. package/dist/tools/thinkseq.d.ts.map +1 -1
  89. package/dist/tools/thinkseq.js +71 -59
  90. package/dist/tools/thinkseq.js.map +1 -1
  91. package/dist/tsconfig.tsbuildinfo +1 -1
  92. package/dist/workers/engineWorker.d.ts +2 -0
  93. package/dist/workers/engineWorker.d.ts.map +1 -0
  94. package/dist/workers/engineWorker.js +15 -0
  95. package/dist/workers/engineWorker.js.map +1 -0
  96. package/package.json +8 -6
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  <img src="docs/logo.png" alt="ThinkSeq MCP Server Logo" width="175" />
4
4
 
5
- An MCP implementation for advanced reasoning and thinking sequences.
5
+ An MCP server for structured, sequential thinking with revision support.
6
6
 
7
7
  [![npm version](https://img.shields.io/npm/v/@j0hanz/thinkseq-mcp.svg)](https://www.npmjs.com/package/@j0hanz/thinkseq-mcp)
8
8
 
@@ -14,7 +14,7 @@ An MCP implementation for advanced reasoning and thinking sequences.
14
14
 
15
15
  ## Overview
16
16
 
17
- ThinkSeq provides a single MCP tool, `thinkseq`, for structured, sequential thinking with branching and revision support. The server runs over stdio and keeps an in-memory history of thoughts so it can return progress, branches, and a short context summary on each call.
17
+ ThinkSeq exposes a single MCP tool, `thinkseq`, for structured, sequential thinking. The server runs over stdio and stores an in-memory thought history so it can return progress, active-path context, and revision metadata on each call.
18
18
 
19
19
  ## Quick start
20
20
 
@@ -22,6 +22,27 @@ ThinkSeq provides a single MCP tool, `thinkseq`, for structured, sequential thin
22
22
  npx -y @j0hanz/thinkseq-mcp@latest
23
23
  ```
24
24
 
25
+ ## CLI options
26
+
27
+ ```bash
28
+ thinkseq --max-thoughts 500 --max-memory-mb 100
29
+ ```
30
+
31
+ Available flags:
32
+
33
+ - `--max-thoughts <number>`: Max thoughts to keep in memory.
34
+ - `--max-memory-mb <number>`: Max memory (MB) for stored thoughts.
35
+ - `--shutdown-timeout-ms <number>`: Graceful shutdown timeout.
36
+ - `--package-read-timeout-ms <number>`: Package.json read timeout.
37
+ - `-h, --help`: Show help.
38
+
39
+ Defaults and limits:
40
+
41
+ - `maxThoughts` default: 500 (cap 10000).
42
+ - `maxMemoryBytes` default: 100 MB (derived from `--max-memory-mb`).
43
+ - `packageReadTimeoutMs` default: 2000 ms.
44
+ - `shutdownTimeoutMs` default: 5000 ms.
45
+
25
46
  ## MCP client configuration
26
47
 
27
48
  Add this to your MCP client settings:
@@ -105,60 +126,71 @@ Add to your `~/.codeium/windsurf/mcp_config.json`:
105
126
 
106
127
  ## Tool: `thinkseq`
107
128
 
108
- Structured sequential thinking with branching and revision support.
129
+ Record a concise thinking step. Be brief: capture only the essential insight, calculation, or decision-like a minimal draft, not a verbose explanation.
109
130
 
110
131
  ### Input
111
132
 
112
- | Field | Type | Required | Description |
113
- | :------------------ | :------ | :------: | :------------------------------------------------------------------------- |
114
- | `thought` | string | yes | Current thinking step (1 to 50000 chars). |
115
- | `thoughtNumber` | number | yes | Current thought number in sequence (1 to 10000). |
116
- | `totalThoughts` | number | yes | Estimated total thoughts needed (1 to 10000). |
117
- | `nextThoughtNeeded` | boolean | yes | Whether another thought step is needed. |
118
- | `isRevision` | boolean | no | Marks this thought as a revision. |
119
- | `revisesThought` | number | no | Thought number being revised (must exist). |
120
- | `branchFromThought` | number | no | Thought number to branch from (must exist). |
121
- | `branchId` | string | no | Branch identifier (1 to 100 chars). |
122
- | `thoughtType` | enum | no | One of `analysis`, `hypothesis`, `verification`, `revision`, `conclusion`. |
133
+ | Field | Type | Required | Description |
134
+ | :--------------- | :----- | :------: | :----------------------------------------------------------------- |
135
+ | `thought` | string | yes | Current thinking step (1-2000 chars). |
136
+ | `totalThoughts` | number | no | Estimated total thoughts (1-25, default: 3). |
137
+ | `revisesThought` | number | no | Revise a previous thought by number. Original preserved for audit. |
123
138
 
124
139
  ### Output
125
140
 
126
- The tool returns JSON with a success or error shape:
141
+ The tool returns `structuredContent` with an `ok` flag. On success, `result` is populated; on error, `error` is populated.
127
142
 
128
- - Success: `{ ok: true, result: { ... } }`
129
- - Error: `{ ok: false, error: { code, message } }`
143
+ Envelope fields:
144
+
145
+ | Field | Type | Description |
146
+ | :------- | :------ | :----------------------------------- |
147
+ | `ok` | boolean | `true` on success, `false` on error. |
148
+ | `result` | object | Present when `ok` is true. |
149
+ | `error` | object | Present when `ok` is false. |
130
150
 
131
151
  Result fields:
132
152
 
133
153
  | Field | Type | Description |
134
154
  | :--------------------- | :------- | :--------------------------------------------------- |
135
- | `thoughtNumber` | number | Stored thought number. |
155
+ | `thoughtNumber` | number | Auto-incremented thought number. |
136
156
  | `totalThoughts` | number | Effective total thoughts (at least `thoughtNumber`). |
137
157
  | `progress` | number | `thoughtNumber / totalThoughts` (0 to 1). |
138
- | `nextThoughtNeeded` | boolean | Mirrors input. |
158
+ | `isComplete` | boolean | `true` when `thoughtNumber >= totalThoughts`. |
139
159
  | `thoughtHistoryLength` | number | Stored thought count after pruning. |
140
- | `branches` | string[] | Known branch IDs. |
160
+ | `hasRevisions` | boolean | `true` if any thought has been revised. |
161
+ | `activePathLength` | number | Count of non-superseded thoughts. |
162
+ | `revisableThoughts` | number[] | Thought numbers available for revision. |
141
163
  | `context` | object | Recent context summary (see below). |
142
164
 
143
165
  Context fields:
144
166
 
145
- | Field | Type | Description |
146
- | :--------------- | :------ | :----------------------------------------------------------------------- |
147
- | `recentThoughts` | array | Up to the last 5 thoughts with `number`, `preview`, and optional `type`. |
148
- | `currentBranch` | string | Latest thought branch ID (if any). |
149
- | `hasRevisions` | boolean | Whether any revision has been recorded. |
167
+ | Field | Type | Description |
168
+ | :--------------- | :----- | :--------------------------------------------------------------------- |
169
+ | `recentThoughts` | array | Up to the last 5 active thoughts with `number` and `preview`. |
170
+ | `revisionInfo` | object | Present when revising: `revises` (number) and `supersedes` (number[]). |
171
+
172
+ Notes:
173
+
174
+ - `recentThoughts` previews are truncated to 100 characters.
175
+ - Revisions supersede the target thought and any later active thoughts.
176
+
177
+ Error fields:
178
+
179
+ | Code | Description |
180
+ | :----------------------------- | :---------------------------------------------- |
181
+ | `E_REVISION_TARGET_NOT_FOUND` | The requested thought number does not exist. |
182
+ | `E_REVISION_TARGET_SUPERSEDED` | The requested thought was already superseded. |
183
+ | `E_THINK` | Unexpected tool failure while processing input. |
150
184
 
151
185
  ### Example
152
186
 
187
+ **Basic usage:**
188
+
153
189
  Input:
154
190
 
155
191
  ```json
156
192
  {
157
- "thought": "Break down the problem into steps.",
158
- "thoughtNumber": 1,
159
- "totalThoughts": 3,
160
- "nextThoughtNeeded": true,
161
- "thoughtType": "analysis"
193
+ "thought": "3 steps: parse -> validate -> transform"
162
194
  }
163
195
  ```
164
196
 
@@ -171,18 +203,61 @@ Output (success):
171
203
  "thoughtNumber": 1,
172
204
  "totalThoughts": 3,
173
205
  "progress": 0.3333333333333333,
174
- "nextThoughtNeeded": true,
206
+ "isComplete": false,
175
207
  "thoughtHistoryLength": 1,
176
- "branches": [],
208
+ "hasRevisions": false,
209
+ "activePathLength": 1,
210
+ "revisableThoughts": [1],
177
211
  "context": {
178
212
  "recentThoughts": [
179
213
  {
180
214
  "number": 1,
181
- "preview": "Break down the problem into steps.",
182
- "type": "analysis"
215
+ "preview": "3 steps: parse -> validate -> transform"
216
+ }
217
+ ]
218
+ }
219
+ }
220
+ }
221
+ ```
222
+
223
+ **Revising a thought:**
224
+
225
+ If you realize an earlier step was wrong, use `revisesThought` to correct it:
226
+
227
+ Input:
228
+
229
+ ```json
230
+ {
231
+ "thought": "Better approach: validate first, then parse",
232
+ "revisesThought": 1
233
+ }
234
+ ```
235
+
236
+ Output:
237
+
238
+ ```json
239
+ {
240
+ "ok": true,
241
+ "result": {
242
+ "thoughtNumber": 2,
243
+ "totalThoughts": 3,
244
+ "progress": 0.6666666666666666,
245
+ "isComplete": false,
246
+ "thoughtHistoryLength": 2,
247
+ "hasRevisions": true,
248
+ "activePathLength": 1,
249
+ "revisableThoughts": [2],
250
+ "context": {
251
+ "recentThoughts": [
252
+ {
253
+ "number": 2,
254
+ "preview": "Better approach: validate first, then parse"
183
255
  }
184
256
  ],
185
- "hasRevisions": false
257
+ "revisionInfo": {
258
+ "revises": 1,
259
+ "supersedes": [1]
260
+ }
186
261
  }
187
262
  }
188
263
  }
@@ -191,26 +266,24 @@ Output (success):
191
266
  ## Behavior and validation
192
267
 
193
268
  - Inputs are validated with Zod and unknown keys are rejected.
194
- - The first thought must have `thoughtNumber` 1.
195
- - `revisesThought` and `branchFromThought` must reference an existing thought number.
196
- - Gaps in thought sequence are allowed but emit a diagnostics event.
197
- - `totalThoughts` is adjusted up to at least `thoughtNumber`.
269
+ - `thoughtNumber` is auto-incremented (1, 2, 3...).
270
+ - `totalThoughts` defaults to 3, must be in 1-25, and is adjusted up to at least `thoughtNumber`.
198
271
  - The engine stores thoughts in memory and prunes when limits are exceeded:
199
- - `maxThoughts` default: 500 (cap 10000)
200
- - `maxMemoryBytes` default: 100 MB
201
- - `estimatedThoughtOverheadBytes` default: 200
272
+ - `maxThoughts` default: 500 (cap 10000). When exceeded, prunes the oldest 10% (minimum excess).
273
+ - `maxMemoryBytes` default: 100 MB. When exceeded and history is large, prunes roughly 20% of history.
274
+ - `estimatedThoughtOverheadBytes` default: 200.
202
275
 
203
276
  ## Diagnostics
204
277
 
205
278
  This server publishes events via `node:diagnostics_channel`:
206
279
 
207
- - `thinkseq:tool` for `tool.start` and `tool.end` events
208
- - `thinkseq:lifecycle` for `lifecycle.started` and `lifecycle.shutdown`
209
- - `thinkseq:engine` for `engine.sequence_gap`
280
+ - `thinkseq:tool` for `tool.start` and `tool.end` (includes duration, errors, and request context).
281
+ - `thinkseq:lifecycle` for `lifecycle.started` and `lifecycle.shutdown`.
282
+ - `thinkseq:engine` for internal engine events such as `engine.sequence_gap`.
210
283
 
211
284
  ## Configuration
212
285
 
213
- No environment variables or CLI flags are required for basic operation. The server runs over stdio and enforces MCP initialization order and protocol version checks.
286
+ No environment variables or CLI flags are required for basic operation. The server runs over stdio, enforces MCP initialization order, and validates protocol versions. Invalid JSON-RPC message shapes and parse errors are surfaced as JSON-RPC errors on stdio.
214
287
 
215
288
  ## Development
216
289
 
@@ -220,38 +293,55 @@ No environment variables or CLI flags are required for basic operation. The serv
220
293
 
221
294
  ### Scripts
222
295
 
223
- | Command | Description |
224
- | :----------------------- | :---------------------------------------------------------- |
225
- | `npm run build` | Compile TypeScript to `dist/`. |
226
- | `npm run dev` | Run the server in watch mode. |
227
- | `npm start` | Run `dist/index.js`. |
228
- | `npm run test` | Run the test suite. |
229
- | `npm run test:coverage` | Run tests with coverage output. |
230
- | `npm run lint` | Lint with ESLint. |
231
- | `npm run format` | Format with Prettier. |
232
- | `npm run format:check` | Check formatting with Prettier. |
233
- | `npm run type-check` | Type-check without emitting. |
234
- | `npm run inspector` | Launch the MCP inspector. |
235
- | `npm run clean` | Remove `dist/`. |
236
- | `npm run prepublishOnly` | Lint, type-check, and build. |
237
- | `npm run benchmark` | Run `benchmark/engine.bench.ts` (add the file to use this). |
296
+ | Command | Description |
297
+ | :----------------------- | :------------------------------- |
298
+ | `npm run build` | Compile TypeScript to `dist/`. |
299
+ | `npm run dev` | Run the server in watch mode. |
300
+ | `npm start` | Run `dist/index.js`. |
301
+ | `npm run test` | Run the test suite. |
302
+ | `npm run test:ci` | Build, then run the test suite. |
303
+ | `npm run test:coverage` | Run tests with coverage output. |
304
+ | `npm run lint` | Lint with ESLint. |
305
+ | `npm run format` | Format with Prettier. |
306
+ | `npm run format:check` | Check formatting with Prettier. |
307
+ | `npm run type-check` | Type-check without emitting. |
308
+ | `npm run inspector` | Launch the MCP inspector. |
309
+ | `npm run clean` | Remove `dist/`. |
310
+ | `npm run prepublishOnly` | Lint, type-check, and build. |
311
+ | `npm run benchmark` | Run `benchmark/engine.bench.ts`. |
312
+
313
+ Benchmark environment variables:
314
+
315
+ - `THINKSEQ_BENCH_SAMPLES` (default: 1)
316
+ - `THINKSEQ_BENCH_NEW_ITERATIONS` (default: 10000)
317
+ - `THINKSEQ_BENCH_REV_ITERATIONS` (default: 1000)
318
+ - `THINKSEQ_BENCH_WARMUP` (default: 1000)
319
+ - `THINKSEQ_BENCH_PIN` (optional CPU affinity mask)
238
320
 
239
321
  ### Project structure
240
322
 
241
323
  ```text
242
324
  src/
243
- app.ts # Application setup and MCP wiring
244
- engine.ts # Core thinking engine
245
- index.ts # Entry point
246
- lib/ # Diagnostics, package, error, protocol, stdio utilities
247
- schemas/ # Zod input/output schemas
248
- tools/ # Tool definitions (thinkseq)
249
- tests/ # Node.js tests
250
- benchmark/ # Benchmark targets (currently empty)
251
- docs/ # Assets (logo)
252
- dist/ # Build output
325
+ app.ts # Application setup and MCP wiring
326
+ appConfig.ts # Dependency wiring and shutdown handling
327
+ engine.ts # Core thinking engine
328
+ engineConfig.ts # Defaults and limits
329
+ engine/ # Revision and query helpers
330
+ lib/ # CLI, diagnostics, errors, protocol, stdio utilities
331
+ schemas/ # Zod input/output schemas
332
+ tools/ # MCP tool definitions (thinkseq)
333
+ tests/ # Node.js tests
334
+ benchmark/ # Benchmark targets
335
+ docs/ # Assets (logo)
336
+ dist/ # Build output
337
+ scripts/ # Quality gates and metrics helpers
338
+ metrics/ # Generated metrics outputs
253
339
  ```
254
340
 
341
+ ## Troubleshooting
342
+
343
+ - CI workflow references `npm run maintainability` and `npm run duplication`, but these scripts are not defined in `package.json`.
344
+
255
345
  ## Contributing
256
346
 
257
347
  Contributions are welcome. Please open a pull request with a clear description and include relevant tests.
package/dist/app.d.ts CHANGED
@@ -1,43 +1,9 @@
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 {
1
+ import { type ProcessLike, type RunDependencies } from './appConfig.js';
2
+ interface ProcessErrorHandlerDeps {
17
3
  processLike?: ProcessLike;
18
4
  logError?: (message: string) => void;
19
5
  exit?: (code: number) => void;
20
6
  }
21
- interface ShutdownDependencies {
22
- processLike?: ProcessLike;
23
- server: Closeable;
24
- transport: Closeable;
25
- publishLifecycleEvent?: (event: LifecycleEvent) => void;
26
- now?: () => number;
27
- shutdownTimeoutMs?: number;
28
- }
29
- export interface RunDependencies {
30
- processLike?: ProcessLike;
31
- packageReadTimeoutMs?: number;
32
- readPackageJson?: (signal?: AbortSignal) => Promise<PackageInfo>;
33
- publishLifecycleEvent?: (event: LifecycleEvent) => void;
34
- createServer?: (name: string, version: string) => ServerLike;
35
- connectServer?: (server: ServerLike) => Promise<TransportLike>;
36
- registerTool?: (server: ServerLike, engine: EngineLike) => void;
37
- engineFactory?: () => EngineLike;
38
- installShutdownHandlers?: (deps: ShutdownDependencies) => void;
39
- now?: () => number;
40
- }
41
7
  export declare function installProcessErrorHandlers(deps?: ProcessErrorHandlerDeps): void;
42
8
  export declare function run(deps?: RunDependencies): Promise<void>;
43
9
  export {};
package/dist/app.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,OAA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M,KAAK,IAAI,CAAC;CAC/B;AAqBD,wBAAgB,2BAA2B,CACzC,IAAI,GAAE,uBAA4B,GACjC,IAAI,CAQN;AAED,wBAAsB,GAAG,CAAC,IAAI,GAAE,eAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAqBnE"}
package/dist/app.js CHANGED
@@ -1,104 +1,24 @@
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';
1
+ import { buildShutdownDependencies, resolvePackageIdentity, resolveRunDependencies, } from './appConfig.js';
6
2
  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
- const DEFAULT_SHUTDOWN_TIMEOUT_MS = 5000;
3
+ const toError = (value) => value instanceof Error ? value : new Error(String(value));
4
+ const createExit = (proc, exit) => exit ?? ((code) => proc.exit(code));
5
+ const createHandlerFor = (logError, exit) => (label) => (value) => {
6
+ const error = toError(value);
7
+ logError(`thinkseq: ${label}: ${error.message}`);
8
+ exit(1);
9
+ };
12
10
  export function installProcessErrorHandlers(deps = {}) {
13
11
  const proc = deps.processLike ?? process;
14
12
  const logError = deps.logError ?? console.error;
15
- const exit = deps.exit ??
16
- ((code) => {
17
- proc.exit(code);
18
- });
19
- const handlerFor = (label) => (value) => {
20
- const error = value instanceof Error ? value : new Error(String(value));
21
- logError(`thinkseq: ${label}: ${error.message}`);
22
- exit(1);
23
- };
13
+ const exit = createExit(proc, deps.exit);
14
+ const handlerFor = createHandlerFor(logError, exit);
24
15
  proc.on('unhandledRejection', handlerFor('unhandledRejection'));
25
16
  proc.on('uncaughtException', handlerFor('uncaughtException'));
26
17
  }
27
- function createServer(name, version) {
28
- return new McpServer({ name, version }, {
29
- instructions: SERVER_INSTRUCTIONS,
30
- capabilities: { logging: {} },
31
- });
32
- }
33
- async function connectServer(server) {
34
- const transport = new StdioServerTransport();
35
- await server.connect(transport);
36
- installStdioInvalidMessageGuards(transport);
37
- installStdioParseErrorResponder(transport);
38
- return transport;
39
- }
40
- const DEFAULT_RUN_DEPENDENCIES = {
41
- processLike: process,
42
- packageReadTimeoutMs: DEFAULT_PACKAGE_READ_TIMEOUT_MS,
43
- readPackageJson: readSelfPackageJson,
44
- publishLifecycleEvent,
45
- createServer,
46
- connectServer,
47
- registerTool: registerThinkSeq,
48
- engineFactory: () => new ThinkingEngine(),
49
- installShutdownHandlers,
50
- now: Date.now,
51
- };
52
- async function closeSafely(value) {
53
- try {
54
- if (typeof value.close === 'function') {
55
- await value.close();
56
- }
57
- }
58
- catch {
59
- return;
60
- }
61
- }
62
- async function closeWithTimeout(value, timeoutMs) {
63
- const timeout = new Promise((resolve) => {
64
- setTimeout(resolve, timeoutMs);
65
- });
66
- await Promise.race([closeSafely(value), timeout]);
67
- }
68
- function installShutdownHandlers({ processLike, server, transport, publishLifecycleEvent: publishLifecycle, now, shutdownTimeoutMs, }) {
69
- const proc = processLike ?? process;
70
- const emit = publishLifecycle ?? publishLifecycleEvent;
71
- const timestamp = now ?? Date.now;
72
- const timeoutMs = shutdownTimeoutMs ?? DEFAULT_SHUTDOWN_TIMEOUT_MS;
73
- let shuttingDown = false;
74
- const shutdown = async (signal) => {
75
- if (shuttingDown)
76
- return;
77
- shuttingDown = true;
78
- emit({
79
- type: 'lifecycle.shutdown',
80
- ts: timestamp(),
81
- signal,
82
- });
83
- await closeWithTimeout(server, timeoutMs);
84
- await closeWithTimeout(transport, timeoutMs);
85
- proc.exit(0);
86
- };
87
- proc.on('SIGTERM', () => {
88
- void shutdown('SIGTERM');
89
- });
90
- proc.on('SIGINT', () => {
91
- void shutdown('SIGINT');
92
- });
93
- }
94
18
  export async function run(deps = {}) {
95
- const resolved = {
96
- ...DEFAULT_RUN_DEPENDENCIES,
97
- ...deps,
98
- };
19
+ const resolved = resolveRunDependencies(deps);
99
20
  const pkg = await resolved.readPackageJson(AbortSignal.timeout(resolved.packageReadTimeoutMs));
100
- const name = pkg.name ?? 'thinkseq';
101
- const version = pkg.version ?? '0.0.0';
21
+ const { name, version } = resolvePackageIdentity(pkg);
102
22
  resolved.publishLifecycleEvent({
103
23
  type: 'lifecycle.started',
104
24
  ts: resolved.now(),
@@ -108,12 +28,6 @@ export async function run(deps = {}) {
108
28
  resolved.registerTool(server, engine);
109
29
  installInitializationGuards(server);
110
30
  const transport = await resolved.connectServer(server);
111
- resolved.installShutdownHandlers({
112
- processLike: resolved.processLike,
113
- server,
114
- transport,
115
- publishLifecycleEvent: resolved.publishLifecycleEvent,
116
- now: resolved.now,
117
- });
31
+ resolved.installShutdownHandlers(buildShutdownDependencies(resolved, { server, engine, transport }));
118
32
  }
119
33
  //# sourceMappingURL=app.js.map
package/dist/app.js.map CHANGED
@@ -1 +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,M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AAM,MAAM,GAAG,QAAQ,CAAC,aAAa,EAAE,CAAC;IACxC,QAAQ,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,2BAA2B,CAAC,MAAM,CAAC,CAAC;IAEpC,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IACvD,QAAQ,CAAC,uBAAuB,CAC9B,yBAAyB,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CACnE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,36 @@
1
+ import type { LifecycleEvent } from '../lib/diagnostics.js';
2
+ import type { PackageInfo } from '../lib/package.js';
3
+ import type { ShutdownDependencies } from './shutdown.js';
4
+ import type { EngineLike, ProcessLike, ServerLike, TransportLike } from './types.js';
5
+ export interface RunDependencies {
6
+ processLike?: ProcessLike;
7
+ packageReadTimeoutMs?: number;
8
+ shutdownTimeoutMs?: number;
9
+ readPackageJson?: (signal?: AbortSignal) => Promise<PackageInfo>;
10
+ publishLifecycleEvent?: (event: LifecycleEvent) => void;
11
+ createServer?: (name: string, version: string) => ServerLike;
12
+ connectServer?: (server: ServerLike, createTransport?: () => TransportLike) => Promise<TransportLike>;
13
+ registerTool?: (server: ServerLike, engine: EngineLike) => void;
14
+ engineFactory?: () => EngineLike;
15
+ installShutdownHandlers?: (deps: ShutdownDependencies) => void;
16
+ now?: () => number;
17
+ }
18
+ export interface ResolvedRunDependencies {
19
+ processLike: ProcessLike;
20
+ packageReadTimeoutMs: number;
21
+ shutdownTimeoutMs?: number;
22
+ readPackageJson: (signal?: AbortSignal) => Promise<PackageInfo>;
23
+ publishLifecycleEvent: (event: LifecycleEvent) => void;
24
+ createServer: (name: string, version: string) => ServerLike;
25
+ connectServer: (server: ServerLike, createTransport?: () => TransportLike) => Promise<TransportLike>;
26
+ registerTool: (server: ServerLike, engine: EngineLike) => void;
27
+ engineFactory: () => EngineLike;
28
+ installShutdownHandlers: (deps: ShutdownDependencies) => void;
29
+ now: () => number;
30
+ }
31
+ export declare function resolveRunDependencies(deps: RunDependencies): ResolvedRunDependencies;
32
+ export declare function resolvePackageIdentity(pkg: PackageInfo): {
33
+ name: string;
34
+ version: string;
35
+ };
36
+ //# sourceMappingURL=runDependencies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runDependencies.d.ts","sourceRoot":"","sources":["../../src/appConfig/runDependencies.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAOrD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAE1D,OAAO,KAAK,EACV,UAAU,EACV,WAAW,EACX,UAAU,EACV,aAAa,EACd,MAAM,YAAY,CAAC;AAMpB,MAAM,WAAW,eAAe;IAC9B,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,eAAe,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,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,CACd,MAAM,EAAE,UAAU,EAClB,eAAe,CAAC,EAAE,MAAM,aAAa,KAClC,OAAO,CAAC,aAAa,CAAC,CAAC;IAC5B,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;AAED,MAAM,WAAW,uBAAuB;IACtC,WAAW,EAAE,WAAW,CAAC;IACzB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,eAAe,EAAE,CAAC,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;IAChE,qBAAqB,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;IACvD,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,UAAU,CAAC;IAC5D,aAAa,EAAE,CACb,MAAM,EAAE,UAAU,EAClB,eAAe,CAAC,EAAE,MAAM,aAAa,KAClC,OAAO,CAAC,aAAa,CAAC,CAAC;IAC5B,YAAY,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;IAC/D,aAAa,EAAE,MAAM,UAAU,CAAC;IAChC,uBAAuB,EAAE,CAAC,IAAI,EAAE,oBAAoB,KAAK,IAAI,CAAC;IAC9D,GAAG,EAAE,MAAM,MAAM,CAAC;CACnB;AAyED,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,eAAe,GACpB,uBAAuB,CAOzB;AAED,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,WAAW,GAAG;IACxD,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB,CAKA"}
@@ -0,0 +1,65 @@
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 { installStdioInvalidMessageGuards, installStdioParseErrorResponder, } from '../lib/stdioGuards.js';
7
+ import { registerThinkSeq } from '../tools/thinkseq.js';
8
+ import { installShutdownHandlers } from './shutdown.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
+ const defaultCreateServer = (name, version) => {
12
+ return new McpServer({ name, version }, {
13
+ instructions: SERVER_INSTRUCTIONS,
14
+ capabilities: { logging: {} },
15
+ });
16
+ };
17
+ const defaultConnectServer = async (server, createTransport = () => new StdioServerTransport()) => {
18
+ const transport = createTransport();
19
+ await server.connect(transport);
20
+ installStdioInvalidMessageGuards(transport);
21
+ installStdioParseErrorResponder(transport);
22
+ return transport;
23
+ };
24
+ function resolveCoreDependencies(deps) {
25
+ return {
26
+ processLike: deps.processLike ?? process,
27
+ packageReadTimeoutMs: deps.packageReadTimeoutMs ?? DEFAULT_PACKAGE_READ_TIMEOUT_MS,
28
+ readPackageJson: deps.readPackageJson ?? readSelfPackageJson,
29
+ publishLifecycleEvent: deps.publishLifecycleEvent ?? publishLifecycleEvent,
30
+ now: deps.now ?? Date.now,
31
+ };
32
+ }
33
+ function resolveServerDependencies(deps) {
34
+ return {
35
+ createServer: deps.createServer ?? defaultCreateServer,
36
+ connectServer: deps.connectServer ?? defaultConnectServer,
37
+ };
38
+ }
39
+ function resolveEngineDependencies(deps) {
40
+ return {
41
+ registerTool: deps.registerTool ?? registerThinkSeq,
42
+ engineFactory: deps.engineFactory ?? (() => new ThinkingEngine()),
43
+ installShutdownHandlers: deps.installShutdownHandlers ?? installShutdownHandlers,
44
+ };
45
+ }
46
+ function resolveShutdownTimeout(deps) {
47
+ if (deps.shutdownTimeoutMs === undefined)
48
+ return {};
49
+ return { shutdownTimeoutMs: deps.shutdownTimeoutMs };
50
+ }
51
+ export function resolveRunDependencies(deps) {
52
+ return {
53
+ ...resolveCoreDependencies(deps),
54
+ ...resolveServerDependencies(deps),
55
+ ...resolveEngineDependencies(deps),
56
+ ...resolveShutdownTimeout(deps),
57
+ };
58
+ }
59
+ export function resolvePackageIdentity(pkg) {
60
+ return {
61
+ name: pkg.name ?? 'thinkseq',
62
+ version: pkg.version ?? '0.0.0',
63
+ };
64
+ }
65
+ //# sourceMappingURL=runDependencies.js.map