martin-loop 0.1.2 → 0.1.3

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 (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +362 -344
  3. package/dist/bin/martin-loop.js +23 -0
  4. package/dist/index.d.ts +22 -0
  5. package/dist/index.js +31 -0
  6. package/dist/vendor/adapters/claude-cli.d.ts +89 -0
  7. package/dist/vendor/adapters/claude-cli.js +555 -0
  8. package/dist/vendor/adapters/cli-bridge.d.ts +28 -0
  9. package/dist/vendor/adapters/cli-bridge.js +127 -0
  10. package/dist/vendor/adapters/direct-provider.d.ts +10 -0
  11. package/dist/vendor/adapters/direct-provider.js +41 -0
  12. package/dist/vendor/adapters/index.d.ts +5 -0
  13. package/dist/vendor/adapters/index.js +5 -0
  14. package/dist/vendor/adapters/runtime-support.d.ts +14 -0
  15. package/dist/vendor/adapters/runtime-support.js +52 -0
  16. package/dist/vendor/adapters/stub-agent-cli.d.ts +8 -0
  17. package/dist/vendor/adapters/stub-agent-cli.js +41 -0
  18. package/dist/vendor/adapters/stub-direct-provider.d.ts +8 -0
  19. package/dist/vendor/adapters/stub-direct-provider.js +10 -0
  20. package/dist/vendor/cli/bin/martin.d.ts +2 -0
  21. package/dist/vendor/cli/bin/martin.js +19 -0
  22. package/dist/vendor/cli/index.d.ts +39 -0
  23. package/dist/vendor/cli/index.js +634 -0
  24. package/dist/vendor/cli/persistence.d.ts +34 -0
  25. package/dist/vendor/cli/persistence.js +71 -0
  26. package/dist/vendor/contracts/governance.d.ts +21 -0
  27. package/dist/vendor/contracts/governance.js +12 -0
  28. package/dist/vendor/contracts/index.d.ts +330 -0
  29. package/dist/vendor/contracts/index.js +203 -0
  30. package/dist/vendor/core/compiler.d.ts +50 -0
  31. package/dist/vendor/core/compiler.js +47 -0
  32. package/dist/vendor/core/grounding.d.ts +37 -0
  33. package/dist/vendor/core/grounding.js +270 -0
  34. package/dist/vendor/core/index.d.ts +145 -0
  35. package/dist/vendor/core/index.js +1099 -0
  36. package/dist/vendor/core/leash.d.ts +48 -0
  37. package/dist/vendor/core/leash.js +408 -0
  38. package/dist/vendor/core/persistence/compiler.d.ts +18 -0
  39. package/dist/vendor/core/persistence/compiler.js +35 -0
  40. package/dist/vendor/core/persistence/index.d.ts +6 -0
  41. package/dist/vendor/core/persistence/index.js +4 -0
  42. package/dist/vendor/core/persistence/ledger.d.ts +23 -0
  43. package/dist/vendor/core/persistence/ledger.js +10 -0
  44. package/dist/vendor/core/persistence/store.d.ts +77 -0
  45. package/dist/vendor/core/persistence/store.js +84 -0
  46. package/dist/vendor/core/policy.d.ts +126 -0
  47. package/dist/vendor/core/policy.js +625 -0
  48. package/dist/vendor/core/rollback.d.ts +11 -0
  49. package/dist/vendor/core/rollback.js +219 -0
  50. package/docs/oss/EXAMPLES.md +126 -126
  51. package/docs/oss/OSS-BOUNDARY-REPORT.json +113 -113
  52. package/docs/oss/OSS-BOUNDARY-REPORT.md +48 -48
  53. package/docs/oss/QUICKSTART.md +135 -135
  54. package/docs/oss/README.md +93 -93
  55. package/docs/oss/RELEASE-SURFACE-REPORT.json +45 -45
  56. package/docs/oss/RELEASE-SURFACE-REPORT.md +35 -35
  57. package/package.json +56 -54
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { executeCli } from "../vendor/cli/index.js";
4
+
5
+ const args = process.argv.slice(2);
6
+
7
+ executeCli(args)
8
+ .then((result) => {
9
+ if (result.stdout) {
10
+ process.stdout.write(`${result.stdout}\n`);
11
+ }
12
+
13
+ if (result.stderr) {
14
+ process.stderr.write(`${result.stderr}\n`);
15
+ }
16
+
17
+ process.exitCode = result.exitCode;
18
+ })
19
+ .catch((error) => {
20
+ const message = error instanceof Error ? error.message : String(error);
21
+ process.stderr.write(`${message}\n`);
22
+ process.exitCode = 1;
23
+ });
@@ -0,0 +1,22 @@
1
+ export { runMartin, compilePromptPacket, createFileRunStore, makeLedgerEvent, resolveRunsRoot } from "./vendor/core/index.js";
2
+ export type { CompileResult, MartinAdapter, MartinAdapterRequest, MartinAdapterResult, PromptPacket, RunMartinInput, RunMartinResult, RunStore } from "./vendor/core/index.js";
3
+ export { executeCli, parseCliArguments, renderCliHelp } from "./vendor/cli/index.js";
4
+ export type { ParsedCliArguments, RunCommandRequest } from "./vendor/cli/index.js";
5
+ export { createClaudeCliAdapter, createCodexCliAdapter, createDirectProviderAdapter, createStubDirectProviderAdapter, createStubAgentCliAdapter } from "./vendor/adapters/index.js";
6
+ export type { AgentCliAdapterOptions, ClaudeCliAdapterOptions, CliArgsBuilder, CodexCliAdapterOptions, DirectProviderAdapterOptions, SpawnLike, StubAgentCliAdapterOptions, StubDirectProviderAdapterOptions, SubprocessResult, VerificationOutcome } from "./vendor/adapters/index.js";
7
+ export { appendLoopEvent, buildPortfolioSnapshot, createGovernanceSnapshot, createLoopRecord, createTelemetryEnvelope, DEFAULT_BUDGET, EMPTY_COST, validateTelemetryBatch, validateTelemetryEnvelope } from "./vendor/contracts/index.js";
8
+ export type { ApprovalPolicy, ExecutionProfile, LoopBudget, LoopRecord, LoopTask } from "./vendor/contracts/index.js";
9
+
10
+ export interface MartinLoopOptions {
11
+ adapter?: MartinAdapter;
12
+ defaults?: Partial<Omit<RunMartinInput, "adapter">>;
13
+ }
14
+
15
+ export type MartinLoopRunInput = Omit<RunMartinInput, "adapter"> & {
16
+ adapter?: MartinAdapter;
17
+ };
18
+
19
+ export declare class MartinLoop {
20
+ constructor(options?: MartinLoopOptions);
21
+ run(input: MartinLoopRunInput): Promise<RunMartinResult>;
22
+ }
package/dist/index.js ADDED
@@ -0,0 +1,31 @@
1
+ import { runMartin } from "./vendor/core/index.js";
2
+
3
+ export { runMartin, compilePromptPacket, createFileRunStore, makeLedgerEvent, resolveRunsRoot } from "./vendor/core/index.js";
4
+ export { executeCli, parseCliArguments, renderCliHelp } from "./vendor/cli/index.js";
5
+ export { createClaudeCliAdapter, createCodexCliAdapter, createDirectProviderAdapter, createStubDirectProviderAdapter, createStubAgentCliAdapter } from "./vendor/adapters/index.js";
6
+ export { appendLoopEvent, buildPortfolioSnapshot, createGovernanceSnapshot, createLoopRecord, createTelemetryEnvelope, DEFAULT_BUDGET, EMPTY_COST, validateTelemetryBatch, validateTelemetryEnvelope } from "./vendor/contracts/index.js";
7
+
8
+ export class MartinLoop {
9
+ constructor(options = {}) {
10
+ this.adapter = options.adapter;
11
+ this.defaults = options.defaults ?? {};
12
+ }
13
+
14
+ async run(input) {
15
+ const merged = {
16
+ ...this.defaults,
17
+ ...input,
18
+ metadata: {
19
+ ...(this.defaults.metadata ?? {}),
20
+ ...(input.metadata ?? {}),
21
+ },
22
+ adapter: input.adapter ?? this.adapter,
23
+ };
24
+
25
+ if (!merged.adapter) {
26
+ throw new Error("MartinLoop.run requires an adapter. Import an adapter helper from \"martin-loop\" or pass a MartinAdapter instance.");
27
+ }
28
+
29
+ return runMartin(merged);
30
+ }
31
+ }
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Real agent-CLI adapters.
3
+ *
4
+ * Exports a generic factory (`createAgentCliAdapter`) and two pre-configured
5
+ * factories (`createClaudeCliAdapter`, `createCodexCliAdapter`) that spawn
6
+ * the respective AI coding CLI as a child subprocess.
7
+ *
8
+ * Usage in CLI:
9
+ * createClaudeCliAdapter({ workingDirectory: process.cwd() })
10
+ * createCodexCliAdapter({ workingDirectory: process.cwd() })
11
+ *
12
+ * MCP tools and integration tests use the same factories.
13
+ */
14
+ import type { MartinAdapter } from "../core/index.js";
15
+ import { type SpawnLike } from "./cli-bridge.js";
16
+ /**
17
+ * Given a prompt string, returns the full argv array to pass to spawn().
18
+ * Example for Claude: (p) => ["--print", p, "--dangerously-skip-permissions"]
19
+ * Example for Codex: (p) => ["--full-auto", p]
20
+ */
21
+ export type CliArgsBuilder = (prompt: string) => string[];
22
+ export interface AgentCliAdapterOptions {
23
+ /** The executable to spawn (e.g. "claude", "codex"). */
24
+ command: string;
25
+ /** Converts a prompt string into the argv array passed to spawn(). */
26
+ argsBuilder: CliArgsBuilder;
27
+ /** Adapter ID suffix. Defaults to command. */
28
+ adapterIdSuffix?: string;
29
+ /** Working directory for all subprocesses. Defaults to process.cwd(). */
30
+ workingDirectory?: string;
31
+ /** Timeout for the agent subprocess in ms. Defaults to 300_000 (5 min). */
32
+ timeoutMs?: number;
33
+ /** Timeout per verification command in ms. Defaults to 60_000 (1 min). */
34
+ verifyTimeoutMs?: number;
35
+ /** Human-readable label shown in loop records. */
36
+ label?: string;
37
+ /** Model name surfaced in adapter metadata (also used for cost estimation). */
38
+ model?: string;
39
+ /**
40
+ * Whether the CLI outputs JSON when --output-format json is passed.
41
+ * Set to false for CLIs that don't support this flag (e.g. Codex).
42
+ * Defaults to true for Claude.
43
+ */
44
+ supportsJsonOutput?: boolean;
45
+ /** Test-only override for subprocess spawning. */
46
+ spawnImpl?: SpawnLike;
47
+ }
48
+ export interface ClaudeCliAdapterOptions {
49
+ workingDirectory?: string;
50
+ timeoutMs?: number;
51
+ verifyTimeoutMs?: number;
52
+ label?: string;
53
+ /** Override the model passed via --model flag. */
54
+ model?: string;
55
+ /** Extra args appended after core args (before prompt). */
56
+ extraArgs?: string[];
57
+ spawnImpl?: SpawnLike;
58
+ }
59
+ export interface CodexCliAdapterOptions {
60
+ workingDirectory?: string;
61
+ timeoutMs?: number;
62
+ verifyTimeoutMs?: number;
63
+ label?: string;
64
+ /** Override the model passed via --model flag. */
65
+ model?: string;
66
+ /** Run in full-auto mode (--full-auto). Defaults to true. */
67
+ fullAuto?: boolean;
68
+ /** Extra args appended after core args (before prompt). */
69
+ extraArgs?: string[];
70
+ spawnImpl?: SpawnLike;
71
+ }
72
+ export declare function createAgentCliAdapter(options: AgentCliAdapterOptions): MartinAdapter;
73
+ /**
74
+ * Spawns `claude --output-format json --print "<prompt>" --dangerously-skip-permissions [extraArgs]`.
75
+ *
76
+ * The --output-format json flag causes Claude CLI to return structured JSON
77
+ * including real token usage counts, enabling accurate cost tracking.
78
+ *
79
+ * Requires the Claude Code CLI to be installed and authenticated:
80
+ * https://docs.anthropic.com/claude-code
81
+ */
82
+ export declare function createClaudeCliAdapter(options?: ClaudeCliAdapterOptions): MartinAdapter;
83
+ /**
84
+ * Spawns `codex [--full-auto] [--model <model>] "<prompt>" [extraArgs]`.
85
+ *
86
+ * Requires the Codex CLI to be installed and authenticated:
87
+ * npm install -g @openai/codex
88
+ */
89
+ export declare function createCodexCliAdapter(options?: CodexCliAdapterOptions): MartinAdapter;