@polycode-projects/the-mechanical-code-talker 3.1.3 → 3.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polycode-projects/the-mechanical-code-talker",
3
- "version": "3.1.3",
3
+ "version": "3.2.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "The Mechanical Code Talker (tmct) — a tolerant, offline, $0 chat surface that guides you toward precision queries about a software repository. ELIZA/PARRY-style but domain-obsessed with code. No model calls; indexes a repo on request (tmct index) or reads any producer's graph.",
@@ -3,14 +3,23 @@
3
3
  //
4
4
  // A static `import "wink-nlp"` would drag the ~1 MB model into the base/viewer bundle.
5
5
  // Instead, `registerWinkModel` lets a browser/bundler entry hand in an already-imported
6
- // `{ winkNLP, model }` pair once; Node instead resolves lazily via `createRequire`.
6
+ // `{ winkNLP, model }` pair once; Node instead resolves lazily via `createRequire`,
7
+ // fetched at call time from `process.getBuiltinModule("node:module")` rather than a
8
+ // top-level `import { createRequire } from "node:module"`. A top-level import declares
9
+ // the `createRequire` binding in this module's own output, and a downstream consumer
10
+ // that bundles tmct alongside other CJS dependencies (esbuild, `--format=esm`) can
11
+ // inject its own auto-generated `createRequire` shim into the same bundle scope,
12
+ // producing a duplicate top-level declaration and a `SyntaxError` at Node module-parse
13
+ // time. Resolving it lazily via `process.getBuiltinModule` keeps the bundled output free
14
+ // of any top-level `createRequire` declaration, so there's nothing left to collide with.
15
+ // Don't "simplify" this back to a top-level import. `process.getBuiltinModule` needs
16
+ // Node 22.3.0/20.16.0+; this package's `engines.node` floor (">=24") already clears
17
+ // that, so lowering the floor later needs to keep clearing it too.
7
18
  //
8
19
  // The loader stays synchronous. Failure is cached as null — a checkout without the
9
20
  // optional deps, or a page that never registered a model, runs adapter-less rather
10
21
  // than throwing.
11
22
 
12
- import { createRequire } from "node:module";
13
-
14
23
  let injected; // browser/bundler-supplied `() => ({ winkNLP, model })`, or undefined
15
24
  let cached; // undefined = not tried yet; null = unavailable (tried once, honestly off)
16
25
 
@@ -40,7 +49,7 @@ function loadWinkModel() {
40
49
  /** Node fallback: resolve wink through the module system (never a guessed path).
41
50
  * CJS deps, so `createRequire`. */
42
51
  function nodeRequireWink() {
43
- const require = createRequire(import.meta.url);
52
+ const require = process.getBuiltinModule("node:module").createRequire(import.meta.url);
44
53
  return {
45
54
  winkNLP: require("wink-nlp"),
46
55
  model: require("wink-eng-lite-web-model"),
@@ -128,6 +128,12 @@ export async function createSession({
128
128
  // already-resolved value; full precedence (this param > TMCT_MEMORY_BACKEND
129
129
  // env > tmct.toml > the sqlite default) resolved below.
130
130
  memoryBackend = null,
131
+ // The tool-name prefix a host's own follow-up hints should use in place of
132
+ // "tmct_" (e.g. seonix's own tool names) — threaded onto `config` below so
133
+ // dispatchTool's handlers (kit.mjs/tmct-search.mjs/tmct-members.mjs/
134
+ // tmct-context.mjs) render hints under the host's own names. Omitted (the
135
+ // default) preserves today's "tmct_" behavior exactly.
136
+ toolNamePrefix,
131
137
  } = {}) {
132
138
  // EPHEMERAL mode (--ephemeral, or TMCT_EPHEMERAL=1): read the target graph but
133
139
  // write NOTHING back into it. The shipped examples run this way so a demo never
@@ -193,6 +199,10 @@ export async function createSession({
193
199
  ({ config, toml } = await resolveRuntimeConfig({ argv, cwd, env, gitRoot }));
194
200
  }
195
201
  }
202
+ // Every `config` branch above ends up here — set once so every downstream
203
+ // hint-rendering call site (dispatchTool's handlers, via config.toolNamePrefix)
204
+ // sees the same value regardless of which branch built `config`.
205
+ config.toolNamePrefix = toolNamePrefix || "tmct_";
196
206
 
197
207
  // Every game's tuning knobs (spider-fly's mass economy, guess-the-number's
198
208
  // bounds, the shared plan lane's search-depth cap), resolved once per
@@ -465,11 +475,12 @@ export async function runChat({
465
475
  narrate = false,
466
476
  liveReference = false,
467
477
  memoryBackend = null,
478
+ toolNamePrefix,
468
479
  } = {}) {
469
480
  // createSession's first-run seed (~2-3s) produces ZERO output until it fully
470
481
  // resolves, which otherwise reads as `npm run chat` hanging with total silence.
471
482
  output.write("tmct — starting…\n");
472
- const session = await createSession({ repoPath, graphPaths, configPath, source, env, cwd, gitRoot, ephemeral, narrate, liveReference, memoryBackend });
483
+ const session = await createSession({ repoPath, graphPaths, configPath, source, env, cwd, gitRoot, ephemeral, narrate, liveReference, memoryBackend, toolNamePrefix });
473
484
 
474
485
  const dim = (s) => (env.NO_COLOR || !output.isTTY ? s : `\x1b[2m${s}\x1b[0m`);
475
486
  for (const line of session.bannerLines) output.write(dim(line) + "\n");