@j0hanz/thinkseq-mcp 1.2.5 → 1.2.7

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 (91) hide show
  1. package/dist/app.d.ts +0 -1
  2. package/dist/app.js +0 -1
  3. package/dist/appConfig/runDependencies.d.ts +0 -1
  4. package/dist/appConfig/runDependencies.js +6 -4
  5. package/dist/appConfig/shutdown.d.ts +0 -1
  6. package/dist/appConfig/shutdown.js +0 -1
  7. package/dist/appConfig/types.d.ts +0 -1
  8. package/dist/appConfig/types.js +0 -1
  9. package/dist/appConfig.d.ts +0 -1
  10. package/dist/appConfig.js +0 -1
  11. package/dist/engine/revision.d.ts +0 -1
  12. package/dist/engine/revision.js +0 -1
  13. package/dist/engine/thoughtQueries.d.ts +0 -1
  14. package/dist/engine/thoughtQueries.js +24 -21
  15. package/dist/engine/thoughtStore.d.ts +5 -3
  16. package/dist/engine/thoughtStore.js +18 -7
  17. package/dist/engine.d.ts +0 -1
  18. package/dist/engine.js +4 -18
  19. package/dist/engineConfig.d.ts +0 -1
  20. package/dist/engineConfig.js +0 -1
  21. package/dist/index.d.ts +0 -1
  22. package/dist/index.js +0 -1
  23. package/dist/instructions.md +1 -1
  24. package/dist/lib/cli.d.ts +0 -1
  25. package/dist/lib/cli.js +0 -1
  26. package/dist/lib/context.d.ts +0 -1
  27. package/dist/lib/context.js +0 -1
  28. package/dist/lib/diagnostics.d.ts +0 -1
  29. package/dist/lib/diagnostics.js +0 -1
  30. package/dist/lib/errors.d.ts +0 -1
  31. package/dist/lib/errors.js +0 -1
  32. package/dist/lib/mcpLogging.d.ts +0 -1
  33. package/dist/lib/mcpLogging.js +0 -1
  34. package/dist/lib/package.d.ts +0 -1
  35. package/dist/lib/package.js +0 -1
  36. package/dist/lib/stdioGuards.d.ts +0 -1
  37. package/dist/lib/stdioGuards.js +59 -46
  38. package/dist/lib/types.d.ts +0 -1
  39. package/dist/lib/types.js +0 -1
  40. package/dist/schemas/inputs.d.ts +0 -1
  41. package/dist/schemas/inputs.js +0 -1
  42. package/dist/schemas/outputs.d.ts +0 -1
  43. package/dist/schemas/outputs.js +0 -1
  44. package/dist/tools/thinkseq.d.ts +0 -1
  45. package/dist/tools/thinkseq.js +54 -43
  46. package/dist/tsconfig.tsbuildinfo +1 -1
  47. package/package.json +2 -2
  48. package/dist/app.d.ts.map +0 -1
  49. package/dist/app.js.map +0 -1
  50. package/dist/appConfig/runDependencies.d.ts.map +0 -1
  51. package/dist/appConfig/runDependencies.js.map +0 -1
  52. package/dist/appConfig/shutdown.d.ts.map +0 -1
  53. package/dist/appConfig/shutdown.js.map +0 -1
  54. package/dist/appConfig/types.d.ts.map +0 -1
  55. package/dist/appConfig/types.js.map +0 -1
  56. package/dist/appConfig.d.ts.map +0 -1
  57. package/dist/appConfig.js.map +0 -1
  58. package/dist/engine/revision.d.ts.map +0 -1
  59. package/dist/engine/revision.js.map +0 -1
  60. package/dist/engine/thoughtQueries.d.ts.map +0 -1
  61. package/dist/engine/thoughtQueries.js.map +0 -1
  62. package/dist/engine/thoughtStore.d.ts.map +0 -1
  63. package/dist/engine/thoughtStore.js.map +0 -1
  64. package/dist/engine.d.ts.map +0 -1
  65. package/dist/engine.js.map +0 -1
  66. package/dist/engineConfig.d.ts.map +0 -1
  67. package/dist/engineConfig.js.map +0 -1
  68. package/dist/index.d.ts.map +0 -1
  69. package/dist/index.js.map +0 -1
  70. package/dist/lib/cli.d.ts.map +0 -1
  71. package/dist/lib/cli.js.map +0 -1
  72. package/dist/lib/context.d.ts.map +0 -1
  73. package/dist/lib/context.js.map +0 -1
  74. package/dist/lib/diagnostics.d.ts.map +0 -1
  75. package/dist/lib/diagnostics.js.map +0 -1
  76. package/dist/lib/errors.d.ts.map +0 -1
  77. package/dist/lib/errors.js.map +0 -1
  78. package/dist/lib/mcpLogging.d.ts.map +0 -1
  79. package/dist/lib/mcpLogging.js.map +0 -1
  80. package/dist/lib/package.d.ts.map +0 -1
  81. package/dist/lib/package.js.map +0 -1
  82. package/dist/lib/stdioGuards.d.ts.map +0 -1
  83. package/dist/lib/stdioGuards.js.map +0 -1
  84. package/dist/lib/types.d.ts.map +0 -1
  85. package/dist/lib/types.js.map +0 -1
  86. package/dist/schemas/inputs.d.ts.map +0 -1
  87. package/dist/schemas/inputs.js.map +0 -1
  88. package/dist/schemas/outputs.d.ts.map +0 -1
  89. package/dist/schemas/outputs.js.map +0 -1
  90. package/dist/tools/thinkseq.d.ts.map +0 -1
  91. package/dist/tools/thinkseq.js.map +0 -1
