stealthos-cli 0.1.0-alpha.3 → 0.1.0-alpha.5

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.
Files changed (177) hide show
  1. package/ai/CONTRACT.md +110 -0
  2. package/ai/INDEX.md +203 -0
  3. package/ai/README.md +434 -0
  4. package/ai/ROUTER.md +288 -0
  5. package/ai/agents/README.md +103 -0
  6. package/ai/agents/architect.md +59 -0
  7. package/ai/agents/backend-engineer.md +62 -0
  8. package/ai/agents/founder.md +45 -0
  9. package/ai/agents/frontend-engineer.md +61 -0
  10. package/ai/agents/product-manager.md +56 -0
  11. package/ai/agents/qa-engineer.md +53 -0
  12. package/ai/agents/researcher.md +74 -0
  13. package/ai/agents/reviewer.md +73 -0
  14. package/ai/agents/security-engineer.md +59 -0
  15. package/ai/agents/sre-engineer.md +70 -0
  16. package/ai/agents/tech-lead.md +70 -0
  17. package/ai/architecture/README.md +35 -0
  18. package/ai/architecture/components.md +24 -0
  19. package/ai/architecture/containers.md +30 -0
  20. package/ai/architecture/event-flows.md +36 -0
  21. package/ai/architecture/sequence-diagrams.md +38 -0
  22. package/ai/architecture/system-context.md +46 -0
  23. package/ai/architecture/threat-modeling.md +40 -0
  24. package/ai/blueprints/README.md +67 -0
  25. package/ai/blueprints/_schema.json +40 -0
  26. package/ai/blueprints/ai-platform.json +28 -0
  27. package/ai/blueprints/crm.json +22 -0
  28. package/ai/blueprints/game.json +25 -0
  29. package/ai/blueprints/mobile.json +24 -0
  30. package/ai/blueprints/realtime.json +22 -0
  31. package/ai/blueprints/saas.json +25 -0
  32. package/ai/blueprints/telemetry.json +30 -0
  33. package/ai/blueprints/web.json +23 -0
  34. package/ai/bootstrap/discovery-questions.md +117 -0
  35. package/ai/bootstrap/dispatcher.md +85 -0
  36. package/ai/bootstrap/existing-project.md +191 -0
  37. package/ai/bootstrap/new-project.md +127 -0
  38. package/ai/bootstrap/tech-mapping.md +164 -0
  39. package/ai/clients/README.md +114 -0
  40. package/ai/clients/antigravity.md +125 -0
  41. package/ai/clients/claude-code.md +65 -0
  42. package/ai/clients/cline.md +69 -0
  43. package/ai/clients/codex-aider-cli.md +82 -0
  44. package/ai/clients/continue.md +67 -0
  45. package/ai/clients/copilot.md +49 -0
  46. package/ai/clients/cursor.md +81 -0
  47. package/ai/clients/snippets/mcp-absolute-paths.json +9 -0
  48. package/ai/clients/snippets/mcp-http.json +7 -0
  49. package/ai/clients/snippets/mcp-stdio.json +9 -0
  50. package/ai/clients/trae.md +69 -0
  51. package/ai/clients/windsurf.md +71 -0
  52. package/ai/core/pipeline/execution-engine.md +157 -0
  53. package/ai/engineering/README.md +32 -0
  54. package/ai/engineering/observability/incident-response.md +82 -0
  55. package/ai/evals/protocol-tests.md +150 -0
  56. package/ai/evolution/agent-evolution.md +161 -0
  57. package/ai/evolution/improvements.md +91 -0
  58. package/ai/evolution/learnings.md +49 -0
  59. package/ai/evolution/patterns-discovered.md +48 -0
  60. package/ai/execution/README.md +33 -0
  61. package/ai/execution/backlog.md +27 -0
  62. package/ai/execution/milestones.md +26 -0
  63. package/ai/execution/roadmap.md +30 -0
  64. package/ai/execution/sprint.md +42 -0
  65. package/ai/governance/README.md +34 -0
  66. package/ai/governance/architecture-principles.md +99 -0
  67. package/ai/governance/definition-of-done.md +88 -0
  68. package/ai/governance/definition-of-ready.md +69 -0
  69. package/ai/governance/engineering-principles.md +70 -0
  70. package/ai/governance/quality-gates.md +85 -0
  71. package/ai/governance/security-policies.md +84 -0
  72. package/ai/hooks/enforce-audit.ps1 +41 -0
  73. package/ai/hooks/enforce-audit.sh +39 -0
  74. package/ai/hooks/guard-edit.ps1 +182 -0
  75. package/ai/hooks/guard-edit.sh +161 -0
  76. package/ai/hooks/inject-os-reminder.ps1 +40 -0
  77. package/ai/hooks/inject-os-reminder.sh +16 -0
  78. package/ai/manifest.json +238 -0
  79. package/ai/memory/_detected-stack.json +33 -0
  80. package/ai/memory/_summary.md +49 -0
  81. package/ai/memory/archive/.gitkeep +3 -0
  82. package/ai/memory/completed-tasks.md +156 -0
  83. package/ai/memory/decisions.md +257 -0
  84. package/ai/memory/errors-and-solutions.md +41 -0
  85. package/ai/memory/known-issues.md +40 -0
  86. package/ai/memory/pending-tasks.md +37 -0
  87. package/ai/memory/project-context.md +67 -0
  88. package/ai/operating-system/architecture.md +54 -0
  89. package/ai/operating-system/coding-standards.md +84 -0
  90. package/ai/operating-system/folder-structure.md +126 -0
  91. package/ai/operating-system/performance-rules.md +86 -0
  92. package/ai/operating-system/quality-control.md +81 -0
  93. package/ai/operating-system/security-rules.md +91 -0
  94. package/ai/operating-system/workflow.md +86 -0
  95. package/ai/product/README.md +24 -0
  96. package/ai/product/business-rules.md +26 -0
  97. package/ai/product/personas.md +29 -0
  98. package/ai/product/user-journeys.md +30 -0
  99. package/ai/product/vision.md +35 -0
  100. package/ai/rules/behavior.md +45 -0
  101. package/ai/rules/do.md +47 -0
  102. package/ai/rules/dont.md +46 -0
  103. package/ai/rules/execution-flow.md +125 -0
  104. package/ai/rules/structural-constraints.md +59 -0
  105. package/ai/rules/structure-canon.md +116 -0
  106. package/ai/runtime.md +179 -0
  107. package/ai/scripts/detect-stack.ps1 +166 -0
  108. package/ai/scripts/detect-stack.sh +172 -0
  109. package/ai/scripts/init-ai-os.ps1 +215 -0
  110. package/ai/scripts/init-ai-os.sh +99 -0
  111. package/ai/scripts/lint-os.ps1 +99 -0
  112. package/ai/scripts/lint-os.sh +85 -0
  113. package/ai/scripts/start-os.ps1 +151 -0
  114. package/ai/scripts/start-os.sh +141 -0
  115. package/ai/server/README.md +105 -0
  116. package/ai/server/aios-server.mjs +2134 -0
  117. package/ai/server/package-lock.json +802 -0
  118. package/ai/server/package.json +31 -0
  119. package/ai/server/src/analyzer/graph-builder.ts +92 -0
  120. package/ai/server/src/analyzer/index.ts +191 -0
  121. package/ai/server/src/analyzer/module-mapper.ts +171 -0
  122. package/ai/server/src/analyzer/smell-detector.ts +54 -0
  123. package/ai/server/src/analyzer/stack-detector.ts +70 -0
  124. package/ai/server/src/index.ts +16 -0
  125. package/ai/server/src/packager/context-builder.ts +217 -0
  126. package/ai/server/src/packager/index.ts +3 -0
  127. package/ai/server/src/packager/memory-injector.ts +128 -0
  128. package/ai/server/src/packager/module-summarizer.ts +60 -0
  129. package/ai/server/src/packager/token-estimator.ts +26 -0
  130. package/ai/server/src/snapshot/index.ts +3 -0
  131. package/ai/server/src/snapshot/snapshot-creator.ts +206 -0
  132. package/ai/server/src/snapshot/snapshot-diff.ts +86 -0
  133. package/ai/server/src/snapshot/snapshot-restore.ts +14 -0
  134. package/ai/server/src/types.ts +94 -0
  135. package/ai/server/tsconfig.json +26 -0
  136. package/ai/skills/architecture-design.md +82 -0
  137. package/ai/skills/backend-engineering.md +57 -0
  138. package/ai/skills/database-design.md +76 -0
  139. package/ai/skills/frontend-engineering.md +63 -0
  140. package/ai/skills/performance.md +73 -0
  141. package/ai/skills/scalability.md +84 -0
  142. package/ai/skills/security.md +71 -0
  143. package/ai/skills/testing.md +77 -0
  144. package/ai/specs/ADR/ADR-0002-typescript-runtime.md +103 -0
  145. package/ai/specs/ADR/ADR-0004-runtime-orchestrator.md +94 -0
  146. package/ai/specs/ADR/ADR-0005-workflow-engine.md +105 -0
  147. package/ai/specs/ADR/ADR-0006-runtime-state.md +104 -0
  148. package/ai/specs/ADR/ADR-0007-state-compiler-drift-context-layers-artifact-index.md +82 -0
  149. package/ai/specs/ADR/ADR-0008-intent-runtime-discovery-branching.md +93 -0
  150. package/ai/specs/ADR/ADR-0009-confidence-system-maturity-tracking.md +113 -0
  151. package/ai/specs/ADR/ADR-0010-structural-architecture-standards.md +121 -0
  152. package/ai/specs/ADR/ADR-0011-mcp-prompts.md +86 -0
  153. package/ai/specs/ADR/ADR-0012-stealthos-hybrid-architecture.md +174 -0
  154. package/ai/specs/ADR/_TEMPLATE.md +60 -0
  155. package/ai/specs/BRD/_TEMPLATE.md +50 -0
  156. package/ai/specs/PRD/_TEMPLATE.md +72 -0
  157. package/ai/specs/README.md +43 -0
  158. package/ai/specs/RFC/RFC-0001-runtime-orchestrator.md +149 -0
  159. package/ai/specs/RFC/RFC-0002-runtime-orchestrator-extended.md +134 -0
  160. package/ai/specs/RFC/_TEMPLATE.md +61 -0
  161. package/ai/specs/RUNBOOKS/_TEMPLATE.md +68 -0
  162. package/ai/specs/SDD/_TEMPLATE.md +104 -0
  163. package/ai/specs/TASKS/_TEMPLATE.md +52 -0
  164. package/ai/tools/debugging.md +64 -0
  165. package/ai/tools/dependency-analysis.md +46 -0
  166. package/ai/tools/internet-research.md +42 -0
  167. package/ai/tools/mcp-discovery.md +44 -0
  168. package/ai/workflows/_schema.json +81 -0
  169. package/ai/workflows/init.json +148 -0
  170. package/ai/workflows/sync.json +71 -0
  171. package/ai/workflows/work.json +91 -0
  172. package/package.json +42 -36
  173. package/scripts/bundle-ai.mjs +58 -0
  174. package/src/cli.mjs +83 -79
  175. package/src/commands/install.mjs +35 -11
  176. package/src/commands/run.mjs +117 -0
  177. package/src/lib/resolve-source.mjs +27 -10
