@llm-dev-ops/agentics-cli 2.7.39 → 2.7.41

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/dist/cli/index.js CHANGED
@@ -1918,124 +1918,42 @@ async function main() {
1918
1918
  if (verdictKind !== 'failed') {
1919
1919
  // ADR-PIPELINE-088: under MCP mode, detach the auto-chain into a
1920
1920
  // background subprocess so the tool call returns within Claude
1921
- // Code's MCP client-side timeout. Auto-chain phases can take
1922
- // 30-60 minutes (ruflo swarm start has a 15-minute per-phase
1923
- // budget) which is far longer than the MCP client will wait.
1924
- // Shell invocations keep the original inline behaviour.
1925
- const mcpMode = process.env['MCP_SERVER_MODE'] === '1';
1921
+ // ADR-PIPELINE-103: Auto-chain runs synchronously in ALL modes
1922
+ // (including MCP). The prior "fast-return" path (ADR-088) detached
1923
+ // a background subprocess and returned after Phase 1 so the MCP
1924
+ // client wouldn't see a 30-60 minute call. In practice that
1925
+ // exposed the pipeline's internal phase boundaries to the end
1926
+ // user ("Phases 2-6 running in background, here's a trace id…")
1927
+ // and made the consumer Claude ask the user how to proceed.
1928
+ // End users need this to just work.
1929
+ //
1930
+ // The MCP server's runCLI has a 2-hour child timeout and emits
1931
+ // a 5s heartbeat (mcp-server.ts:937) plus per-event progress
1932
+ // notifications (mcp-server.ts:718-728). Together those keep the
1933
+ // MCP client connection alive across the full pipeline.
1926
1934
  const traceId = options.trace_id;
1927
- if (mcpMode) {
1928
- try {
1929
- const { spawn } = await import('node:child_process');
1930
- const fsMod = await import('node:fs');
1931
- const pathMod = await import('node:path');
1932
- const os = await import('node:os');
1933
- const runDir = pathMod.join(os.homedir(), '.agentics', 'runs', traceId);
1934
- fsMod.mkdirSync(runDir, { recursive: true, mode: 0o700 });
1935
- const logPath = pathMod.join(runDir, 'autochain.log');
1936
- const statusPath = pathMod.join(runDir, 'status.json');
1937
- const plansDir = pathMod.join(process.cwd(), '.agentics', 'plans');
1938
- // CLI_ENTRY must be the same dist/cli/index.js that is
1939
- // running us — __filename-equivalent in ESM.
1940
- const selfPath = new URL(import.meta.url).pathname;
1941
- const logFd = fsMod.openSync(logPath, 'a');
1942
- const child = spawn(process.execPath, [selfPath, '_autochain', traceId], {
1943
- detached: true,
1944
- stdio: ['ignore', logFd, logFd],
1945
- // Clear MCP_SERVER_MODE on the child so it uses the inline
1946
- // auto-chain path (the whole point of spawning it is to
1947
- // let it run the full pipeline without timing out).
1948
- env: { ...process.env, MCP_SERVER_MODE: '', AGENTICS_AUTOCHAIN_TRACE: traceId },
1949
- cwd: process.cwd(),
1950
- });
1951
- child.unref();
1952
- fsMod.closeSync(logFd);
1953
- // Write an initial status record so `agentics status <id>`
1954
- // has something to read before the child updates it.
1955
- // ADR-PIPELINE-089 §6: seed Phase 1 verdict fields so the
1956
- // status tool can surface HEALTHY / DEGRADED / FAILED plus
1957
- // the specific degradation list on the very first poll.
1958
- const phase1V = routeResult.result.phase1Verdict;
1959
- const initialStatus = {
1960
- traceId,
1961
- pid: child.pid ?? null,
1962
- startedAt: new Date().toISOString(),
1963
- mode: 'mcp-fast-return',
1964
- phase: 0,
1965
- inProgress: true,
1966
- completedPhases: [],
1967
- logPath,
1968
- plansDir,
1969
- artifacts: {},
1970
- phase1_verdict: phase1V?.verdict ?? null,
1971
- phase1_reason: phase1V?.reason ?? null,
1972
- phase1_degradations: phase1V?.degradations ?? [],
1973
- phase1_stats: phase1V?.stats ?? null,
1974
- };
1975
- fsMod.writeFileSync(statusPath, JSON.stringify(initialStatus, null, 2), { encoding: 'utf-8', mode: 0o600 });
1976
- // Emit structured markers so the MCP tool handler (and
1977
- // downstream Claude Code consumers) can parse them out of
1978
- // stdout without needing a second JSON-RPC round-trip.
1979
- console.log('');
1980
- console.log(`AGENTICS_TRACE_ID=${traceId}`);
1981
- console.log('AGENTICS_AUTOCHAIN_STATUS=background');
1982
- console.log(`AGENTICS_AUTOCHAIN_PID=${child.pid ?? ''}`);
1983
- console.log(`AGENTICS_AUTOCHAIN_LOG=${logPath}`);
1984
- console.log(`AGENTICS_AUTOCHAIN_STATUS_FILE=${statusPath}`);
1985
- console.log(`AGENTICS_PLANS_DIR=${plansDir}`);
1986
- // ADR-PIPELINE-089 §2: surface Phase 1 verdict as a
1987
- // structured marker so the MCP tool wrapper (and any
1988
- // log-grepping relay) can read it without parsing the
1989
- // status file. Count only — the full degradation list is
1990
- // in status.json.
1991
- if (phase1V) {
1992
- console.log(`AGENTICS_PHASE1_VERDICT=${phase1V.verdict}`);
1993
- console.log(`AGENTICS_PHASE1_DEGRADATIONS=${phase1V.degradations.length}`);
1994
- }
1995
- console.log('');
1996
- console.log('Phases 2-6 are running in the background. Poll with:');
1997
- console.log(` agentics status ${traceId}`);
1998
- console.log('ADR-PIPELINE-088.');
1999
- }
2000
- catch (detachErr) {
2001
- const errMsg = detachErr instanceof Error ? detachErr.message : String(detachErr);
2002
- console.error(`[WARN] MCP fast-return detach failed: ${errMsg}. Falling back to inline auto-chain.`);
2003
- // Fall through to the inline path below by setting a flag.
2004
- // We intentionally do not throw — better to block the MCP
2005
- // call than to lose auto-chain entirely.
2006
- try {
2007
- const { executeAutoChain, formatAutoChainForDisplay } = await import('../pipeline/auto-chain.js');
2008
- chainResult = await executeAutoChain(traceId, { verbose: options.verbose });
2009
- if (chainResult && options.format !== 'json') {
2010
- console.log(formatAutoChainForDisplay(chainResult));
2011
- }
2012
- }
2013
- catch (chainErr) {
2014
- console.error(`\nAuto-chain pipeline error: ${chainErr instanceof Error ? chainErr.message : String(chainErr)}`);
2015
- }
1935
+ console.error('');
1936
+ console.error('Auto-chaining Phases 2-6 (each phase builds on the previous)...');
1937
+ console.error(' Phase 1 (109 agents + ruvector simulation) complete. Starting sequential pipeline:');
1938
+ console.error(' Phase 2: Deep Research → Phase 3: SPARC+TDD → Phase 4: ADRs/DDDs → Phase 5: Build (ruflo) → Phase 6: ERP Push');
1939
+ console.error('');
1940
+ // Emit the trace id marker so the MCP tool wrapper can include
1941
+ // it in the response payload (mcp-server.ts:1133 parses this).
1942
+ console.log(`AGENTICS_TRACE_ID=${traceId}`);
1943
+ try {
1944
+ const { executeAutoChain, formatAutoChainForDisplay } = await import('../pipeline/auto-chain.js');
1945
+ chainResult = await executeAutoChain(traceId, {
1946
+ verbose: options.verbose,
1947
+ });
1948
+ if (chainResult && options.format !== 'json') {
1949
+ console.log(formatAutoChainForDisplay(chainResult));
2016
1950
  }
2017
1951
  }
2018
- else {
2019
- console.error('');
2020
- console.error('Auto-chaining Phases 2-6 (each phase builds on the previous)...');
2021
- console.error(' Phase 1 (109 agents + ruvector simulation) complete. Starting sequential pipeline:');
2022
- console.error(' Phase 2: Deep Research → Phase 3: SPARC+TDD → Phase 4: ADRs/DDDs → Phase 5: Build (ruflo) → Phase 6: ERP Push');
2023
- console.error('');
2024
- try {
2025
- const { executeAutoChain, formatAutoChainForDisplay } = await import('../pipeline/auto-chain.js');
2026
- chainResult = await executeAutoChain(traceId, {
2027
- verbose: options.verbose,
2028
- });
2029
- if (chainResult && options.format !== 'json') {
2030
- console.log(formatAutoChainForDisplay(chainResult));
2031
- }
2032
- }
2033
- catch (chainErr) {
2034
- const errMsg = chainErr instanceof Error ? chainErr.message : String(chainErr);
2035
- console.error(`\nAuto-chain pipeline error: ${errMsg}`);
2036
- if (chainErr instanceof Error && chainErr.stack) {
2037
- console.error(chainErr.stack);
2038
- }
1952
+ catch (chainErr) {
1953
+ const errMsg = chainErr instanceof Error ? chainErr.message : String(chainErr);
1954
+ console.error(`\nAuto-chain pipeline error: ${errMsg}`);
1955
+ if (chainErr instanceof Error && chainErr.stack) {
1956
+ console.error(chainErr.stack);
2039
1957
  }
2040
1958
  }
2041
1959
  }