package/dist/app.d.ts CHANGED
@@ -7,4 +7,3 @@ interface ProcessErrorHandlerDeps {
7
7
  export declare function installProcessErrorHandlers(deps?: ProcessErrorHandlerDeps): void;
8
8
  export declare function run(deps?: RunDependencies): Promise<void>;
9
9
  export {};
10
- //# sourceMappingURL=app.d.ts.map
package/dist/app.js CHANGED
@@ -31,4 +31,3 @@ export async function run(deps = {}) {
31
31
  const transport = await resolved.connectServer(server);
32
32
  resolved.installShutdownHandlers(buildShutdownDependencies(resolved, { server, engine, transport }));
33
33
  }
34
- //# sourceMappingURL=app.js.map
@@ -33,4 +33,3 @@ export declare function resolvePackageIdentity(pkg: PackageInfo): {
33
33
  name: string;
34
34
  version: string;
35
35
  };
36
- //# sourceMappingURL=runDependencies.d.ts.map
@@ -35,8 +35,8 @@ function registerInstructionsResource(server) {
35
35
  }
36
36
  const SERVER_INSTRUCTIONS = loadServerInstructions();
37
37
  const DEFAULT_PACKAGE_READ_TIMEOUT_MS = 2000;
38
- const defaultCreateServer = (name, version) => {
39
- const server = new McpServer({ name, version }, {
38
+ function buildServerConfig() {
39
+ return {
40
40
  instructions: SERVER_INSTRUCTIONS,
41
41
  capabilities: {
42
42
  logging: {},
@@ -44,7 +44,10 @@ const defaultCreateServer = (name, version) => {
44
44
  resources: { subscribe: false, listChanged: false },
45
45
  prompts: { listChanged: false },
46
46
  },
47
- });
47
+ };
48
+ }
49
+ const defaultCreateServer = (name, version) => {
50
+ const server = new McpServer({ name, version }, buildServerConfig());
48
51
  registerInstructionsResource(server);
49
52
  server.registerPrompt('get-help', {
50
53
  description: 'Get usage instructions for this server',
@@ -102,4 +105,3 @@ export function resolvePackageIdentity(pkg) {
102
105
  version: pkg.version ?? '0.0.0',
103
106
  };
104
107
  }
105
- //# sourceMappingURL=runDependencies.js.map
@@ -16,4 +16,3 @@ export declare function buildShutdownDependencies(resolved: ResolvedRunDependenc
16
16
  engine: unknown;
17
17
  transport: unknown;
18
18
  }): ShutdownDependencies;
19
- //# sourceMappingURL=shutdown.d.ts.map
@@ -67,4 +67,3 @@ export function buildShutdownDependencies(resolved, payload) {
67
67
  ? { ...base, shutdownTimeoutMs: resolved.shutdownTimeoutMs }
68
68
  : base;
69
69
  }
70
- //# sourceMappingURL=shutdown.js.map
@@ -3,4 +3,3 @@ export type { CloseFn, EngineLike } from '../lib/types.js';
3
3
  export type ProcessLike = Pick<typeof process, 'on' | 'exit'>;
4
4
  export type TransportLike = Parameters<McpServer['connect']>[0];
5
5
  export type ServerLike = Pick<McpServer, 'connect' | 'registerTool' | 'registerResource' | 'registerPrompt' | 'sendLoggingMessage'>;
6
- //# sourceMappingURL=types.d.ts.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=types.js.map
@@ -2,4 +2,3 @@ export type { ProcessLike } from './appConfig/types.js';
2
2
  export type { RunDependencies } from './appConfig/runDependencies.js';
3
3
  export { resolvePackageIdentity, resolveRunDependencies, } from './appConfig/runDependencies.js';
4
4
  export { buildShutdownDependencies } from './appConfig/shutdown.js';
5
- //# sourceMappingURL=appConfig.d.ts.map
package/dist/appConfig.js CHANGED
@@ -1,3 +1,2 @@
1
1
  export { resolvePackageIdentity, resolveRunDependencies, } from './appConfig/runDependencies.js';
2
2
  export { buildShutdownDependencies } from './appConfig/shutdown.js';
3
- //# sourceMappingURL=appConfig.js.map
@@ -6,4 +6,3 @@ export declare function resolveRevisionTarget(input: ThoughtData, getThoughtByNu
6
6
  ok: false;
7
7
  error: ProcessResult;
8
8
  };
9
- //# sourceMappingURL=revision.d.ts.map
@@ -28,4 +28,3 @@ function buildRevisionError(code, message) {
28
28
  error: { code, message },
29
29
  };
30
30
  }
31
- //# sourceMappingURL=revision.js.map
@@ -1,3 +1,2 @@
1
1
  import type { ContextSummary, RevisionInfo, StoredThought } from '../lib/types.js';
2
2
  export declare function buildContextSummary(activeThoughts: readonly StoredThought[], revisionInfo?: RevisionInfo): ContextSummary;
3
- //# sourceMappingURL=thoughtQueries.d.ts.map
@@ -1,31 +1,34 @@
1
- export function buildContextSummary(activeThoughts, revisionInfo) {
2
- let recent;
3
- let stepIndexes;
4
- if (activeThoughts.length > 5) {
5
- const anchor = activeThoughts[0];
6
- if (!anchor)
7
- throw new Error('Invariant violation: anchor thought missing');
8
- const tail = activeThoughts.slice(-4);
9
- recent = [anchor, ...tail];
10
- stepIndexes = [
11
- 1,
12
- ...tail.map((_, index) => activeThoughts.length - 4 + index + 1),
13
- ];
14
- }
15
- else {
16
- recent = activeThoughts.slice();
17
- stepIndexes = recent.map((_, index) => index + 1);
1
+ function selectRecentThoughts(activeThoughts) {
2
+ if (activeThoughts.length <= 5) {
3
+ const recent = activeThoughts.slice();
4
+ const stepIndexes = recent.map((_, index) => index + 1);
5
+ return { recent, stepIndexes };
18
6
  }
7
+ const anchor = activeThoughts[0];
8
+ if (!anchor)
9
+ throw new Error('Invariant violation: anchor thought missing');
10
+ const tail = activeThoughts.slice(-4);
11
+ const recent = [anchor, ...tail];
12
+ const stepIndexes = [
13
+ 1,
14
+ ...tail.map((_, index) => activeThoughts.length - 4 + index + 1),
15
+ ];
16
+ return { recent, stepIndexes };
17
+ }
18
+ function formatThoughtPreview(thought) {
19
+ if (thought.length <= 100)
20
+ return thought;
21
+ return `${thought.slice(0, 100)}...`;
22
+ }
23
+ export function buildContextSummary(activeThoughts, revisionInfo) {
24
+ const { recent, stepIndexes } = selectRecentThoughts(activeThoughts);
19
25
  const recentThoughts = recent.map((thought, index) => ({
20
26
  stepIndex: stepIndexes[index] ?? index + 1,
21
27
  number: thought.thoughtNumber,
22
- preview: thought.thought.length > 100
23
- ? `${thought.thought.slice(0, 100)}...`
24
- : thought.thought,
28
+ preview: formatThoughtPreview(thought.thought),
25
29
  }));
26
30
  if (revisionInfo !== undefined) {
27
31
  return { recentThoughts, revisionInfo };
28
32
  }
29
33
  return { recentThoughts };
30
34
  }
31
- //# sourceMappingURL=thoughtQueries.js.map
@@ -12,11 +12,13 @@ export declare class ThoughtStore {
12
12
  totalThoughts: number;
13
13
  };
14
14
  storeThought(stored: StoredThought): void;
15
- supersedeFrom(targetNumber: number, supersededBy: number): number[];
15
+ supersedeFrom(targetNumber: number, supersededBy: number, maxSupersedes?: number): {
16
+ supersedes: number[];
17
+ supersedesTotal: number;
18
+ };
16
19
  getActiveThoughts(): readonly StoredThought[];
17
- getActiveThoughtNumbers(): readonly number[];
20
+ getActiveThoughtNumbers(max?: number): number[];
18
21
  getThoughtByNumber(thoughtNumber: number): StoredThought | undefined;
19
22
  getTotalLength(): number;
20
23
  pruneHistoryIfNeeded(): void;
21
24
  }
22
- //# sourceMappingURL=thoughtStore.d.ts.map
@@ -65,11 +65,12 @@ export class ThoughtStore {
65
65
  }
66
66
  return -1;
67
67
  }
68
- supersedeFrom(targetNumber, supersededBy) {
68
+ supersedeFrom(targetNumber, supersededBy, maxSupersedes) {
69
69
  const startIndex = this.#findActiveThoughtIndex(targetNumber);
70
70
  if (startIndex < 0)
71
- return [];
71
+ return { supersedes: [], supersedesTotal: 0 };
72
72
  const supersedes = [];
73
+ let supersedesTotal = 0;
73
74
  for (let i = startIndex; i < this.#activeThoughts.length; i += 1) {
74
75
  const thought = this.#activeThoughts[i];
75
76
  if (!thought)
@@ -78,18 +79,29 @@ export class ThoughtStore {
78
79
  thought.isActive = false;
79
80
  thought.supersededBy = supersededBy;
80
81
  }
81
- supersedes.push(thought.thoughtNumber);
82
+ supersedesTotal += 1;
83
+ if (maxSupersedes === undefined || supersedes.length < maxSupersedes) {
84
+ supersedes.push(thought.thoughtNumber);
85
+ }
82
86
  }
83
87
  this.#activeThoughts.length = startIndex;
84
88
  this.#activeThoughtNumbers.length = startIndex;
85
89
  this.#recomputeActiveMaxTotalThoughts();
86
- return supersedes;
90
+ return { supersedes, supersedesTotal };
87
91
  }
88
92
  getActiveThoughts() {
89
93
  return this.#activeThoughts;
90
94
  }
91
- getActiveThoughtNumbers() {
92
- return this.#activeThoughtNumbers.slice();
95
+ getActiveThoughtNumbers(max) {
96
+ if (max === undefined) {
97
+ return this.#activeThoughtNumbers.slice();
98
+ }
99
+ if (max <= 0)
100
+ return [];
101
+ if (this.#activeThoughtNumbers.length <= max) {
102
+ return this.#activeThoughtNumbers.slice();
103
+ }
104
+ return this.#activeThoughtNumbers.slice(-max);
93
105
  }
94
106
  getThoughtByNumber(thoughtNumber) {
95
107
  return this.#thoughtIndex.get(thoughtNumber);
@@ -188,4 +200,3 @@ export class ThoughtStore {
188
200
  this.#estimatedBytes = 0;
189
201
  }
190
202
  }
191
- //# sourceMappingURL=thoughtStore.js.map
package/dist/engine.d.ts CHANGED
@@ -10,4 +10,3 @@ export declare class ThinkingEngine {
10
10
  constructor(options?: ThinkingEngineOptions);
11
11
  processThought(input: ThoughtData): ProcessResult;
12
12
  }
13
- //# sourceMappingURL=engine.d.ts.map
package/dist/engine.js CHANGED
@@ -36,9 +36,7 @@ export class ThinkingEngine {
36
36
  const { numbers, stored } = this.#createStoredThought(input, {
37
37
  revisionOf: targetNumber,
38
38
  });
39
- const supersedesAll = this.#store.supersedeFrom(targetNumber, numbers.thoughtNumber);
40
- const supersedesTotal = supersedesAll.length;
41
- const supersedes = capArrayStart(supersedesAll, MAX_SUPERSEDES);
39
+ const { supersedes, supersedesTotal } = this.#store.supersedeFrom(targetNumber, numbers.thoughtNumber, MAX_SUPERSEDES);
42
40
  this.#hasRevisions = true;
43
41
  this.#commitThought(stored);
44
42
  return this.#buildProcessResult(stored, {
@@ -77,7 +75,7 @@ export class ThinkingEngine {
77
75
  }
78
76
  #resolveEffectiveTotalThoughts(input) {
79
77
  if (input.totalThoughts !== undefined) {
80
- return input.totalThoughts;
78
+ return normalizeInt(input.totalThoughts, _a.DEFAULT_TOTAL_THOUGHTS, { min: 1, max: MAX_THOUGHTS_CAP });
81
79
  }
82
80
  const activeThoughts = this.#store.getActiveThoughts();
83
81
  const lastActive = activeThoughts[activeThoughts.length - 1];
@@ -90,9 +88,8 @@ export class ThinkingEngine {
90
88
  const activeThoughts = this.#store.getActiveThoughts();
91
89
  const context = buildContextSummary(activeThoughts, revisionInfo);
92
90
  const isComplete = stored.thoughtNumber >= stored.totalThoughts;
93
- const revisableThoughtsAll = this.#store.getActiveThoughtNumbers();
94
- const revisableThoughtsTotal = revisableThoughtsAll.length;
95
- const revisableThoughts = capArrayEnd(revisableThoughtsAll, MAX_REVISABLE_THOUGHTS);
91
+ const revisableThoughtsTotal = activeThoughts.length;
92
+ const revisableThoughts = this.#store.getActiveThoughtNumbers(MAX_REVISABLE_THOUGHTS);
96
93
  return {
97
94
  ok: true,
98
95
  result: {
@@ -111,14 +108,3 @@ export class ThinkingEngine {
111
108
  }
112
109
  }
113
110
  _a = ThinkingEngine;
114
- function capArrayStart(values, max) {
115
- if (values.length <= max)
116
- return values.slice();
117
- return values.slice(0, max);
118
- }
119
- function capArrayEnd(values, max) {
120
- if (values.length <= max)
121
- return values.slice();
122
- return values.slice(-max);
123
- }
124
- //# sourceMappingURL=engine.js.map
@@ -10,4 +10,3 @@ export declare function normalizeInt(value: number | undefined, fallback: number
10
10
  min: number;
11
11
  max: number;
12
12
  }): number;
13
- //# sourceMappingURL=engineConfig.d.ts.map
@@ -11,4 +11,3 @@ export function normalizeInt(value, fallback, options) {
11
11
  return fallback;
12
12
  return Math.max(options.min, Math.min(options.max, Math.trunc(value)));
13
13
  }
14
- //# sourceMappingURL=engineConfig.js.map
package/dist/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  #!/usr/bin/env node
2
2
  export {};
3
- //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -39,4 +39,3 @@ const runCli = async () => {
39
39
  await run(buildRunDependencies(config));
40
40
  };
41
41
  void runCli().catch(fatal);
42
- //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
1
1
  # ThinkSeq Instructions
2
2
 
3
- > **Guidance for the Agent:** These instructions are available as a resource (`internal://instructions`).
3
+ > **Guidance for the Agent:** These instructions are available as a resource (`internal://instructions`). Load them when you are confused about tool usage.
4
4
 
5
5
  ## 1. Core Capability
6
6
 
package/dist/lib/cli.d.ts CHANGED
@@ -11,4 +11,3 @@ export interface CliParseResult {
11
11
  export declare function getCliHelpText(): string;
12
12
  export declare function parseCliConfig(args?: readonly string[]): CliParseResult;
13
13
  export {};
14
- //# sourceMappingURL=cli.d.ts.map
package/dist/lib/cli.js CHANGED
@@ -74,4 +74,3 @@ export function parseCliConfig(args) {
74
74
  config: buildCliConfig(values),
75
75
  };
76
76
  }
77
- //# sourceMappingURL=cli.js.map
@@ -5,4 +5,3 @@ export interface RequestContext {
5
5
  }
6
6
  export declare function runWithContext<T>(callback: () => T, context?: Partial<RequestContext>): T;
7
7
  export declare function getRequestContext(): RequestContext | undefined;
8
- //# sourceMappingURL=context.d.ts.map
@@ -13,4 +13,3 @@ export function runWithContext(callback, context) {
13
13
  export function getRequestContext() {
14
14
  return storage.getStore();
15
15
  }
16
- //# sourceMappingURL=context.js.map
@@ -36,4 +36,3 @@ export type LifecycleEvent = {
36
36
  export declare function publishToolEvent(event: ToolEvent): void;
37
37
  export declare function publishLifecycleEvent(event: LifecycleEvent): void;
38
38
  export {};
39
- //# sourceMappingURL=diagnostics.d.ts.map
@@ -32,4 +32,3 @@ export function publishToolEvent(event) {
32
32
  export function publishLifecycleEvent(event) {
33
33
  safePublish(lifecycleChannel, event);
34
34
  }
35
- //# sourceMappingURL=diagnostics.js.map
@@ -18,4 +18,3 @@ export interface CreateErrorResponseOptions {
18
18
  }
19
19
  export declare function getErrorMessage(error: unknown): string;
20
20
  export declare function createErrorResponse(code: string, message: string, result?: unknown, options?: CreateErrorResponseOptions): ErrorResponse;
21
- //# sourceMappingURL=errors.d.ts.map
@@ -21,4 +21,3 @@ export function createErrorResponse(code, message, result, options = {}) {
21
21
  };
22
22
  return response;
23
23
  }
24
- //# sourceMappingURL=errors.js.map
@@ -4,4 +4,3 @@ export interface LoggingTarget {
4
4
  }
5
5
  export declare function installMcpLogging(target: LoggingTarget): () => void;
6
6
  export declare function installConsoleBridge(target: LoggingTarget): void;
7
- //# sourceMappingURL=mcpLogging.d.ts.map
@@ -74,4 +74,3 @@ export function installConsoleBridge(target) {
74
74
  });
75
75
  };
76
76
  }
77
- //# sourceMappingURL=mcpLogging.js.map
@@ -12,4 +12,3 @@ export interface PackageJsonDependencies {
12
12
  }
13
13
  export declare function readSelfPackageJson(signal?: AbortSignal, deps?: PackageJsonDependencies): Promise<PackageInfo>;
14
14
  export {};
15
- //# sourceMappingURL=package.d.ts.map
@@ -45,4 +45,3 @@ export async function readSelfPackageJson(signal, deps) {
45
45
  return {};
46
46
  }
47
47
  }
48
- //# sourceMappingURL=package.js.map
@@ -1,4 +1,3 @@
1
1
  export declare function installStdioInitializationGuards(transport: unknown): void;
2
2
  export declare function installStdioInvalidMessageGuards(transport: unknown): void;
3
3
  export declare function installStdioParseErrorResponder(transport: unknown): void;
4
- //# sourceMappingURL=stdioGuards.d.ts.map
@@ -68,6 +68,63 @@ function isParseError(error) {
68
68
  function isSchemaError(error) {
69
69
  return error instanceof Error && error.name === 'ZodError';
70
70
  }
71
+ function wrapSendForInitTracking(transport, state) {
72
+ if (!transport.send)
73
+ return;
74
+ const originalSend = transport.send.bind(transport);
75
+ transport.send = (message) => {
76
+ trackInitializeResponse(message, state);
77
+ return originalSend(message);
78
+ };
79
+ }
80
+ function trackInitializeResponse(message, state) {
81
+ try {
82
+ const response = parseJsonRpcResponse(message);
83
+ if (!response)
84
+ return;
85
+ const key = getIdKey(response.id);
86
+ if (!state.pendingInitIds.has(key))
87
+ return;
88
+ state.pendingInitIds.delete(key);
89
+ if (response.error === undefined) {
90
+ state.sawInitialize = true;
91
+ }
92
+ }
93
+ catch {
94
+ // Ignore send inspection errors.
95
+ }
96
+ }
97
+ function handleInitializeMethod(methodMessage, state, originalOnMessage, message, extra) {
98
+ state.pendingInitIds.add(getIdKey(methodMessage.id));
99
+ originalOnMessage(message, extra);
100
+ return true;
101
+ }
102
+ function handleNonInitializedRequest(methodMessage, transport) {
103
+ if (methodMessage.hasId) {
104
+ sendError(transport, ErrorCode.InvalidRequest, INIT_FIRST_ERROR_MESSAGE, methodMessage.id);
105
+ }
106
+ return true;
107
+ }
108
+ function createInitGuardHandler(state, originalOnMessage, transport) {
109
+ return (message, extra) => {
110
+ const methodMessage = parseJsonRpcMethodMessage(message);
111
+ if (!methodMessage) {
112
+ originalOnMessage(message, extra);
113
+ return;
114
+ }
115
+ if (methodMessage.method === 'initialize') {
116
+ if (!methodMessage.hasId)
117
+ return;
118
+ handleInitializeMethod(methodMessage, state, originalOnMessage, message, extra);
119
+ return;
120
+ }
121
+ if (!state.sawInitialize) {
122
+ handleNonInitializedRequest(methodMessage, transport);
123
+ return;
124
+ }
125
+ originalOnMessage(message, extra);
126
+ };
127
+ }
71
128
  export function installStdioInitializationGuards(transport) {
72
129
  if (!isStdioMessageTransport(transport))
73
130
  return;
@@ -78,51 +135,8 @@ export function installStdioInitializationGuards(transport) {
78
135
  sawInitialize: false,
79
136
  pendingInitIds: new Set(),
80
137
  };
81
- if (transport.send) {
82
- const originalSend = transport.send.bind(transport);
83
- transport.send = (message) => {
84
- try {
85
- const response = parseJsonRpcResponse(message);
86
- if (response) {
87
- const key = getIdKey(response.id);
88
- if (state.pendingInitIds.has(key)) {
89
- state.pendingInitIds.delete(key);
90
- if (response.error === undefined) {
91
- state.sawInitialize = true;
92
- }
93
- }
94
- }
95
- }
96
- catch {
97
- // Ignore send inspection errors.
98
- }
99
- return originalSend(message);
100
- };
101
- }
102
- transport.onmessage = (message, extra) => {
103
- const methodMessage = parseJsonRpcMethodMessage(message);
104
- if (methodMessage) {
105
- if (methodMessage.method === 'initialize') {
106
- if (!methodMessage.hasId) {
107
- // initialize must be a request (not a notification).
108
- return;
109
- }
110
- // DELEGATION: We intentionally skip manual protocolVersion checks here and
111
- // let the SDK handle version negotiation. This prevents this guard from
112
- // becoming a maintenance burden or rejecting valid newer versions.
113
- state.pendingInitIds.add(getIdKey(methodMessage.id));
114
- originalOnMessage(message, extra);
115
- return;
116
- }
117
- if (!state.sawInitialize) {
118
- if (methodMessage.hasId) {
119
- sendError(transport, ErrorCode.InvalidRequest, INIT_FIRST_ERROR_MESSAGE, methodMessage.id);
120
- }
121
- return;
122
- }
123
- }
124
- originalOnMessage(message, extra);
125
- };
138
+ wrapSendForInitTracking(transport, state);
139
+ transport.onmessage = createInitGuardHandler(state, originalOnMessage, transport);
126
140
  }
127
141
  export function installStdioInvalidMessageGuards(transport) {
128
142
  if (!isStdioMessageTransport(transport))
@@ -155,4 +169,3 @@ export function installStdioParseErrorResponder(transport) {
155
169
  }
156
170
  };
157
171
  }
158
- //# sourceMappingURL=stdioGuards.js.map
@@ -55,4 +55,3 @@ export interface EngineLike {
55
55
  processThought: ProcessThought;
56
56
  close?: CloseFn;
57
57
  }
58
- //# sourceMappingURL=types.d.ts.map
package/dist/lib/types.js CHANGED
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=types.js.map
@@ -4,4 +4,3 @@ export declare const ThinkSeqInputSchema: z.ZodObject<{
4
4
  totalThoughts: z.ZodOptional<z.ZodNumber>;
5
5
  revisesThought: z.ZodOptional<z.ZodNumber>;
6
6
  }, z.core.$strict>;
7
- //# sourceMappingURL=inputs.d.ts.map
@@ -15,4 +15,3 @@ export const ThinkSeqInputSchema = z.strictObject({
15
15
  .optional()
16
16
  .describe('Revise a previous thought by number. The original is preserved for audit.'),
17
17
  });
18
- //# sourceMappingURL=inputs.js.map
@@ -29,4 +29,3 @@ export declare const ThinkSeqOutputSchema: z.ZodObject<{
29
29
  message: z.ZodString;
30
30
  }, z.core.$strip>>;
31
31
  }, z.core.$strict>;
32
- //# sourceMappingURL=outputs.d.ts.map
@@ -72,4 +72,3 @@ export const ThinkSeqOutputSchema = z
72
72
  });
73
73
  }
74
74
  });
75
- //# sourceMappingURL=outputs.js.map
@@ -5,4 +5,3 @@ interface ToolRegistrar {
5
5
  }
6
6
  export declare function registerThinkSeq(server: ToolRegistrar, engine: EngineLike): void;
7
7
  export {};
8
- //# sourceMappingURL=thinkseq.d.ts.map