@@ -0,0 +1,91 @@
1
+ {
2
+ "$schema": "./_schema.json",
3
+ "id": "work",
4
+ "version": "3.0.0",
5
+ "description": "Intent Runtime completo: carrega runtime-context compilado, classifica, faz gap analysis, pode pausar para clarification se complex, gera plan, pausa para approval, executa (LLM externa faz tool calls), valida, atualiza memory, snapshot final.",
6
+ "safety": { "project_files_readonly": false },
7
+ "guarantees": [
8
+ "runtime_context_compiled",
9
+ "task_classified",
10
+ "query_routed",
11
+ "memory_searched"
12
+ ],
13
+ "steps": [
14
+ {
15
+ "id": "load_runtime_context",
16
+ "tool": "aios_compile_runtime_context",
17
+ "args": { "max_modules": 10, "max_decisions": 5, "write": true },
18
+ "on_error": "continue"
19
+ },
20
+ {
21
+ "id": "classify",
22
+ "tool": "aios_classify_task",
23
+ "args": { "query": "${input.intent}" },
24
+ "on_error": "abort"
25
+ },
26
+ {
27
+ "id": "route",
28
+ "tool": "aios_route_query",
29
+ "args": { "query": "${input.intent}" },
30
+ "on_error": "abort"
31
+ },
32
+ {
33
+ "id": "search_memory_for_gap",
34
+ "tool": "aios_search_memory",
35
+ "args": { "query": "${input.intent}", "max_results": 10 },
36
+ "on_error": "continue"
37
+ },
38
+ {
39
+ "id": "clarification_gate",
40
+ "tool": "aios_state_set",
41
+ "args": { "path": "rotating.active_focus", "value": "work: clarification on '${input.intent}'" },
42
+ "on_error": "continue",
43
+ "pause_for": {
44
+ "when": "after",
45
+ "reason": "clarification_questions",
46
+ "prompt": "Antes de executar '${input.intent}': há ambiguidades, escopo incerto, ou decisão arquitetural envolvida? Responda 'ok' para prosseguir direto, ou descreva clarificações necessárias.",
47
+ "expected_input": "string"
48
+ }
49
+ },
50
+ {
51
+ "id": "build_focused_context",
52
+ "tool": "aios_build_context_package",
53
+ "args": {
54
+ "intent": "${input.intent}",
55
+ "max_modules": 8,
56
+ "write": false
57
+ },
58
+ "on_error": "continue"
59
+ },
60
+ {
61
+ "id": "approval_gate",
62
+ "tool": "aios_state_set",
63
+ "args": { "path": "rotating.active_focus", "value": "work: pending approval for '${input.intent}'" },
64
+ "on_error": "continue",
65
+ "pause_for": {
66
+ "when": "after",
67
+ "reason": "plan_approval",
68
+ "prompt": "Plano para '${input.intent}' montado pela LLM com base no runtime-context. Aprovar execução? ('ok' / 'ajustar: <detalhes>' / 'cancelar')",
69
+ "expected_input": "string"
70
+ }
71
+ },
72
+ {
73
+ "id": "validate_post_execution",
74
+ "tool": "aios_lint",
75
+ "args": {},
76
+ "on_error": "continue"
77
+ },
78
+ {
79
+ "id": "record_completion",
80
+ "tool": "aios_state_set",
81
+ "args": { "path": "rotating.active_focus", "value": "work: completed '${input.intent}'" },
82
+ "on_error": "continue"
83
+ },
84
+ {
85
+ "id": "post_snapshot",
86
+ "tool": "aios_snapshot",
87
+ "args": { "label": "work-${timestamp}" },
88
+ "on_error": "continue"
89
+ }
90
+ ]
91
+ }
package/package.json CHANGED
@@ -1,36 +1,42 @@
1
- {
2
- "name": "stealthos-cli",
3
- "version": "0.1.0-alpha.3",
4
- "description": "StealthOS CLI — install/manage the StealthOS knowledge base in ~/.stealthos/. Subcommands: install, status, version.",
5
- "type": "module",
6
- "bin": {
7
- "stealthos": "./bin.cjs"
8
- },
9
- "files": [
10
- "bin.cjs",
11
- "bin.mjs",
12
- "src/",
13
- "README.md"
14
- ],
15
- "engines": {
16
- "node": ">=18.0.0"
17
- },
18
- "keywords": [
19
- "stealthos",
20
- "mcp",
21
- "ai",
22
- "cli",
23
- "claude-code"
24
- ],
25
- "author": "Igor Kadu (https://github.com/IgorKadu)",
26
- "license": "MIT",
27
- "repository": {
28
- "type": "git",
29
- "url": "git+https://github.com/IgorKadu/stealthos.git",
30
- "directory": "packages/stealthos-cli"
31
- },
32
- "bugs": {
33
- "url": "https://github.com/IgorKadu/stealthos/issues"
34
- },
35
- "homepage": "https://github.com/IgorKadu/stealthos/tree/main/packages/stealthos-cli#readme"
36
- }
1
+ {
2
+ "name": "stealthos-cli",
3
+ "version": "0.1.0-alpha.5",
4
+ "scripts": {
5
+ "bundle-ai": "node scripts/bundle-ai.mjs",
6
+ "prepublishOnly": "node scripts/bundle-ai.mjs"
7
+ },
8
+ "description": "StealthOS CLI — install/manage the StealthOS knowledge base in ~/.stealthos/. Subcommands: install, status, version.",
9
+ "type": "module",
10
+ "bin": {
11
+ "stealthos": "./bin.cjs"
12
+ },
13
+ "files": [
14
+ "bin.cjs",
15
+ "bin.mjs",
16
+ "src/",
17
+ "scripts/",
18
+ "ai/",
19
+ "README.md"
20
+ ],
21
+ "engines": {
22
+ "node": ">=18.0.0"
23
+ },
24
+ "keywords": [
25
+ "stealthos",
26
+ "mcp",
27
+ "ai",
28
+ "cli",
29
+ "claude-code"
30
+ ],
31
+ "author": "Igor Kadu (https://github.com/IgorKadu)",
32
+ "license": "MIT",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/IgorKadu/stealthos.git",
36
+ "directory": "packages/stealthos-cli"
37
+ },
38
+ "bugs": {
39
+ "url": "https://github.com/IgorKadu/stealthos/issues"
40
+ },
41
+ "homepage": "https://github.com/IgorKadu/stealthos/tree/main/packages/stealthos-cli#readme"
42
+ }
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env node
2
+ // Copies the canonical .ai/ tree from the monorepo root into packages/stealthos-cli/ai/
3
+ // Runs automatically via `prepublishOnly`. Output dir is gitignored.
4
+
5
+ import { existsSync } from "node:fs";
6
+ import { mkdir, readdir, copyFile, rm, stat } from "node:fs/promises";
7
+ import { join, dirname, resolve } from "node:path";
8
+ import { fileURLToPath } from "node:url";
9
+
10
+ const __dirname = dirname(fileURLToPath(import.meta.url));
11
+ const PKG_ROOT = resolve(__dirname, "..");
12
+ const REPO_ROOT = resolve(PKG_ROOT, "..", "..");
13
+ const SRC = join(REPO_ROOT, ".ai");
14
+ const DST = join(PKG_ROOT, "ai");
15
+
16
+ const EXCLUDES = new Set([
17
+ "node_modules",
18
+ ".runtime",
19
+ "runtime",
20
+ "artifacts",
21
+ "context",
22
+ "snapshots",
23
+ ]);
24
+
25
+ async function copyDir(src, dst) {
26
+ await mkdir(dst, { recursive: true });
27
+ const entries = await readdir(src, { withFileTypes: true });
28
+ let count = 0;
29
+ for (const e of entries) {
30
+ if (EXCLUDES.has(e.name)) continue;
31
+ const s = join(src, e.name);
32
+ const d = join(dst, e.name);
33
+ if (e.isDirectory()) {
34
+ count += await copyDir(s, d);
35
+ } else if (e.isFile()) {
36
+ await copyFile(s, d);
37
+ count++;
38
+ }
39
+ }
40
+ return count;
41
+ }
42
+
43
+ async function main() {
44
+ if (!existsSync(SRC)) {
45
+ console.error(`✖ Source not found: ${SRC}`);
46
+ process.exit(1);
47
+ }
48
+ if (existsSync(DST)) {
49
+ await rm(DST, { recursive: true, force: true });
50
+ }
51
+ const n = await copyDir(SRC, DST);
52
+ console.log(`✓ Bundled ${n} files: ${SRC} → ${DST}`);
53
+ }
54
+
55
+ main().catch((e) => {
56
+ console.error("✖ bundle-ai failed:", e.message);
57
+ process.exit(1);
58
+ });
package/src/cli.mjs CHANGED
@@ -1,79 +1,83 @@
1
- // stealthos CLI router. Subcommand dispatcher.
2
-
3
- import { installCommand } from "./commands/install.mjs";
4
- import { statusCommand } from "./commands/status.mjs";
5
-
6
- const VERSION = "0.1.0-alpha.1";
7
-
8
- function usage() {
9
- process.stdout.write(`
10
- stealthos v${VERSION}
11
-
12
- USAGE
13
- stealthos <command> [options]
14
-
15
- COMMANDS
16
- install Install StealthOS knowledge base into ~/.stealthos/
17
- Options:
18
- --source <path> Source .ai/ tree (default: auto-detect in monorepo)
19
- --home <path> Target home (default: ~/.stealthos)
20
- --force Overwrite existing files
21
- status Show ~/.stealthos/ install status (version, paths, project count)
22
- version Print stealthos CLI version
23
- help Show this message
24
-
25
- ENVIRONMENT
26
- STEALTHOS_HOME Override target home (default: ~/.stealthos)
27
- STEALTHOS_SOURCE Override source .ai/ path (default: auto-detect)
28
- STEALTHOS_DEBUG=1 Print stack traces on errors
29
-
30
- EXAMPLES
31
- stealthos install
32
- stealthos install --home /opt/stealthos
33
- stealthos status
34
- `);
35
- }
36
-
37
- export async function runCli(argv) {
38
- const [cmd = "help", ...rest] = argv;
39
- switch (cmd) {
40
- case "install":
41
- return installCommand(parseFlags(rest));
42
- case "status":
43
- return statusCommand(parseFlags(rest));
44
- case "version":
45
- case "-v":
46
- case "--version":
47
- process.stdout.write(`${VERSION}\n`);
48
- return;
49
- case "help":
50
- case "-h":
51
- case "--help":
52
- usage();
53
- return;
54
- default:
55
- process.stderr.write(`Unknown command: ${cmd}\n`);
56
- usage();
57
- process.exit(2);
58
- }
59
- }
60
-
61
- function parseFlags(args) {
62
- const out = { _positional: [] };
63
- for (let i = 0; i < args.length; i++) {
64
- const a = args[i];
65
- if (a.startsWith("--")) {
66
- const key = a.slice(2);
67
- const next = args[i + 1];
68
- if (next && !next.startsWith("--")) {
69
- out[key] = next;
70
- i++;
71
- } else {
72
- out[key] = true;
73
- }
74
- } else {
75
- out._positional.push(a);
76
- }
77
- }
78
- return out;
79
- }
1
+ // stealthos CLI router. Subcommand dispatcher.
2
+
3
+ import { installCommand } from "./commands/install.mjs";
4
+ import { statusCommand } from "./commands/status.mjs";
5
+ import { runCommand } from "./commands/run.mjs";
6
+
7
+ const VERSION = "0.1.0-alpha.5";
8
+
9
+ function usage() {
10
+ process.stdout.write(`
11
+ stealthos v${VERSION}
12
+
13
+ USAGE
14
+ stealthos <command> [options]
15
+
16
+ COMMANDS
17
+ install Install StealthOS knowledge base into ~/.stealthos/
18
+ Options:
19
+ --source <path> Source .ai/ tree (default: auto-detect in monorepo)
20
+ --home <path> Target home (default: ~/.stealthos)
21
+ --force Overwrite existing files
22
+ status Show ~/.stealthos/ install status (version, paths, project count)
23
+ run <wf> Run a workflow via the local MCP server (init|sync|work [intent...])
24
+ version Print stealthos CLI version
25
+ help Show this message
26
+
27
+ ENVIRONMENT
28
+ STEALTHOS_HOME Override target home (default: ~/.stealthos)
29
+ STEALTHOS_SOURCE Override source .ai/ path (default: auto-detect)
30
+ STEALTHOS_DEBUG=1 Print stack traces on errors
31
+
32
+ EXAMPLES
33
+ stealthos install
34
+ stealthos install --home /opt/stealthos
35
+ stealthos status
36
+ `);
37
+ }
38
+
39
+ export async function runCli(argv) {
40
+ const [cmd = "help", ...rest] = argv;
41
+ switch (cmd) {
42
+ case "install":
43
+ return installCommand(parseFlags(rest));
44
+ case "status":
45
+ return statusCommand(parseFlags(rest));
46
+ case "run":
47
+ return runCommand(parseFlags(rest));
48
+ case "version":
49
+ case "-v":
50
+ case "--version":
51
+ process.stdout.write(`${VERSION}\n`);
52
+ return;
53
+ case "help":
54
+ case "-h":
55
+ case "--help":
56
+ usage();
57
+ return;
58
+ default:
59
+ process.stderr.write(`Unknown command: ${cmd}\n`);
60
+ usage();
61
+ process.exit(2);
62
+ }
63
+ }
64
+
65
+ function parseFlags(args) {
66
+ const out = { _positional: [] };
67
+ for (let i = 0; i < args.length; i++) {
68
+ const a = args[i];
69
+ if (a.startsWith("--")) {
70
+ const key = a.slice(2);
71
+ const next = args[i + 1];
72
+ if (next && !next.startsWith("--")) {
73
+ out[key] = next;
74
+ i++;
75
+ } else {
76
+ out[key] = true;
77
+ }
78
+ } else {
79
+ out._positional.push(a);
80
+ }
81
+ }
82
+ return out;
83
+ }
@@ -5,10 +5,24 @@
5
5
  import { existsSync } from "node:fs";
