agent-mp 0.3.9 → 0.4.1

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.
@@ -40,6 +40,14 @@ export declare class AgentEngine {
40
40
  runReviewer(taskId: string, plan: TaskPlan, progress: TaskProgress): Promise<{
41
41
  verdict: string;
42
42
  }>;
43
+ /**
44
+ * Scan contextDir for stray files (outside the allowed structure) and clean them up:
45
+ * - Old timestamped explorer-*.md reports → delete (content already in architecture.md)
46
+ * - Other stray .md files at root level → append content to architecture.md, then delete
47
+ * Allowed root-level files: architecture.md, explorer-last.md
48
+ * Allowed subdirectory files: <service>/architecture.md (not touched here)
49
+ */
50
+ private _cleanContextDir;
43
51
  runExplorer(task?: string): Promise<string>;
44
52
  /** Called when the current binary IS the configured explorer CLI (prevents recursion).
45
53
  * Builds the full exploration prompt and calls Qwen API using own credentials. */
@@ -799,6 +799,66 @@ INSTRUCCIONES:
799
799
  log.verdict(verdict);
800
800
  return { verdict };
801
801
  }
802
+ /**
803
+ * Scan contextDir for stray files (outside the allowed structure) and clean them up:
804
+ * - Old timestamped explorer-*.md reports → delete (content already in architecture.md)
805
+ * - Other stray .md files at root level → append content to architecture.md, then delete
806
+ * Allowed root-level files: architecture.md, explorer-last.md
807
+ * Allowed subdirectory files: <service>/architecture.md (not touched here)
808
+ */
809
+ async _cleanContextDir(contextDir) {
810
+ let entries;
811
+ try {
812
+ entries = await fs.readdir(contextDir, { withFileTypes: true });
813
+ }
814
+ catch {
815
+ return;
816
+ } // dir doesn't exist yet
817
+ const archPath = path.join(contextDir, 'architecture.md');
818
+ const stray = [];
819
+ for (const e of entries) {
820
+ if (!e.isFile())
821
+ continue;
822
+ if (!e.name.endsWith('.md'))
823
+ continue;
824
+ if (e.name === 'architecture.md' || e.name === 'explorer-last.md')
825
+ continue;
826
+ stray.push(e.name);
827
+ }
828
+ if (stray.length === 0)
829
+ return;
830
+ log.info(`Limpiando ${stray.length} archivo(s) fuera de estructura en .agent/context/`);
831
+ for (const name of stray) {
832
+ const filePath = path.join(contextDir, name);
833
+ // Old timestamped explorer reports — just delete (content is redundant)
834
+ if (/^explorer-\d{4}-\d{2}-/.test(name)) {
835
+ await fs.unlink(filePath);
836
+ log.ok(` Eliminado: ${name}`);
837
+ continue;
838
+ }
839
+ // Other stray files — migrate content to architecture.md, then delete
840
+ try {
841
+ const content = (await readFile(filePath)).trim();
842
+ if (content) {
843
+ let arch = '';
844
+ try {
845
+ arch = await readFile(archPath);
846
+ }
847
+ catch { /* no arch yet */ }
848
+ const label = name.replace(/\.md$/, '');
849
+ await writeFile(archPath, `${arch}\n\n---\n## ${label}\n\n${content}\n`);
850
+ log.ok(` Migrado: ${name} → architecture.md`);
851
+ }
852
+ else {
853
+ log.ok(` Eliminado (vacío): ${name}`);
854
+ }
855
+ await fs.unlink(filePath);
856
+ }
857
+ catch (err) {
858
+ log.warn(` No se pudo limpiar ${name}: ${err.message}`);
859
+ }
860
+ }
861
+ }
802
862
  async runExplorer(task) {
803
863
  if (!this.config.roles.explorer) {
804
864
  if (!this.config.fallback_global) {
@@ -813,6 +873,8 @@ INSTRUCCIONES:
813
873
  const contextDir = path.join(agentDir, 'context');
814
874
  await fs.mkdir(contextDir, { recursive: true });
815
875
  await fs.mkdir(path.join(agentDir, 'rules'), { recursive: true });
876
+ // Clean up stray files before running
877
+ await this._cleanContextDir(contextDir);
816
878
  // Read existing architecture doc if any
817
879
  const archPath = path.join(contextDir, 'architecture.md');
818
880
  let existingArch = '';
@@ -840,16 +902,16 @@ INSTRUCCIONES:
840
902
  7. Al terminar lista todos los archivos creados/actualizados.
841
903
 
842
904
  REGLAS:
843
- - NO modifiques archivos de aplicacion (solo .agent/context/)
905
+ - Escribe UNICAMENTE los archivos indicados: ${archPath} y ${contextDir}/<servicio>/architecture.md
906
+ - NO crees archivos adicionales ni con otros nombres
907
+ - NO modifiques archivos de aplicacion
844
908
  - NO ejecutes comandos que cambien estado (npm install, migraciones, etc.)
845
909
  - Si un directorio esta en node_modules, dist, .git: ignoralo`;
846
910
  const res = await this.runWithFallback('explorer', prompt, 'Exploracion');
847
911
  const text = extractCliText(res);
848
- // Always save a timestamped explorer report
912
+ // Overwrite the single last-run report (no timestamp accumulation)
849
913
  try {
850
- const ts = new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19);
851
- await writeFile(path.join(contextDir, `explorer-${ts}.md`), `# Explorer Report\n\nTask: ${effectiveTask}\nDate: ${new Date().toISOString()}\n\n${text}\n`);
852
- log.ok(`Saved to .agent/context/explorer-${ts}.md`);
914
+ await writeFile(path.join(contextDir, 'explorer-last.md'), `# Explorer Report\n\nTask: ${effectiveTask}\nDate: ${new Date().toISOString()}\n\n${text}\n`);
853
915
  }
854
916
  catch { /* don't fail if save fails */ }
855
917
  return text;
@@ -863,6 +925,8 @@ REGLAS:
863
925
  const agentDir = path.join(this.projectDir, '.agent');
864
926
  const contextDir = path.join(agentDir, 'context');
865
927
  await fs.mkdir(contextDir, { recursive: true });
928
+ // Clean up stray files before running
929
+ await this._cleanContextDir(contextDir);
866
930
  const archPath = path.join(contextDir, 'architecture.md');
867
931
  let existingArch = '';
868
932
  try {
@@ -883,7 +947,11 @@ INSTRUCCIONES:
883
947
  2. Para cada uno: lee package.json/requirements.txt, explora src/, identifica entry point, rutas/endpoints, puerto.
884
948
  3. Identifica dependencias entre servicios.
885
949
  4. Crea/actualiza ${archPath} con tabla resumen y detalle por servicio.
886
- 5. Crea/actualiza ${contextDir}/<servicio>/architecture.md para cada servicio.`);
950
+ 5. Crea/actualiza ${contextDir}/<servicio>/architecture.md para cada servicio.
951
+
952
+ REGLAS:
953
+ - Escribe UNICAMENTE los archivos indicados: ${archPath} y ${contextDir}/<servicio>/architecture.md
954
+ - NO crees archivos adicionales ni con otros nombres en ningun directorio`);
887
955
  let result;
888
956
  const stopSpin = this._startSpinner(`agent-explorer ${role.model}`);
889
957
  try {
@@ -900,9 +968,7 @@ INSTRUCCIONES:
900
968
  throw err;
901
969
  }
902
970
  try {
903
- const ts = new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19);
904
- await writeFile(path.join(contextDir, `explorer-${ts}.md`), `# Explorer Report\n\nTask: ${effectiveTask}\n\n${result}\n`);
905
- log.ok(`Saved to .agent/context/explorer-${ts}.md`);
971
+ await writeFile(path.join(contextDir, 'explorer-last.md'), `# Explorer Report\n\nTask: ${effectiveTask}\nDate: ${new Date().toISOString()}\n\n${result}\n`);
906
972
  }
907
973
  catch { /* ignore */ }
908
974
  return result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-mp",
3
- "version": "0.3.9",
3
+ "version": "0.4.1",
4
4
  "description": "Deterministic multi-agent CLI orchestrator — plan, code, review",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",