@polycode-projects/the-mechanical-code-talker 6.0.9 → 6.0.10
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/bin/tmct.mjs +18 -1
- package/package.json +1 -1
- package/src/services/corpus-loader.mjs +24 -1
package/bin/tmct.mjs
CHANGED
|
@@ -669,6 +669,20 @@ async function refuseMissingRepoPath(argv) {
|
|
|
669
669
|
process.exit(2);
|
|
670
670
|
}
|
|
671
671
|
|
|
672
|
+
/** One `tmct corpus load` progress line for `corpus-loader.mjs`'s
|
|
673
|
+
* `onProgress({loaded, total, elapsedMs})` — a load against millions of
|
|
674
|
+
* rows can run for an hour or more, so this is the only sign of life on
|
|
675
|
+
* the terminal until it finishes. The rate is the average since the load
|
|
676
|
+
* started, not since the last tick, which is steadier once a run has been
|
|
677
|
+
* going for a while. */
|
|
678
|
+
function corpusLoadProgressLine(band, { loaded, total, elapsedMs }) {
|
|
679
|
+
const pct = total > 0 ? Math.floor((loaded / total) * 100) : 100;
|
|
680
|
+
const elapsedSeconds = elapsedMs / 1000;
|
|
681
|
+
const rowsPerSecond = elapsedSeconds > 0 ? loaded / elapsedSeconds : 0;
|
|
682
|
+
const minutesLeft = rowsPerSecond > 0 ? Math.round((total - loaded) / rowsPerSecond / 60) : 0;
|
|
683
|
+
return `corpus load ${band}: ${loaded}/${total} rows (${pct}%) — ${Math.round(rowsPerSecond)} rows/s, ~${minutesLeft} min left\n`;
|
|
684
|
+
}
|
|
685
|
+
|
|
672
686
|
async function main() {
|
|
673
687
|
const mode = process.argv[2];
|
|
674
688
|
if (mode !== "init") await refuseMissingRepoPath(process.argv.slice(3));
|
|
@@ -1870,7 +1884,10 @@ async function main() {
|
|
|
1870
1884
|
return;
|
|
1871
1885
|
}
|
|
1872
1886
|
const { loadBand } = await import("../src/services/corpus-loader.mjs");
|
|
1873
|
-
const result = await loadBand({
|
|
1887
|
+
const result = await loadBand({
|
|
1888
|
+
client, tableName, band, source, dryRun: rest.includes("--dry-run"),
|
|
1889
|
+
onProgress: (progress) => process.stderr.write(corpusLoadProgressLine(band, progress)),
|
|
1890
|
+
});
|
|
1874
1891
|
const verb = { unchanged: "unchanged", loaded: "loaded", "dry-run": "would load" }[result.status];
|
|
1875
1892
|
process.stdout.write(`tmct corpus load ${band}: ${verb} (${result.rowCount} row(s), source digest ${result.sourceDigest})\n`);
|
|
1876
1893
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polycode-projects/the-mechanical-code-talker",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.10",
|
|
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.",
|
|
@@ -47,6 +47,11 @@ const DEFAULT_WRITE_CONCURRENCY = 25;
|
|
|
47
47
|
const DEFAULT_RETRY_ATTEMPTS = 5;
|
|
48
48
|
const RETRY_BASE_DELAY_MS = 100;
|
|
49
49
|
|
|
50
|
+
// A load against millions of rows can run for an hour or more with nothing
|
|
51
|
+
// on the terminal to show it's alive, so `loadBand` reports progress on a
|
|
52
|
+
// timer rather than leaving the operator staring at a silent shell.
|
|
53
|
+
const DEFAULT_PROGRESS_INTERVAL_MS = 60_000;
|
|
54
|
+
|
|
50
55
|
const defaultSleep = (ms) => new Promise((resolve) => { setTimeout(resolve, ms); });
|
|
51
56
|
const defaultRandom = () => Math.random();
|
|
52
57
|
|
|
@@ -178,10 +183,18 @@ async function queryWholePartition({ client, tableName, band, retry }) {
|
|
|
178
183
|
* `{status: "unchanged" | "loaded" | "dry-run", band, rowCount, sourceDigest}`.
|
|
179
184
|
* `dryRun` computes the digest and reports what would happen without
|
|
180
185
|
* writing anything. `retryAttempts`/`retryBaseDelayMs`/`sleep`/`random` tune
|
|
181
|
-
* the retry policy every store call below shares; see `retryPolicyFrom`.
|
|
186
|
+
* the retry policy every store call below shares; see `retryPolicyFrom`.
|
|
187
|
+
* `onProgress({loaded, total, elapsedMs})` fires at most once per
|
|
188
|
+
* `progressIntervalMs` while rows are being written, plus once more when the
|
|
189
|
+
* write finishes. It defaults to a no-op, so a caller that doesn't pass it
|
|
190
|
+
* sees no behavior change. `progressNow` is the clock the interval is
|
|
191
|
+
* measured against (default `Date.now`), injectable the same way
|
|
192
|
+
* `sleep`/`random` are, so a test can drive it deterministically instead of
|
|
193
|
+
* racing real time. */
|
|
182
194
|
export async function loadBand({
|
|
183
195
|
client, tableName, band, source, dryRun = false,
|
|
184
196
|
writeConcurrency = DEFAULT_WRITE_CONCURRENCY, now = () => new Date().toISOString(),
|
|
197
|
+
onProgress = () => {}, progressIntervalMs = DEFAULT_PROGRESS_INTERVAL_MS, progressNow = () => Date.now(),
|
|
185
198
|
retryAttempts, retryBaseDelayMs, sleep, random,
|
|
186
199
|
}) {
|
|
187
200
|
if (!client) throw new TypeError("loadBand needs a client");
|
|
@@ -204,13 +217,23 @@ export async function loadBand({
|
|
|
204
217
|
const rows = [];
|
|
205
218
|
for await (const row of readWireRows(source)) rows.push(row);
|
|
206
219
|
rowCount = rows.length;
|
|
220
|
+
const startedAtMs = progressNow();
|
|
221
|
+
let lastReportedAtMs = startedAtMs;
|
|
222
|
+
let loaded = 0;
|
|
207
223
|
await mapWithConcurrency(rows, writeConcurrency, async (row) => {
|
|
208
224
|
const item = {
|
|
209
225
|
pk, sk: bandSortKeyForRow(row.rowClass, row.term, row.rowKey),
|
|
210
226
|
rowKey: row.rowKey, rowClass: row.rowClass, term: row.term, json: row.json,
|
|
211
227
|
};
|
|
212
228
|
await call(() => client.put({ TableName: tableName, Item: item }), "put", retry);
|
|
229
|
+
loaded += 1;
|
|
230
|
+
const tickMs = progressNow();
|
|
231
|
+
if (tickMs - lastReportedAtMs >= progressIntervalMs) {
|
|
232
|
+
lastReportedAtMs = tickMs;
|
|
233
|
+
onProgress({ loaded, total: rowCount, elapsedMs: tickMs - startedAtMs });
|
|
234
|
+
}
|
|
213
235
|
});
|
|
236
|
+
onProgress({ loaded: rowCount, total: rowCount, elapsedMs: progressNow() - startedAtMs });
|
|
214
237
|
const manifest = buildBandManifest({
|
|
215
238
|
band, rowCount, loadedAt: now(), sourceDigest, license, notice,
|
|
216
239
|
});
|