6
6
  import { mkdir, writeFile, readFile } from "node:fs/promises";
7
7
  import { join } from "node:path";
8
- import { homedir } from "node:os";
8
+ import { homedir, platform } from "node:os";
9
+ import { spawn } from "node:child_process";
9
10
  import { resolveSource } from "../lib/resolve-source.mjs";
10
11
  import { copyTree } from "../lib/copy-tree.mjs";
11
12
 
13
+ function runNpmInstall(cwd) {
14
+ return new Promise((resolve) => {
15
+ const npmCmd = platform() === "win32" ? "npm.cmd" : "npm";
16
+ const child = spawn(npmCmd, ["install", "--silent", "--no-audit", "--no-fund"], {
17
+ cwd,
18
+ stdio: ["ignore", "inherit", "inherit"],
19
+ shell: false,
20
+ });
21
+ child.on("close", (code) => resolve(code === 0));
22
+ child.on("error", () => resolve(false));
23
+ });
24
+ }
25
+
12
26
  // Paths NOT to copy: runtime-generated outputs + project-specific history.
13
27
  // These get freshly initialized per project by the server.
14
28
  const DEFAULT_EXCLUDES = [
@@ -67,6 +81,7 @@ export async function installCommand(flags = {}) {
67
81
  const home = flags.home ? String(flags.home) : (process.env.STEALTHOS_HOME || join(homedir(), ".stealthos"));
68
82
  const source = resolveSource({ flagSource: flags.source });
69
83
  const force = !!flags.force;
84
+ const skipServerDeps = !!flags["skip-server-deps"];
70
85
 
71
86
  process.stdout.write(`\n╔══════════════════════════════════════════════╗\n`);
72
87
  process.stdout.write(`║ stealthos install ║\n`);
@@ -110,7 +125,7 @@ export async function installCommand(flags = {}) {
110
125
  installed_at: new Date().toISOString(),
111
126
  installed_from: source,
112
127
  source_version: sourceVersion,
113
- cli_version: "0.1.0-alpha.3",
128
+ cli_version: "0.1.0-alpha.4",
114
129
  };
115
130
  await writeFile(join(home, ".stealthos-version.json"), JSON.stringify(versionMarker, null, 2), "utf8");
116
131
 
@@ -122,15 +137,24 @@ export async function installCommand(flags = {}) {
122
137
  process.stdout.write(` • Memory templates: ${templatesWritten}\n`);
123
138
  process.stdout.write(` • Versão source: ${sourceVersion}\n`);
124
139
 
125
- // Check server/node_modules needs install
126
- const serverPkgJson = join(home, "server", "package.json");
127
- if (existsSync(serverPkgJson) && !existsSync(join(home, "server", "node_modules"))) {
128
- process.stdout.write(`\n⚠ Próximo passo: instalar deps do server\n`);
129
- process.stdout.write(` cd "${join(home, "server")}" && npm install\n`);
140
+ // Auto-install server deps (unless --skip-server-deps)
141
+ const serverDir = join(home, "server");
142
+ const serverPkgJson = join(serverDir, "package.json");
143
+ if (existsSync(serverPkgJson) && !existsSync(join(serverDir, "node_modules"))) {
144
+ if (skipServerDeps) {
145
+ process.stdout.write(`\n⚠ Server deps NÃO instaladas (--skip-server-deps).\n`);
146
+ process.stdout.write(` Rode depois: cd "${serverDir}" && npm install\n`);
147
+ } else {
148
+ process.stdout.write(`\n📦 Instalando deps do server (pode levar 30s)...\n`);
149
+ const ok = await runNpmInstall(serverDir);
150
+ if (ok) {
151
+ process.stdout.write(`✓ Server deps instaladas\n`);
152
+ } else {
153
+ process.stdout.write(`⚠ npm install no server falhou. Rode manualmente:\n`);
154
+ process.stdout.write(` cd "${serverDir}" && npm install\n`);
155
+ }
156
+ }
130
157
  }
131
158
 
132
- process.stdout.write(`\nPara usar em modo hybrid:\n`);
133
- process.stdout.write(` export STEALTHOS_MODE=hybrid\n`);
134
- process.stdout.write(` export STEALTHOS_HOME="${home}"\n`);
135
- process.stdout.write(` node "${join(home, "server", "aios-server.mjs")}" --http\n`);
159
+ process.stdout.write(`\n✓ Tudo pronto. Abra sua IDE no projeto e use /init, /sync ou /work.\n`);
136
160
  }
@@ -0,0 +1,117 @@
1
+ // `stealthos run <workflow> [intent...]`
2
+ // Spawns aios-server.mjs as an MCP stdio process and sends a single
3
+ // tools/call for aios_run_workflow. Streams stdout/stderr from the server
4
+ // and prints the parsed tool result.
5
+ //
6
+ // Used by VSCode tasks (and as a generic CLI escape hatch) so users on IDEs
7
+ // without MCP can still trigger workflows directly.
8
+
9
+ import { spawn } from "node:child_process";
10
+ import { existsSync } from "node:fs";
11
+ import { join } from "node:path";
12
+ import { homedir } from "node:os";
13
+
14
+ function resolveServerPath() {
15
+ const home = process.env.STEALTHOS_HOME || join(homedir(), ".stealthos");
16
+ const candidate = join(home, "server", "aios-server.mjs");
17
+ if (!existsSync(candidate)) {
18
+ throw new Error(
19
+ `aios-server.mjs nao encontrado em ${candidate}. ` +
20
+ `Rode 'stealthos install' primeiro.`,
21
+ );
22
+ }
23
+ return { home, server: candidate };
24
+ }
25
+
26
+ function sendRpc(child, payload) {
27
+ return new Promise((resolve, reject) => {
28
+ let buf = "";
29
+ const onData = (chunk) => {
30
+ buf += chunk.toString("utf8");
31
+ // MCP framing: each message terminated by newline
32
+ const lines = buf.split("\n");
33
+ buf = lines.pop();
34
+ for (const line of lines) {
35
+ if (!line.trim()) continue;
36
+ try {
37
+ const msg = JSON.parse(line);
38
+ if (msg.id === payload.id) {
39
+ child.stdout.off("data", onData);
40
+ resolve(msg);
41
+ return;
42
+ }
43
+ } catch {
44
+ // ignore non-JSON lines (server logs)
45
+ }
46
+ }
47
+ };
48
+ child.stdout.on("data", onData);
49
+ child.stdin.write(JSON.stringify(payload) + "\n");
50
+ setTimeout(() => {
51
+ child.stdout.off("data", onData);
52
+ reject(new Error("timeout aguardando resposta do MCP server"));
53
+ }, 60000);
54
+ });
55
+ }
56
+
57
+ export async function runCommand(opts) {
58
+ const positional = opts._positional || [];
59
+ const workflow = positional[0];
60
+ if (!workflow) {
61
+ throw new Error("Uso: stealthos run <workflow> [intent...]");
62
+ }
63
+ const intent = positional.slice(1).join(" ");
64
+
65
+ const { home, server } = resolveServerPath();
66
+ process.stdout.write(`▶ stealthos run ${workflow}${intent ? ` (intent: ${intent})` : ""}\n`);
67
+ process.stdout.write(` home: ${home}\n server: ${server}\n\n`);
68
+
69
+ const child = spawn(process.execPath, [server], {
70
+ stdio: ["pipe", "pipe", "inherit"],
71
+ env: {
72
+ ...process.env,
73
+ STEALTHOS_MODE: "hybrid",
74
+ STEALTHOS_HOME: home,
75
+ STEALTHOS_PROJECT_DIR: process.cwd(),
76
+ },
77
+ });
78
+
79
+ let exitCode = 0;
80
+ try {
81
+ // 1. initialize
82
+ await sendRpc(child, {
83
+ jsonrpc: "2.0",
84
+ id: 1,
85
+ method: "initialize",
86
+ params: { protocolVersion: "2024-11-05", capabilities: {}, clientInfo: { name: "stealthos-cli", version: "0.1" } },
87
+ });
88
+
89
+ // 2. tools/call aios_run_workflow
90
+ const resp = await sendRpc(child, {
91
+ jsonrpc: "2.0",
92
+ id: 2,
93
+ method: "tools/call",
94
+ params: {
95
+ name: "aios_run_workflow",
96
+ arguments: { name: workflow, input: { intent } },
97
+ },
98
+ });
99
+
100
+ if (resp.error) {
101
+ process.stderr.write(`Erro do MCP: ${JSON.stringify(resp.error, null, 2)}\n`);
102
+ exitCode = 1;
103
+ } else {
104
+ const content = resp.result?.content || [];
105
+ for (const part of content) {
106
+ if (part.type === "text") process.stdout.write(part.text + "\n");
107
+ }
108
+ }
109
+ } catch (err) {
110
+ process.stderr.write(`Erro: ${err.message}\n`);
111
+ exitCode = 1;
112
+ } finally {
113
+ child.stdin.end();
114
+ child.kill();
115
+ }
116
+ process.exit(exitCode);
117
+ }
@@ -1,9 +1,10 @@
1
1
  // Locate the source .ai/ tree to install from.
2
- // Strategy:
3
- // 1. Explicit --source flag wins
2
+ // Strategy (in order):
3
+ // 1. Explicit --source flag
4
4
  // 2. STEALTHOS_SOURCE env var
5
- // 3. Monorepo discovery: walk up from __dirname looking for sibling .ai/
6
- // 4. Fail loudly
5
+ // 3. Bundled ai/ inside the published package (preferred for end users)
6
+ // 4. Monorepo discovery: walk up looking for sibling .ai/ (dev mode)
7
+ // 5. Fail loudly
7
8
 
8
9
  import { existsSync } from "node:fs";
9
10
  import { resolve, dirname, join } from "node:path";
@@ -12,22 +13,29 @@ import { fileURLToPath } from "node:url";
12
13
  const __dirname = dirname(fileURLToPath(import.meta.url));
13
14
 
14
15
  function resolveAiDir(abs) {
15
- // Accept either <root> (contains .ai/manifest.json) or <root>/.ai (contains manifest.json)
16
+ // Accept either <root> (contains manifest.json) or <root>/.ai (contains manifest.json) or <root>/ai (bundled)
16
17
  if (existsSync(join(abs, "manifest.json"))) return abs;
17
- const sub = join(abs, ".ai");
18
- if (existsSync(join(sub, "manifest.json"))) return sub;
18
+ for (const sub of [".ai", "ai"]) {
19
+ const candidate = join(abs, sub);
20
+ if (existsSync(join(candidate, "manifest.json"))) return candidate;
21
+ }
19
22
  return null;
20
23
  }
21
24
 
22
25
  export function resolveSource({ flagSource } = {}) {
26
+ // 1. Explicit --source
23
27
  if (flagSource) {
24
28
  const abs = resolve(flagSource);
25
29
  const ai = resolveAiDir(abs);
26
30
  if (!ai) {
27
- throw new Error(`--source path does not contain manifest.json (checked ${abs} and ${join(abs, ".ai")})`);
31
+ throw new Error(
32
+ `--source path does not contain manifest.json (checked ${abs}, ${join(abs, ".ai")}, ${join(abs, "ai")})`,
33
+ );
28
34
  }
29
35
  return ai;
30
36
  }
37
+
38
+ // 2. Env var
31
39
  if (process.env.STEALTHOS_SOURCE) {
32
40
  const abs = resolve(process.env.STEALTHOS_SOURCE);
33
41
  const ai = resolveAiDir(abs);
@@ -36,7 +44,15 @@ export function resolveSource({ flagSource } = {}) {
36
44
  }
37
45
  return ai;
38
46
  }
39
- // Monorepo discovery: walk up from packages/stealthos-cli/src/lib/ to find sibling .ai/
47
+
48
+ // 3. Bundled inside the package itself (created by prepublishOnly)
49
+ // __dirname = packages/stealthos-cli/src/lib → ../../ai
50
+ const bundled = resolve(__dirname, "..", "..", "ai");
51
+ if (existsSync(join(bundled, "manifest.json"))) {
52
+ return bundled;
53
+ }
54
+
55
+ // 4. Monorepo dev fallback: walk up from src/lib looking for sibling .ai/
40
56
  let dir = __dirname;
41
57
  for (let i = 0; i < 6; i++) {
42
58
  const candidate = join(dir, ".ai");
@@ -47,7 +63,8 @@ export function resolveSource({ flagSource } = {}) {
47
63
  if (parent === dir) break;
48
64
  dir = parent;
49
65
  }
66
+
50
67
  throw new Error(
51
- "Could not locate source .ai/ tree. Pass --source <path> or set STEALTHOS_SOURCE env var.",
68
+ "Could not locate source .ai/ tree. The CLI should ship with bundled ai/ — reinstall stealthos-cli, or pass --source <path-to-stealthos-repo>.",
52
69
  );
53
70
  }