@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.
- package/README.md +161 -71
- package/dist/app.d.ts +2 -36
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +13 -99
- package/dist/app.js.map +1 -1
- package/dist/appConfig/runDependencies.d.ts +36 -0
- package/dist/appConfig/runDependencies.d.ts.map +1 -0
- package/dist/appConfig/runDependencies.js +65 -0
- package/dist/appConfig/runDependencies.js.map +1 -0
- package/dist/appConfig/shutdown.d.ts +19 -0
- package/dist/appConfig/shutdown.d.ts.map +1 -0
- package/dist/appConfig/shutdown.js +65 -0
- package/dist/appConfig/shutdown.js.map +1 -0
- package/dist/appConfig/types.d.ts +10 -0
- package/dist/appConfig/types.d.ts.map +1 -0
- package/dist/appConfig/types.js +2 -0
- package/dist/appConfig/types.js.map +1 -0
- package/dist/appConfig.d.ts +5 -0
- package/dist/appConfig.d.ts.map +1 -0
- package/dist/appConfig.js +3 -0
- package/dist/appConfig.js.map +1 -0
- package/dist/engine/pruning.d.ts +3 -0
- package/dist/engine/pruning.d.ts.map +1 -0
- package/dist/engine/pruning.js +11 -0
- package/dist/engine/pruning.js.map +1 -0
- package/dist/engine/revision.d.ts +9 -0
- package/dist/engine/revision.d.ts.map +1 -0
- package/dist/engine/revision.js +38 -0
- package/dist/engine/revision.js.map +1 -0
- package/dist/engine/thoughtQueries.d.ts +3 -0
- package/dist/engine/thoughtQueries.d.ts.map +1 -0
- package/dist/engine/thoughtQueries.js +18 -0
- package/dist/engine/thoughtQueries.js.map +1 -0
- package/dist/engine/thoughtStore.d.ts +22 -0
- package/dist/engine/thoughtStore.d.ts.map +1 -0
- package/dist/engine/thoughtStore.js +151 -0
- package/dist/engine/thoughtStore.js.map +1 -0
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +64 -158
- package/dist/engine.js.map +1 -1
- package/dist/engineConfig.d.ts +11 -0
- package/dist/engineConfig.d.ts.map +1 -0
- package/dist/engineConfig.js +12 -0
- package/dist/engineConfig.js.map +1 -0
- package/dist/index.js +35 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/cli.d.ts +14 -0
- package/dist/lib/cli.d.ts.map +1 -0
- package/dist/lib/cli.js +71 -0
- package/dist/lib/cli.js.map +1 -0
- package/dist/lib/context.d.ts +7 -0
- package/dist/lib/context.d.ts.map +1 -0
- package/dist/lib/context.js +15 -0
- package/dist/lib/context.js.map +1 -0
- package/dist/lib/diagnostics.d.ts +9 -8
- package/dist/lib/diagnostics.d.ts.map +1 -1
- package/dist/lib/diagnostics.js +18 -8
- package/dist/lib/diagnostics.js.map +1 -1
- package/dist/lib/engineWorkerHandler.d.ts +12 -0
- package/dist/lib/engineWorkerHandler.d.ts.map +1 -0
- package/dist/lib/engineWorkerHandler.js +44 -0
- package/dist/lib/engineWorkerHandler.js.map +1 -0
- package/dist/lib/protocolGuards.d.ts.map +1 -1
- package/dist/lib/protocolGuards.js +8 -5
- package/dist/lib/protocolGuards.js.map +1 -1
- package/dist/lib/stdioGuards.d.ts.map +1 -1
- package/dist/lib/stdioGuards.js +23 -12
- package/dist/lib/stdioGuards.js.map +1 -1
- package/dist/lib/types.d.ts +13 -12
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/workerEngineClient.d.ts +23 -0
- package/dist/lib/workerEngineClient.d.ts.map +1 -0
- package/dist/lib/workerEngineClient.js +144 -0
- package/dist/lib/workerEngineClient.js.map +1 -0
- package/dist/lib/workerProtocol.d.ts +21 -0
- package/dist/lib/workerProtocol.d.ts.map +1 -0
- package/dist/lib/workerProtocol.js +22 -0
- package/dist/lib/workerProtocol.js.map +1 -0
- package/dist/schemas/inputs.d.ts +1 -13
- package/dist/schemas/inputs.d.ts.map +1 -1
- package/dist/schemas/inputs.js +5 -29
- package/dist/schemas/inputs.js.map +1 -1
- package/dist/schemas/outputs.d.ts +13 -16
- package/dist/schemas/outputs.d.ts.map +1 -1
- package/dist/schemas/outputs.js +46 -59
- package/dist/schemas/outputs.js.map +1 -1
- package/dist/tools/thinkseq.d.ts +7 -2
- package/dist/tools/thinkseq.d.ts.map +1 -1
- package/dist/tools/thinkseq.js +71 -59
- package/dist/tools/thinkseq.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/workers/engineWorker.d.ts +2 -0
- package/dist/workers/engineWorker.d.ts.map +1 -0
- package/dist/workers/engineWorker.js +15 -0
- package/dist/workers/engineWorker.js.map +1 -0
- package/package.json +8 -6
package/dist/engine.js
CHANGED
|
@@ -1,177 +1,83 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
}
|
|
1
|
+
import { resolveRevisionTarget } from './engine/revision.js';
|
|
2
|
+
import { buildContextSummary } from './engine/thoughtQueries.js';
|
|
3
|
+
import { ThoughtStore } from './engine/thoughtStore.js';
|
|
4
|
+
import { DEFAULT_MAX_THOUGHTS, ESTIMATED_THOUGHT_OVERHEAD_BYTES, MAX_MEMORY_BYTES, MAX_THOUGHTS_CAP, normalizeInt, } from './engineConfig.js';
|
|
11
5
|
export class ThinkingEngine {
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#branchIdsCache = [];
|
|
15
|
-
#branchIdsDirty = true;
|
|
16
|
-
#estimatedBytes = 0;
|
|
17
|
-
#revisionCount = 0;
|
|
18
|
-
#maxThoughts;
|
|
19
|
-
#maxMemoryBytes;
|
|
20
|
-
#estimatedThoughtOverheadBytes;
|
|
6
|
+
#store;
|
|
7
|
+
#hasRevisions = false;
|
|
21
8
|
constructor(options = {}) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
9
|
+
const maxThoughts = normalizeInt(options.maxThoughts, DEFAULT_MAX_THOUGHTS, { min: 1, max: MAX_THOUGHTS_CAP });
|
|
10
|
+
const maxMemoryBytes = normalizeInt(options.maxMemoryBytes, MAX_MEMORY_BYTES, { min: 1, max: Number.MAX_SAFE_INTEGER });
|
|
11
|
+
const estimatedThoughtOverheadBytes = normalizeInt(options.estimatedThoughtOverheadBytes, ESTIMATED_THOUGHT_OVERHEAD_BYTES, { min: 1, max: Number.MAX_SAFE_INTEGER });
|
|
12
|
+
this.#store = new ThoughtStore({
|
|
13
|
+
maxThoughts,
|
|
14
|
+
maxMemoryBytes,
|
|
15
|
+
estimatedThoughtOverheadBytes,
|
|
16
|
+
});
|
|
25
17
|
}
|
|
26
18
|
processThought(input) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
19
|
+
if (input.revisesThought !== undefined) {
|
|
20
|
+
return this.#processRevision(input);
|
|
21
|
+
}
|
|
22
|
+
return this.#processNewThought(input);
|
|
23
|
+
}
|
|
24
|
+
#processNewThought(input) {
|
|
25
|
+
const numbers = this.#store.nextThoughtNumbers(input.totalThoughts);
|
|
26
|
+
const stored = this.#buildStoredThought(input, numbers);
|
|
27
|
+
this.#store.storeThought(stored);
|
|
28
|
+
this.#store.pruneHistoryIfNeeded();
|
|
29
|
+
return this.#buildProcessResult(stored);
|
|
30
|
+
}
|
|
31
|
+
#processRevision(input) {
|
|
32
|
+
const resolved = resolveRevisionTarget(input, (thoughtNumber) => this.#store.getThoughtByNumber(thoughtNumber));
|
|
33
|
+
if (!resolved.ok)
|
|
34
|
+
return resolved.error;
|
|
35
|
+
const { targetNumber } = resolved;
|
|
36
|
+
const numbers = this.#store.nextThoughtNumbers(input.totalThoughts);
|
|
37
|
+
const supersedes = this.#store.supersedeFrom(targetNumber, numbers.thoughtNumber);
|
|
38
|
+
const stored = this.#buildStoredThought(input, {
|
|
39
|
+
...numbers,
|
|
40
|
+
revisionOf: targetNumber,
|
|
41
|
+
});
|
|
42
|
+
this.#store.storeThought(stored);
|
|
43
|
+
this.#hasRevisions = true;
|
|
44
|
+
this.#store.pruneHistoryIfNeeded();
|
|
45
|
+
return this.#buildProcessResult(stored, {
|
|
46
|
+
revises: targetNumber,
|
|
47
|
+
supersedes,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
#buildStoredThought(input, details) {
|
|
51
|
+
return {
|
|
31
52
|
...input,
|
|
32
|
-
|
|
53
|
+
thoughtNumber: details.thoughtNumber,
|
|
54
|
+
totalThoughts: details.totalThoughts,
|
|
33
55
|
timestamp: Date.now(),
|
|
56
|
+
isActive: true,
|
|
57
|
+
...(details.revisionOf !== undefined && {
|
|
58
|
+
revisionOf: details.revisionOf,
|
|
59
|
+
}),
|
|
34
60
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (branch)
|
|
42
|
-
branch.push(stored);
|
|
43
|
-
else {
|
|
44
|
-
this.#branches.set(stored.branchId, [stored]);
|
|
45
|
-
this.#branchIdsDirty = true;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
this.#pruneHistoryIfNeeded();
|
|
49
|
-
const context = this.#buildContextSummary();
|
|
61
|
+
}
|
|
62
|
+
#buildProcessResult(stored, revisionInfo) {
|
|
63
|
+
const activeThoughts = this.#store.getActiveThoughts();
|
|
64
|
+
const context = buildContextSummary(activeThoughts, revisionInfo);
|
|
65
|
+
const isComplete = stored.thoughtNumber >= stored.totalThoughts;
|
|
66
|
+
const revisableThoughts = this.#store.getActiveThoughtNumbers().slice();
|
|
50
67
|
return {
|
|
51
68
|
ok: true,
|
|
52
69
|
result: {
|
|
53
70
|
thoughtNumber: stored.thoughtNumber,
|
|
54
71
|
totalThoughts: stored.totalThoughts,
|
|
55
72
|
progress: Math.min(1, stored.thoughtNumber / stored.totalThoughts),
|
|
56
|
-
|
|
57
|
-
thoughtHistoryLength: this.#
|
|
58
|
-
|
|
73
|
+
isComplete,
|
|
74
|
+
thoughtHistoryLength: this.#store.getTotalLength(),
|
|
75
|
+
hasRevisions: this.#hasRevisions,
|
|
76
|
+
activePathLength: activeThoughts.length,
|
|
77
|
+
revisableThoughts,
|
|
59
78
|
context,
|
|
60
79
|
},
|
|
61
80
|
};
|
|
62
81
|
}
|
|
63
|
-
#getBranchIds() {
|
|
64
|
-
if (this.#branchIdsDirty) {
|
|
65
|
-
this.#branchIdsCache = Array.from(this.#branches.keys());
|
|
66
|
-
this.#branchIdsDirty = false;
|
|
67
|
-
}
|
|
68
|
-
return this.#branchIdsCache;
|
|
69
|
-
}
|
|
70
|
-
#buildContextSummary() {
|
|
71
|
-
const recent = this.#thoughts.slice(-5);
|
|
72
|
-
const currentBranch = this.#thoughts.at(-1)?.branchId;
|
|
73
|
-
return {
|
|
74
|
-
recentThoughts: recent.map((t) => {
|
|
75
|
-
const base = {
|
|
76
|
-
number: t.thoughtNumber,
|
|
77
|
-
preview: t.thought.slice(0, 100) + (t.thought.length > 100 ? '...' : ''),
|
|
78
|
-
};
|
|
79
|
-
return t.thoughtType ? { ...base, type: t.thoughtType } : base;
|
|
80
|
-
}),
|
|
81
|
-
...(currentBranch !== undefined ? { currentBranch } : {}),
|
|
82
|
-
hasRevisions: this.#revisionCount > 0,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
#validateThoughtNumber(input) {
|
|
86
|
-
const lastThought = this.#thoughts.at(-1);
|
|
87
|
-
if (!lastThought) {
|
|
88
|
-
this.#ensureFirstThought(input.thoughtNumber);
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
if (this.#isRevisionOrBranch(input))
|
|
92
|
-
return;
|
|
93
|
-
this.#warnOnSequenceGap(lastThought, input.thoughtNumber);
|
|
94
|
-
}
|
|
95
|
-
#ensureFirstThought(thoughtNumber) {
|
|
96
|
-
if (thoughtNumber === 1)
|
|
97
|
-
return;
|
|
98
|
-
throw new Error(`First thought must be number 1, got ${String(thoughtNumber)}`);
|
|
99
|
-
}
|
|
100
|
-
#isRevisionOrBranch(input) {
|
|
101
|
-
return input.isRevision === true || input.branchFromThought !== undefined;
|
|
102
|
-
}
|
|
103
|
-
#warnOnSequenceGap(lastThought, thoughtNumber) {
|
|
104
|
-
if (thoughtNumber === lastThought.thoughtNumber + 1)
|
|
105
|
-
return;
|
|
106
|
-
publishEngineEvent({
|
|
107
|
-
type: 'engine.sequence_gap',
|
|
108
|
-
ts: Date.now(),
|
|
109
|
-
expected: lastThought.thoughtNumber + 1,
|
|
110
|
-
received: thoughtNumber,
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
#validateReferences(input) {
|
|
114
|
-
const maxThoughtNumber = this.#thoughts.at(-1)?.thoughtNumber ?? 0;
|
|
115
|
-
this.#assertValidReference('revisesThought', input.revisesThought, maxThoughtNumber);
|
|
116
|
-
this.#assertValidReference('branchFromThought', input.branchFromThought, maxThoughtNumber);
|
|
117
|
-
}
|
|
118
|
-
#assertValidReference(field, value, max) {
|
|
119
|
-
if (value === undefined || value <= max)
|
|
120
|
-
return;
|
|
121
|
-
throw new Error(`${field} ${String(value)} references non-existent thought (max: ${String(max)})`);
|
|
122
|
-
}
|
|
123
|
-
#pruneHistoryIfNeeded() {
|
|
124
|
-
const excess = this.#thoughts.length - this.#maxThoughts;
|
|
125
|
-
if (excess > 0) {
|
|
126
|
-
const batch = Math.max(excess, Math.ceil(this.#maxThoughts * 0.1));
|
|
127
|
-
this.#removeOldest(batch);
|
|
128
|
-
}
|
|
129
|
-
if (this.#estimatedBytes > this.#maxMemoryBytes &&
|
|
130
|
-
this.#thoughts.length > 10) {
|
|
131
|
-
const toRemove = Math.ceil(this.#thoughts.length * 0.2);
|
|
132
|
-
this.#removeOldest(toRemove);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
#estimateThoughtBytes(thought) {
|
|
136
|
-
return thought.thought.length * 2 + this.#estimatedThoughtOverheadBytes;
|
|
137
|
-
}
|
|
138
|
-
#removeOldest(count) {
|
|
139
|
-
if (count <= 0 || this.#thoughts.length === 0)
|
|
140
|
-
return;
|
|
141
|
-
const actual = Math.min(count, this.#thoughts.length);
|
|
142
|
-
const removed = this.#thoughts.splice(0, actual);
|
|
143
|
-
if (removed.length === 0)
|
|
144
|
-
return;
|
|
145
|
-
this.#applyRemoval(removed);
|
|
146
|
-
}
|
|
147
|
-
#applyRemoval(removed) {
|
|
148
|
-
const branchRemovals = this.#collectBranchRemovals(removed);
|
|
149
|
-
for (const [branchId, removeCount] of branchRemovals) {
|
|
150
|
-
this.#trimBranch(branchId, removeCount);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
#collectBranchRemovals(removed) {
|
|
154
|
-
const branchRemovals = new Map();
|
|
155
|
-
for (const thought of removed) {
|
|
156
|
-
this.#estimatedBytes -= this.#estimateThoughtBytes(thought);
|
|
157
|
-
if (thought.isRevision)
|
|
158
|
-
this.#revisionCount -= 1;
|
|
159
|
-
if (!thought.branchId)
|
|
160
|
-
continue;
|
|
161
|
-
branchRemovals.set(thought.branchId, (branchRemovals.get(thought.branchId) ?? 0) + 1);
|
|
162
|
-
}
|
|
163
|
-
return branchRemovals;
|
|
164
|
-
}
|
|
165
|
-
#trimBranch(branchId, removeCount) {
|
|
166
|
-
const branch = this.#branches.get(branchId);
|
|
167
|
-
if (!branch)
|
|
168
|
-
return;
|
|
169
|
-
if (removeCount >= branch.length) {
|
|
170
|
-
this.#branches.delete(branchId);
|
|
171
|
-
this.#branchIdsDirty = true;
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
branch.splice(0, removeCount);
|
|
175
|
-
}
|
|
176
82
|
}
|
|
177
83
|
//# sourceMappingURL=engine.js.map
|
package/dist/engine.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file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
|
+
export declare const MAX_MEMORY_BYTES: number;
|
|
4
|
+
export declare const ESTIMATED_THOUGHT_OVERHEAD_BYTES = 200;
|
|
5
|
+
export declare const COMPACT_THRESHOLD = 1024;
|
|
6
|
+
export declare const COMPACT_RATIO = 0.5;
|
|
7
|
+
export declare function normalizeInt(value: number | undefined, fallback: number, options: {
|
|
8
|
+
min: number;
|
|
9
|
+
max: number;
|
|
10
|
+
}): number;
|
|
11
|
+
//# sourceMappingURL=engineConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engineConfig.d.ts","sourceRoot":"","sources":["../src/engineConfig.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,MAAM,CAAC;AACxC,eAAO,MAAM,gBAAgB,QAAQ,CAAC;AACtC,eAAO,MAAM,gBAAgB,QAAoB,CAAC;AAClD,eAAO,MAAM,gCAAgC,MAAM,CAAC;AACpD,eAAO,MAAM,iBAAiB,OAAO,CAAC;AACtC,eAAO,MAAM,aAAa,MAAM,CAAC;AAEjC,wBAAgB,YAAY,CAC1B,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GACpC,MAAM,CAGR"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const DEFAULT_MAX_THOUGHTS = 500;
|
|
2
|
+
export const MAX_THOUGHTS_CAP = 10000;
|
|
3
|
+
export const MAX_MEMORY_BYTES = 100 * 1024 * 1024;
|
|
4
|
+
export const ESTIMATED_THOUGHT_OVERHEAD_BYTES = 200;
|
|
5
|
+
export const COMPACT_THRESHOLD = 1024;
|
|
6
|
+
export const COMPACT_RATIO = 0.5;
|
|
7
|
+
export function normalizeInt(value, fallback, options) {
|
|
8
|
+
if (typeof value !== 'number' || !Number.isFinite(value))
|
|
9
|
+
return fallback;
|
|
10
|
+
return Math.max(options.min, Math.min(options.max, Math.trunc(value)));
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=engineConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engineConfig.js","sourceRoot":"","sources":["../src/engineConfig.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,CAAC;AACxC,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAC;AACtC,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;AAClD,MAAM,CAAC,MAAM,gCAAgC,GAAG,GAAG,CAAC;AACpD,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC;AACtC,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,CAAC;AAEjC,MAAM,UAAU,YAAY,CAC1B,KAAyB,EACzB,QAAgB,EAChB,OAAqC;IAErC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,QAAQ,CAAC;IAC1E,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACzE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,42 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { installProcessErrorHandlers, run } from './app.js';
|
|
3
|
+
import { ThinkingEngine } from './engine.js';
|
|
4
|
+
import { getCliHelpText, parseCliConfig } from './lib/cli.js';
|
|
3
5
|
installProcessErrorHandlers();
|
|
4
|
-
|
|
6
|
+
const fatal = (err) => {
|
|
5
7
|
const message = err instanceof Error ? err.message : String(err);
|
|
6
8
|
console.error(`thinkseq: fatal: ${message}`);
|
|
7
9
|
process.exit(1);
|
|
8
|
-
}
|
|
10
|
+
};
|
|
11
|
+
const printHelpAndExit = () => {
|
|
12
|
+
console.log(getCliHelpText());
|
|
13
|
+
process.exit(0);
|
|
14
|
+
};
|
|
15
|
+
const buildEngineOptions = (config) => {
|
|
16
|
+
const options = {};
|
|
17
|
+
if (config.maxThoughts !== undefined)
|
|
18
|
+
options.maxThoughts = config.maxThoughts;
|
|
19
|
+
if (config.maxMemoryBytes !== undefined)
|
|
20
|
+
options.maxMemoryBytes = config.maxMemoryBytes;
|
|
21
|
+
return options;
|
|
22
|
+
};
|
|
23
|
+
const buildRunDependencies = (config) => {
|
|
24
|
+
const engineOptions = buildEngineOptions(config);
|
|
25
|
+
return {
|
|
26
|
+
...(config.packageReadTimeoutMs !== undefined && {
|
|
27
|
+
packageReadTimeoutMs: config.packageReadTimeoutMs,
|
|
28
|
+
}),
|
|
29
|
+
...(config.shutdownTimeoutMs !== undefined && {
|
|
30
|
+
shutdownTimeoutMs: config.shutdownTimeoutMs,
|
|
31
|
+
}),
|
|
32
|
+
engineFactory: () => new ThinkingEngine(engineOptions),
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
const runCli = async () => {
|
|
36
|
+
const { config, help } = parseCliConfig();
|
|
37
|
+
if (help)
|
|
38
|
+
printHelpAndExit();
|
|
39
|
+
await run(buildRunDependencies(config));
|
|
40
|
+
};
|
|
41
|
+
void runCli().catch(fatal);
|
|
9
42
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,2BAA2B,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE5D,OAAO,EAAE,cAAc,EAAE,M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5C,CAAC;QACF,aAAa,EAAE,GAAG,EAAE,CAAC,IAAI,cAAc,CAAC,aAAa,CAAC;KACvD,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,KAAK,IAAmB,EAAE;IACvC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,cAAc,EAAE,CAAC;IAC1C,IAAI,IAAI;QAAE,gBAAgB,EAAE,CAAC;IAC7B,MAAM,GAAG,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC;AAC1C,CAAC,CAAC;AAEF,KAAK,MAAM,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
interface CliConfig {
|
|
2
|
+
maxThoughts?: number;
|
|
3
|
+
maxMemoryBytes?: number;
|
|
4
|
+
shutdownTimeoutMs?: number;
|
|
5
|
+
packageReadTimeoutMs?: number;
|
|
6
|
+
}
|
|
7
|
+
export interface CliParseResult {
|
|
8
|
+
config: CliConfig;
|
|
9
|
+
help: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function getCliHelpText(): string;
|
|
12
|
+
export declare function parseCliConfig(args?: readonly string[]): CliParseResult;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/lib/cli.ts"],"names":[],"mappings":"AAEA,UAAU,SAAS;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,SAAS,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC;CACf;AAuFD,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED,wBAAgB,cAAc,CAAC,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,cAAc,CAMvE"}
|
package/dist/lib/cli.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { parseArgs } from 'node:util';
|
|
2
|
+
const PARSE_CONFIG = {
|
|
3
|
+
options: {
|
|
4
|
+
'max-thoughts': { type: 'string' },
|
|
5
|
+
'max-memory-mb': { type: 'string' },
|
|
6
|
+
'shutdown-timeout-ms': { type: 'string' },
|
|
7
|
+
'package-read-timeout-ms': { type: 'string' },
|
|
8
|
+
help: { type: 'boolean', short: 'h' },
|
|
9
|
+
},
|
|
10
|
+
strict: true,
|
|
11
|
+
allowPositionals: false,
|
|
12
|
+
allowNegative: false,
|
|
13
|
+
};
|
|
14
|
+
const HELP_TEXT = `Usage: thinkseq [options]
|
|
15
|
+
|
|
16
|
+
Options:
|
|
17
|
+
--max-thoughts <number> Max thoughts to keep in memory
|
|
18
|
+
--max-memory-mb <number> Max memory (MB) for stored thoughts
|
|
19
|
+
--shutdown-timeout-ms <number> Graceful shutdown timeout
|
|
20
|
+
--package-read-timeout-ms <number> Package.json read timeout
|
|
21
|
+
-h, --help Show this help`;
|
|
22
|
+
const BYTES_PER_MB = 1024 * 1024;
|
|
23
|
+
function parsePositiveInt(value, label) {
|
|
24
|
+
if (value === undefined)
|
|
25
|
+
return undefined;
|
|
26
|
+
const parsed = Number.parseInt(value, 10);
|
|
27
|
+
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
28
|
+
throw new Error(`Invalid ${label}: ${value}`);
|
|
29
|
+
}
|
|
30
|
+
return parsed;
|
|
31
|
+
}
|
|
32
|
+
function getParsedValues(args) {
|
|
33
|
+
if (args) {
|
|
34
|
+
return parseArgs({ ...PARSE_CONFIG, args }).values;
|
|
35
|
+
}
|
|
36
|
+
return parseArgs(PARSE_CONFIG).values;
|
|
37
|
+
}
|
|
38
|
+
function getStringOption(values, key) {
|
|
39
|
+
const value = values[key];
|
|
40
|
+
return typeof value === 'string' ? value : undefined;
|
|
41
|
+
}
|
|
42
|
+
function buildCliConfig(values) {
|
|
43
|
+
const maxThoughts = parsePositiveInt(getStringOption(values, 'max-thoughts'), 'max-thoughts');
|
|
44
|
+
const maxMemoryMb = parsePositiveInt(getStringOption(values, 'max-memory-mb'), 'max-memory-mb');
|
|
45
|
+
const shutdownTimeoutMs = parsePositiveInt(getStringOption(values, 'shutdown-timeout-ms'), 'shutdown-timeout-ms');
|
|
46
|
+
const packageReadTimeoutMs = parsePositiveInt(getStringOption(values, 'package-read-timeout-ms'), 'package-read-timeout-ms');
|
|
47
|
+
const config = {};
|
|
48
|
+
if (maxThoughts !== undefined)
|
|
49
|
+
config.maxThoughts = maxThoughts;
|
|
50
|
+
if (maxMemoryMb !== undefined) {
|
|
51
|
+
config.maxMemoryBytes = maxMemoryMb * BYTES_PER_MB;
|
|
52
|
+
}
|
|
53
|
+
if (shutdownTimeoutMs !== undefined) {
|
|
54
|
+
config.shutdownTimeoutMs = shutdownTimeoutMs;
|
|
55
|
+
}
|
|
56
|
+
if (packageReadTimeoutMs !== undefined) {
|
|
57
|
+
config.packageReadTimeoutMs = packageReadTimeoutMs;
|
|
58
|
+
}
|
|
59
|
+
return config;
|
|
60
|
+
}
|
|
61
|
+
export function getCliHelpText() {
|
|
62
|
+
return HELP_TEXT;
|
|
63
|
+
}
|
|
64
|
+
export function parseCliConfig(args) {
|
|
65
|
+
const values = getParsedValues(args);
|
|
66
|
+
return {
|
|
67
|
+
help: values.help === true,
|
|
68
|
+
config: buildCliConfig(values),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/lib/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAwB,MAAM,WAAW,CAAC;AAc5D,MAAM,YAAY,GAAG;IACnB,OAAO,EAAE;QACP,cAAc,EAAE,EAAE,IAA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
|
+
export interface RequestContext {
|
|
2
|
+
requestId: string;
|
|
3
|
+
startedAt: number;
|
|
4
|
+
}
|
|
5
|
+
export declare function runWithContext<T>(callback: () => T, context?: Partial<RequestContext>): T;
|
|
6
|
+
export declare function getRequestContext(): RequestContext | undefined;
|
|
7
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/lib/context.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAID,wBAAgB,cAAc,CAAC,CAAC,EAC9B,QAAQ,EAAE,MAAM,CAAC,EACjB,OAAO,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,GAChC,CAAC,CAMH;AAED,wBAAgB,iBAAiB,IAAI,cAAc,GAAG,SAAS,CAE9D"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { performance } from 'node:perf_hooks';
|
|
4
|
+
const storage = new AsyncLocalStorage();
|
|
5
|
+
export function runWithContext(callback, context) {
|
|
6
|
+
const store = {
|
|
7
|
+
requestId: context?.requestId ?? randomUUID(),
|
|
8
|
+
startedAt: context?.startedAt ?? performance.now(),
|
|
9
|
+
};
|
|
10
|
+
return storage.run(store, callback);
|
|
11
|
+
}
|
|
12
|
+
export function getRequestContext() {
|
|
13
|
+
return storage.getStore();
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/lib/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAO9C,MAAM,OAAO,GAAG,IAAI,iBAAiB,EAAkB,CAAC;AAExD,MAAM,UAAU,cAAc,CAC5B,QAAiB,EACjB,OAAiC;IAEjC,MAAM,KAAK,GAAmB;QAC5B,SAAS,EAAE,OAAO,EAAE,SAAS,IAAI,UAAU,EAAE;QAC7C,SAAS,EAAE,OAAO,EAAE,SAAS,IAAI,WAAW,CAAC,GAAG,EAAE;KACnD,CAAC;IACF,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,OAAO,OAAO,CAAC,QAAQ,EAAE,CAAC;AAC5B,CAAC"}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
interface EventContext {
|
|
2
|
+
requestId: string;
|
|
3
|
+
startedAt: number;
|
|
4
|
+
}
|
|
5
|
+
type ToolEventBase = {
|
|
2
6
|
type: 'tool.start';
|
|
3
7
|
tool: 'thinkseq';
|
|
4
8
|
ts: number;
|
|
@@ -17,6 +21,9 @@ export type ToolEvent = {
|
|
|
17
21
|
errorMessage: string;
|
|
18
22
|
durationMs?: number;
|
|
19
23
|
};
|
|
24
|
+
export type ToolEvent = ToolEventBase & {
|
|
25
|
+
context?: EventContext;
|
|
26
|
+
};
|
|
20
27
|
export type LifecycleEvent = {
|
|
21
28
|
type: 'lifecycle.started';
|
|
22
29
|
ts: number;
|
|
@@ -25,13 +32,7 @@ export type LifecycleEvent = {
|
|
|
25
32
|
ts: number;
|
|
26
33
|
signal: string;
|
|
27
34
|
};
|
|
28
|
-
export interface EngineEvent {
|
|
29
|
-
type: 'engine.sequence_gap';
|
|
30
|
-
ts: number;
|
|
31
|
-
expected: number;
|
|
32
|
-
received: number;
|
|
33
|
-
}
|
|
34
35
|
export declare function publishToolEvent(event: ToolEvent): void;
|
|
35
36
|
export declare function publishLifecycleEvent(event: LifecycleEvent): void;
|
|
36
|
-
export
|
|
37
|
+
export {};
|
|
37
38
|
//# sourceMappingURL=diagnostics.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../../src/lib/diagnostics.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../../src/lib/diagnostics.ts"],"names":[],"mappings":"AAIA,UAAU,YAAY;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,KAAK,aAAa,GACd;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,SAAS,GAAG,aAAa,GAAG;IAAE,OAAO,CAAC,EAAE,YAAY,CAAA;CAAE,CAAC;AAEnE,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;AA8B/D,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAEvD;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI,CAEjE"}
|
package/dist/lib/diagnostics.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
1
|
+
import diagnosticsChannel from 'node:diagnostics_channel';
|
|
2
|
+
import { getRequestContext } from './context.js';
|
|
3
|
+
const toolChannel = diagnosticsChannel.channel('thinkseq:tool');
|
|
4
|
+
const lifecycleChannel = diagnosticsChannel.channel('thinkseq:lifecycle');
|
|
5
5
|
function safePublish(channel, message) {
|
|
6
6
|
if (!channel.hasSubscribers)
|
|
7
7
|
return;
|
|
@@ -12,13 +12,23 @@ function safePublish(channel, message) {
|
|
|
12
12
|
// Intentional suppression of publication errors
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
+
function attachContext(event) {
|
|
16
|
+
const context = getRequestContext();
|
|
17
|
+
if (!context)
|
|
18
|
+
return event;
|
|
19
|
+
return {
|
|
20
|
+
...event,
|
|
21
|
+
context: {
|
|
22
|
+
...event.context,
|
|
23
|
+
requestId: context.requestId,
|
|
24
|
+
startedAt: context.startedAt,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
15
28
|
export function publishToolEvent(event) {
|
|
16
|
-
safePublish(toolChannel, event);
|
|
29
|
+
safePublish(toolChannel, attachContext(event));
|
|
17
30
|
}
|
|
18
31
|
export function publishLifecycleEvent(event) {
|
|
19
32
|
safePublish(lifecycleChannel, event);
|
|
20
33
|
}
|
|
21
|
-
export function publishEngineEvent(event) {
|
|
22
|
-
safePublish(engineChannel, event);
|
|
23
|
-
}
|
|
24
34
|
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../../src/lib/diagnostics.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../../src/lib/diagnostics.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAoCjD,MAAM,WAAW,GAAG,kBAAkB,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;AAChE,MAAM,gBAAgB,GAAG,kBAAkB,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAE1E,SAAS,WAAW,CAClB,OAAmC,EACnC,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,SAAS,aAAa,CAAuC,KAAQ;IACnE,MAAM,OAAO,GAAG,iBAAiB,EAAE,CAAC;IACpC,IAAI,CAAC,OAAO;QAAE,OAAO,KAAK,CAAC;IAC3B,OAAO;QACL,GAAG,KAAK;QACR,OAAO,EAAE;YACP,GAAG,KAAK,CAAC,OAAO;YAChB,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,SAAS,EAAE,OAAO,CAAC,SAAS;SAC7B;KACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAgB;IAC/C,WAAW,CAAC,WAAW,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,KAAqB;IACzD,WAAW,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ProcessResult, ThoughtData } from './types.js';
|
|
2
|
+
import type { EngineWorkerResponse } from './workerProtocol.js';
|
|
3
|
+
interface EngineProcessor {
|
|
4
|
+
processThought: (input: ThoughtData) => ProcessResult;
|
|
5
|
+
}
|
|
6
|
+
interface WorkerHandlerDeps {
|
|
7
|
+
engine: EngineProcessor;
|
|
8
|
+
post: (message: EngineWorkerResponse) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare function handleEngineWorkerMessage(raw: unknown, deps: WorkerHandlerDeps): void;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=engineWorkerHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engineWorkerHandler.d.ts","sourceRoot":"","sources":["../../src/lib/engineWorkerHandler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,KAAK,EAEV,oBAAoB,EACrB,MAAM,qBAAqB,CAAC;AAG7B,UAAU,eAAe;IACvB,cAAc,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,aAAa,CAAC;CACvD;AAED,UAAU,iBAAiB;IACzB,MAAM,EAAE,eAAe,CAAC;IACxB,IAAI,EAAE,CAAC,OAAO,EAAE,oBAAoB,KAAK,IAAI,CAAC;CAC/C;AAmCD,wBAAgB,yBAAyB,CACvC,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,iBAAiB,GACtB,IAAI,CAcN"}
|