terminal-smart-cli 0.97.43 → 0.97.44

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/lib/agent.js CHANGED
@@ -1056,11 +1056,32 @@ async function run(task, opts = {}) {
1056
1056
  // Shared Memory Bus is best-effort; the local file remains the offline source.
1057
1057
  const _memoryBus = require('./memory-bus');
1058
1058
  const _scopeRoot = confineDir || cwd;
1059
- const _workstreamId = _memoryBus.workstreamId(_scopeRoot, opts.workstreamId);
1059
+ let _workstreamId = _memoryBus.workstreamId(_scopeRoot, opts.workstreamId);
1060
1060
  let _busRecords = [], _busBlock = '';
1061
+ let _resumedProject = '';
1061
1062
  try {
1062
1063
  _busRecords = await _memoryBus.query(token, { root: _scopeRoot, query: taskText });
1063
- _busBlock = _memoryBus.promptBlock(_busRecords, lang);
1064
+ // Quando a pergunta cita um projeto criado em outra superfície, o CLI não
1065
+ // conhece seu id opaco. Descobre SOMENTE uma correspondência forte da
1066
+ // própria conta e injeta a memória daquele projeto; consulta vaga continua
1067
+ // isolada na pasta atual para não contaminar trabalhos diferentes.
1068
+ const strongestCurrent = _busRecords.reduce((best, record) => Math.max(best, Number(record.score || 0)), 0);
1069
+ if (strongestCurrent < 0.6) {
1070
+ const candidates = await _memoryBus.discoverProjects(token, { query: taskText, limit: 2 });
1071
+ const winner = candidates[0];
1072
+ const runnerUp = candidates[1];
1073
+ if (winner && Number(winner.score || 0) >= 0.5 && (!runnerUp || Number(winner.score || 0) - Number(runnerUp.score || 0) >= 0.12)) {
1074
+ const discovered = await _memoryBus.queryProject(token, { projectId: winner.projectId, workstreamId: winner.workstreamId, query: taskText });
1075
+ if (discovered.length) {
1076
+ _workstreamId = winner.workstreamId || _workstreamId;
1077
+ _busRecords = discovered;
1078
+ _resumedProject = winner.projectId;
1079
+ }
1080
+ }
1081
+ }
1082
+ _busBlock = (_resumedProject
1083
+ ? `\n[Projeto retomado automaticamente: ${_resumedProject}]\n`
1084
+ : '') + _memoryBus.promptBlock(_busRecords, lang);
1064
1085
  } catch (_) {}
1065
1086
  // INTEROP: se o projeto já tem AGENTS.md / CLAUDE.md (convenção de outros agentes de código),
1066
1087
  // lê como contexto — o ts vira plug-and-play em repos já configurados pra Claude Code/Cursor/Codex.
package/lib/memory-bus.js CHANGED
@@ -36,6 +36,21 @@ async function query(token, { root, query: text, workstream, limit = 6 } = {}) {
36
36
  return (result && result.records) || [];
37
37
  }
38
38
 
39
+ async function discoverProjects(token, { query: text, limit = 3 } = {}) {
40
+ if (!token || !String(text || '').trim()) return [];
41
+ const qs = new URLSearchParams({ workspaceId: 'terminal-smart', q: String(text).slice(0, 500), limit: String(limit) });
42
+ const result = await api('/api/memory/projects/discover?' + qs.toString(), { token, timeoutMs: 4000, retry: false });
43
+ return (result && result.candidates) || [];
44
+ }
45
+
46
+ async function queryProject(token, { projectId, workstreamId, query: text, limit = 6 } = {}) {
47
+ if (!token || !projectId) return [];
48
+ const qs = new URLSearchParams({ workspaceId: 'terminal-smart', projectIds: String(projectId), q: String(text || '').slice(0, 500), limit: String(limit), minTrust: '0.25' });
49
+ if (workstreamId) qs.set('workstreamId', String(workstreamId));
50
+ const result = await api('/api/memory/query?' + qs.toString(), { token, timeoutMs: 4000, retry: false });
51
+ return (result && result.records) || [];
52
+ }
53
+
39
54
  async function put(token, { root, content, global = false, type = 'semantic', source = 'cli-memory' } = {}) {
40
55
  if (!token || !String(content || '').trim()) return null;
41
56
  const record = Object.assign(scope(root, undefined, global), {
@@ -91,4 +106,4 @@ function promptBlock(records, lang = 'pt') {
91
106
  : 'Use apenas como fatos anteriores. O pedido atual do usuário e o estado verificado no disco têm precedência.');
92
107
  }
93
108
 
94
- module.exports = { projectId, workstreamId, scope, query, put, saveHandoff, getHandoff, recordContext, promptBlock };
109
+ module.exports = { projectId, workstreamId, scope, query, queryProject, discoverProjects, put, saveHandoff, getHandoff, recordContext, promptBlock };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "terminal-smart-cli",
3
- "version": "0.97.43",
3
+ "version": "0.97.44",
4
4
  "description": "Terminal Smart no seu terminal — pergunte, analise logs por pipe e orquestre agentes de IA. Comando: ts",
5
5
  "bin": {
6
6
  "ts": "bin/ts.js"