@inbrowser/agent 0.0.0-placeholder → 0.1.0

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 (202) hide show
  1. package/AGENTS.md +270 -0
  2. package/README.md +117 -2
  3. package/bin/agent.ts +10 -0
  4. package/dist/cli/commands/describe.d.ts +14 -0
  5. package/dist/cli/commands/describe.d.ts.map +1 -0
  6. package/dist/cli/commands/describe.js +179 -0
  7. package/dist/cli/commands/describe.js.map +1 -0
  8. package/dist/cli/commands/events.d.ts +21 -0
  9. package/dist/cli/commands/events.d.ts.map +1 -0
  10. package/dist/cli/commands/events.js +59 -0
  11. package/dist/cli/commands/events.js.map +1 -0
  12. package/dist/cli/commands/fleet.d.ts +15 -0
  13. package/dist/cli/commands/fleet.d.ts.map +1 -0
  14. package/dist/cli/commands/fleet.js +149 -0
  15. package/dist/cli/commands/fleet.js.map +1 -0
  16. package/dist/cli/commands/help.d.ts +15 -0
  17. package/dist/cli/commands/help.d.ts.map +1 -0
  18. package/dist/cli/commands/help.js +93 -0
  19. package/dist/cli/commands/help.js.map +1 -0
  20. package/dist/cli/commands/migrate.d.ts +27 -0
  21. package/dist/cli/commands/migrate.d.ts.map +1 -0
  22. package/dist/cli/commands/migrate.js +109 -0
  23. package/dist/cli/commands/migrate.js.map +1 -0
  24. package/dist/cli/commands/run.d.ts +38 -0
  25. package/dist/cli/commands/run.d.ts.map +1 -0
  26. package/dist/cli/commands/run.js +535 -0
  27. package/dist/cli/commands/run.js.map +1 -0
  28. package/dist/cli/commands/schema.d.ts +8 -0
  29. package/dist/cli/commands/schema.d.ts.map +1 -0
  30. package/dist/cli/commands/schema.js +12 -0
  31. package/dist/cli/commands/schema.js.map +1 -0
  32. package/dist/cli/commands/serve.d.ts +39 -0
  33. package/dist/cli/commands/serve.d.ts.map +1 -0
  34. package/dist/cli/commands/serve.js +65 -0
  35. package/dist/cli/commands/serve.js.map +1 -0
  36. package/dist/cli/commands/undo.d.ts +36 -0
  37. package/dist/cli/commands/undo.d.ts.map +1 -0
  38. package/dist/cli/commands/undo.js +132 -0
  39. package/dist/cli/commands/undo.js.map +1 -0
  40. package/dist/cli/fixtures.d.ts +17 -0
  41. package/dist/cli/fixtures.d.ts.map +1 -0
  42. package/dist/cli/fixtures.js +107 -0
  43. package/dist/cli/fixtures.js.map +1 -0
  44. package/dist/cli/hardening.d.ts +39 -0
  45. package/dist/cli/hardening.d.ts.map +1 -0
  46. package/dist/cli/hardening.js +68 -0
  47. package/dist/cli/hardening.js.map +1 -0
  48. package/dist/cli/index.d.ts +28 -0
  49. package/dist/cli/index.d.ts.map +1 -0
  50. package/dist/cli/index.js +19 -0
  51. package/dist/cli/index.js.map +1 -0
  52. package/dist/cli/llm/openrouter.d.ts +33 -0
  53. package/dist/cli/llm/openrouter.d.ts.map +1 -0
  54. package/dist/cli/llm/openrouter.js +285 -0
  55. package/dist/cli/llm/openrouter.js.map +1 -0
  56. package/dist/cli/main.d.ts +32 -0
  57. package/dist/cli/main.d.ts.map +1 -0
  58. package/dist/cli/main.js +106 -0
  59. package/dist/cli/main.js.map +1 -0
  60. package/dist/cli/output.d.ts +36 -0
  61. package/dist/cli/output.d.ts.map +1 -0
  62. package/dist/cli/output.js +95 -0
  63. package/dist/cli/output.js.map +1 -0
  64. package/dist/cli/parse.d.ts +26 -0
  65. package/dist/cli/parse.d.ts.map +1 -0
  66. package/dist/cli/parse.js +160 -0
  67. package/dist/cli/parse.js.map +1 -0
  68. package/dist/cli/session-log.d.ts +34 -0
  69. package/dist/cli/session-log.d.ts.map +1 -0
  70. package/dist/cli/session-log.js +52 -0
  71. package/dist/cli/session-log.js.map +1 -0
  72. package/dist/cli/spec.d.ts +62 -0
  73. package/dist/cli/spec.d.ts.map +1 -0
  74. package/dist/cli/spec.js +510 -0
  75. package/dist/cli/spec.js.map +1 -0
  76. package/dist/cli/ui/RunView.d.ts +134 -0
  77. package/dist/cli/ui/RunView.d.ts.map +1 -0
  78. package/dist/cli/ui/RunView.js +341 -0
  79. package/dist/cli/ui/RunView.js.map +1 -0
  80. package/dist/events/codec.d.ts +79 -0
  81. package/dist/events/codec.d.ts.map +1 -0
  82. package/dist/events/codec.js +142 -0
  83. package/dist/events/codec.js.map +1 -0
  84. package/dist/events/log-core.d.ts +76 -0
  85. package/dist/events/log-core.d.ts.map +1 -0
  86. package/dist/events/log-core.js +73 -0
  87. package/dist/events/log-core.js.map +1 -0
  88. package/dist/events/log.d.ts +60 -0
  89. package/dist/events/log.d.ts.map +1 -0
  90. package/dist/events/log.js +193 -0
  91. package/dist/events/log.js.map +1 -0
  92. package/dist/events/replay.d.ts +106 -0
  93. package/dist/events/replay.d.ts.map +1 -0
  94. package/dist/events/replay.js +137 -0
  95. package/dist/events/replay.js.map +1 -0
  96. package/dist/events/wrap.d.ts +100 -0
  97. package/dist/events/wrap.d.ts.map +1 -0
  98. package/dist/events/wrap.js +141 -0
  99. package/dist/events/wrap.js.map +1 -0
  100. package/dist/index.d.ts +52 -0
  101. package/dist/index.d.ts.map +1 -0
  102. package/dist/index.js +37 -0
  103. package/dist/index.js.map +1 -0
  104. package/dist/llm-adapter.d.ts +96 -0
  105. package/dist/llm-adapter.d.ts.map +1 -0
  106. package/dist/llm-adapter.js +132 -0
  107. package/dist/llm-adapter.js.map +1 -0
  108. package/dist/mcp/serve.d.ts +70 -0
  109. package/dist/mcp/serve.d.ts.map +1 -0
  110. package/dist/mcp/serve.js +154 -0
  111. package/dist/mcp/serve.js.map +1 -0
  112. package/dist/metrics/runs.d.ts +58 -0
  113. package/dist/metrics/runs.d.ts.map +1 -0
  114. package/dist/metrics/runs.js +99 -0
  115. package/dist/metrics/runs.js.map +1 -0
  116. package/dist/metrics.d.ts +38 -0
  117. package/dist/metrics.d.ts.map +1 -0
  118. package/dist/metrics.js +123 -0
  119. package/dist/metrics.js.map +1 -0
  120. package/dist/node.d.ts +22 -0
  121. package/dist/node.d.ts.map +1 -0
  122. package/dist/node.js +22 -0
  123. package/dist/node.js.map +1 -0
  124. package/dist/session.d.ts +10 -0
  125. package/dist/session.d.ts.map +1 -0
  126. package/dist/session.js +179 -0
  127. package/dist/session.js.map +1 -0
  128. package/dist/storage.d.ts +14 -0
  129. package/dist/storage.d.ts.map +1 -0
  130. package/dist/storage.js +58 -0
  131. package/dist/storage.js.map +1 -0
  132. package/dist/strategy.d.ts +26 -0
  133. package/dist/strategy.d.ts.map +1 -0
  134. package/dist/strategy.js +200 -0
  135. package/dist/strategy.js.map +1 -0
  136. package/dist/tools.d.ts +26 -0
  137. package/dist/tools.d.ts.map +1 -0
  138. package/dist/tools.js +129 -0
  139. package/dist/tools.js.map +1 -0
  140. package/dist/types/agent.d.ts +94 -0
  141. package/dist/types/agent.d.ts.map +1 -0
  142. package/dist/types/agent.js +17 -0
  143. package/dist/types/agent.js.map +1 -0
  144. package/dist/types/capabilities.d.ts +17 -0
  145. package/dist/types/capabilities.d.ts.map +1 -0
  146. package/dist/types/capabilities.js +13 -0
  147. package/dist/types/capabilities.js.map +1 -0
  148. package/dist/types/chat.d.ts +74 -0
  149. package/dist/types/chat.d.ts.map +1 -0
  150. package/dist/types/chat.js +10 -0
  151. package/dist/types/chat.js.map +1 -0
  152. package/dist/types/events.d.ts +115 -0
  153. package/dist/types/events.d.ts.map +1 -0
  154. package/dist/types/events.js +30 -0
  155. package/dist/types/events.js.map +1 -0
  156. package/dist/types/llm.d.ts +89 -0
  157. package/dist/types/llm.d.ts.map +1 -0
  158. package/dist/types/llm.js +12 -0
  159. package/dist/types/llm.js.map +1 -0
  160. package/dist/types/metrics.d.ts +34 -0
  161. package/dist/types/metrics.d.ts.map +1 -0
  162. package/dist/types/metrics.js +10 -0
  163. package/dist/types/metrics.js.map +1 -0
  164. package/dist/types/observer.d.ts +41 -0
  165. package/dist/types/observer.d.ts.map +1 -0
  166. package/dist/types/observer.js +41 -0
  167. package/dist/types/observer.js.map +1 -0
  168. package/dist/types/project-context.d.ts +18 -0
  169. package/dist/types/project-context.d.ts.map +1 -0
  170. package/dist/types/project-context.js +11 -0
  171. package/dist/types/project-context.js.map +1 -0
  172. package/dist/types/runtime.d.ts +71 -0
  173. package/dist/types/runtime.d.ts.map +1 -0
  174. package/dist/types/runtime.js +21 -0
  175. package/dist/types/runtime.js.map +1 -0
  176. package/dist/types/session.d.ts +103 -0
  177. package/dist/types/session.d.ts.map +1 -0
  178. package/dist/types/session.js +11 -0
  179. package/dist/types/session.js.map +1 -0
  180. package/dist/types/storage.d.ts +20 -0
  181. package/dist/types/storage.d.ts.map +1 -0
  182. package/dist/types/storage.js +41 -0
  183. package/dist/types/storage.js.map +1 -0
  184. package/dist/types/strategy.d.ts +76 -0
  185. package/dist/types/strategy.d.ts.map +1 -0
  186. package/dist/types/strategy.js +10 -0
  187. package/dist/types/strategy.js.map +1 -0
  188. package/dist/types/tools.d.ts +136 -0
  189. package/dist/types/tools.d.ts.map +1 -0
  190. package/dist/types/tools.js +11 -0
  191. package/dist/types/tools.js.map +1 -0
  192. package/dist/types/trace.d.ts +125 -0
  193. package/dist/types/trace.d.ts.map +1 -0
  194. package/dist/types/trace.js +24 -0
  195. package/dist/types/trace.js.map +1 -0
  196. package/dist/types/workspace.d.ts +29 -0
  197. package/dist/types/workspace.d.ts.map +1 -0
  198. package/dist/types/workspace.js +18 -0
  199. package/dist/types/workspace.js.map +1 -0
  200. package/package.json +45 -14
  201. package/skills/agent-cli.md +218 -0
  202. package/index.js +0 -2
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Schema-driven arg parser. Inputs flow through `hardenString`/`hardenPath`
3
+ * per the rules declared in `spec.ts` — there is no second source of
4
+ * truth. Returns a typed `ParsedArgs` or throws `InputHardeningError`
5
+ * (already structured for NDJSON emission).
6
+ */
7
+ import { InputHardeningError, hardenPath, hardenString } from './hardening.js';
8
+ import { CLI_SPEC, findCommand } from './spec.js';
9
+ export class UsageError extends Error {
10
+ hint;
11
+ name = 'UsageError';
12
+ constructor(message, hint) {
13
+ super(message);
14
+ this.hint = hint;
15
+ }
16
+ }
17
+ function optionByFlag(flags, cmd) {
18
+ const all = [...CLI_SPEC.globalOptions, ...(cmd?.options ?? [])];
19
+ return all.find((o) => o.name === flags || o.short === flags);
20
+ }
21
+ function coerceValue(spec, raw, field, cwd) {
22
+ if (spec.type === 'boolean')
23
+ return raw === true ? true : raw !== 'false';
24
+ if (raw === true) {
25
+ throw new UsageError(`${field} requires a value`, `Pass it as --${spec.name.replace(/^--/, '')} <value>`);
26
+ }
27
+ switch (spec.type) {
28
+ case 'number': {
29
+ const n = Number(raw);
30
+ if (!Number.isFinite(n))
31
+ throw new UsageError(`${field} expects a number, got ${JSON.stringify(raw)}`);
32
+ return n;
33
+ }
34
+ case 'enum': {
35
+ if (!spec.choices?.includes(raw)) {
36
+ throw new UsageError(`${field} expects one of ${spec.choices?.join(', ')}; got ${JSON.stringify(raw)}`);
37
+ }
38
+ return raw;
39
+ }
40
+ case 'string[]': {
41
+ const items = raw
42
+ .split(',')
43
+ .map((s) => s.trim())
44
+ .filter(Boolean);
45
+ for (const item of items) {
46
+ if (spec.validate)
47
+ hardenString(field, item, spec.validate);
48
+ }
49
+ return items;
50
+ }
51
+ case 'path': {
52
+ return hardenPath(field, raw, spec.validate ?? {}, cwd);
53
+ }
54
+ case 'json': {
55
+ // The literal value here is either '-' (stdin sentinel) or a file path.
56
+ // Hardening for path-likeness applies, but we don't *resolve* — the
57
+ // command handler decides whether to read stdin or open a file.
58
+ if (raw === '-')
59
+ return '-';
60
+ return hardenPath(field, raw, { rejectControlChars: true, rejectQueryChars: true, maxLength: 1024 }, cwd);
61
+ }
62
+ case 'string':
63
+ default: {
64
+ if (spec.validate)
65
+ hardenString(field, raw, spec.validate);
66
+ return raw;
67
+ }
68
+ }
69
+ }
70
+ /**
71
+ * Parse argv into `{command, options, positional}`. The first
72
+ * non-option token is the command. Unknown flags throw `UsageError`.
73
+ */
74
+ export function parseArgs(argv, cwd = process.cwd()) {
75
+ if (argv.length === 0) {
76
+ return { command: 'help', options: {}, positional: [], remainder: [] };
77
+ }
78
+ // First positional is the command. Allow `agent --help` and `agent -h` as shortcuts to help.
79
+ let commandName = '';
80
+ let cursor = 0;
81
+ while (cursor < argv.length) {
82
+ const tok = argv[cursor];
83
+ if (tok === '--help' || tok === '-h') {
84
+ commandName = 'help';
85
+ cursor += 1;
86
+ break;
87
+ }
88
+ if (tok === '--version' || tok === '-v') {
89
+ commandName = 'version';
90
+ cursor += 1;
91
+ break;
92
+ }
93
+ if (!tok.startsWith('-')) {
94
+ commandName = tok;
95
+ cursor += 1;
96
+ break;
97
+ }
98
+ // A leading global option before the command name is allowed; rewind.
99
+ break;
100
+ }
101
+ if (!commandName) {
102
+ commandName = 'help';
103
+ }
104
+ if (!findCommand(commandName) && commandName !== 'help') {
105
+ throw new UsageError(`unknown command: ${commandName}`, `Try one of: ${CLI_SPEC.commands.map((c) => c.name).join(', ')}`);
106
+ }
107
+ const cmd = findCommand(commandName);
108
+ const options = {};
109
+ const positional = [];
110
+ while (cursor < argv.length) {
111
+ const tok = argv[cursor];
112
+ if (tok === '--') {
113
+ positional.push(...argv.slice(cursor + 1));
114
+ break;
115
+ }
116
+ if (!tok.startsWith('-')) {
117
+ positional.push(tok);
118
+ cursor += 1;
119
+ continue;
120
+ }
121
+ // Support --name=value as well as --name value.
122
+ let flag = tok;
123
+ let inlineValue;
124
+ const eq = tok.indexOf('=');
125
+ if (eq > 0) {
126
+ flag = tok.slice(0, eq);
127
+ inlineValue = tok.slice(eq + 1);
128
+ }
129
+ const spec = optionByFlag(flag, cmd);
130
+ if (!spec) {
131
+ throw new UsageError(`unknown option ${flag} for "${commandName}"`, `Run \`agent describe --target commands\` to list valid options.`);
132
+ }
133
+ const key = spec.name.replace(/^--/, '');
134
+ if (spec.type === 'boolean') {
135
+ options[key] = inlineValue ? inlineValue !== 'false' : true;
136
+ cursor += 1;
137
+ continue;
138
+ }
139
+ let raw;
140
+ if (inlineValue !== undefined) {
141
+ raw = inlineValue;
142
+ cursor += 1;
143
+ }
144
+ else {
145
+ const next = argv[cursor + 1];
146
+ if (next === undefined) {
147
+ raw = true;
148
+ cursor += 1;
149
+ }
150
+ else {
151
+ raw = next;
152
+ cursor += 2;
153
+ }
154
+ }
155
+ options[key] = coerceValue(spec, raw, flag, cwd);
156
+ }
157
+ return { command: commandName, options, positional, remainder: argv.slice(cursor) };
158
+ }
159
+ export { InputHardeningError };
160
+ //# sourceMappingURL=parse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.js","sourceRoot":"","sources":["../../src/cli/parse.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE/E,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAUlD,MAAM,OAAO,UAAW,SAAQ,KAAK;IAIxB;IAHO,IAAI,GAAG,YAAY,CAAC;IACtC,YACE,OAAe,EACN,IAAa;QAEtB,KAAK,CAAC,OAAO,CAAC,CAAC;QAFN,SAAI,GAAJ,IAAI,CAAS;IAGxB,CAAC;CACF;AAED,SAAS,YAAY,CAAC,KAAa,EAAE,GAA4B;IAC/D,MAAM,GAAG,GAAiB,CAAC,GAAG,QAAQ,CAAC,aAAa,EAAE,GAAG,CAAC,GAAG,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC;IAC/E,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,CAAC;AAChE,CAAC;AAED,SAAS,WAAW,CAClB,IAAgB,EAChB,GAAkB,EAClB,KAAa,EACb,GAAW;IAEX,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS;QAAE,OAAO,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,KAAK,OAAO,CAAC;IAC1E,IAAI,GAAG,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AC;gBACX,MAAM,IAAI,CAAC,CAAC;YACd,CAAC;iBAAM,CAAC;gBACN,GAAG,GAAG,IAAI,CAAC;gBACX,MAAM,IAAI,CAAC,CAAC;YACd,CAAC;QACH,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;IACnD,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;AACtF,CAAC;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Per-session NDJSON log writer. Every CLI run gets one file at
3
+ * `<log-dir>/<sessionId>.ndjson` (unless --no-log). Each line is one
4
+ * event from the same stream the CLI emits — session_start, turn
5
+ * events, tool_call, tool_result, sandbox_event, turn_end, session_end.
6
+ *
7
+ * The final `session_end` event carries the metrics totals so the file
8
+ * is self-contained: an agent can `tail` the last line for a summary
9
+ * or stream the whole file for a full replay.
10
+ */
11
+ import { closeSync, existsSync, mkdirSync, openSync, writeSync } from 'node:fs';
12
+ export interface SessionLog {
13
+ readonly path: string | null;
14
+ write(event: Record<string, unknown>): void;
15
+ close(): void;
16
+ }
17
+ export declare function defaultLogDir(): string;
18
+ export interface OpenSessionLogOptions {
19
+ /** Absolute or already-resolved directory. Pass null/undefined to use the default. */
20
+ logDir?: string | null;
21
+ sessionId: string;
22
+ /** When true, returns a no-op writer. */
23
+ disabled?: boolean;
24
+ /** Defaults to fs primitives; injectable for tests. */
25
+ io?: {
26
+ existsSync: typeof existsSync;
27
+ mkdirSync: typeof mkdirSync;
28
+ openSync: typeof openSync;
29
+ writeSync: typeof writeSync;
30
+ closeSync: typeof closeSync;
31
+ };
32
+ }
33
+ export declare function openSessionLog(opts: OpenSessionLogOptions): SessionLog;
34
+ //# sourceMappingURL=session-log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-log.d.ts","sourceRoot":"","sources":["../../src/cli/session-log.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAIhF,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC5C,KAAK,IAAI,IAAI,CAAC;CACf;AAQD,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED,MAAM,WAAW,qBAAqB;IACpC,sFAAsF;IACtF,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,yCAAyC;IACzC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,uDAAuD;IACvD,EAAE,CAAC,EAAE;QACH,UAAU,EAAE,OAAO,UAAU,CAAC;QAC9B,SAAS,EAAE,OAAO,SAAS,CAAC;QAC5B,QAAQ,EAAE,OAAO,QAAQ,CAAC;QAC1B,SAAS,EAAE,OAAO,SAAS,CAAC;QAC5B,SAAS,EAAE,OAAO,SAAS,CAAC;KAC7B,CAAC;CACH;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,qBAAqB,GAAG,UAAU,CAwBtE"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Per-session NDJSON log writer. Every CLI run gets one file at
3
+ * `<log-dir>/<sessionId>.ndjson` (unless --no-log). Each line is one
4
+ * event from the same stream the CLI emits — session_start, turn
5
+ * events, tool_call, tool_result, sandbox_event, turn_end, session_end.
6
+ *
7
+ * The final `session_end` event carries the metrics totals so the file
8
+ * is self-contained: an agent can `tail` the last line for a summary
9
+ * or stream the whole file for a full replay.
10
+ */
11
+ import { closeSync, existsSync, mkdirSync, openSync, writeSync } from 'node:fs';
12
+ import { homedir } from 'node:os';
13
+ import { dirname } from 'node:path';
14
+ const NOOP_LOG = {
15
+ path: null,
16
+ write() { },
17
+ close() { },
18
+ };
19
+ export function defaultLogDir() {
20
+ return `${homedir()}/.pyric/sessions`;
21
+ }
22
+ export function openSessionLog(opts) {
23
+ if (opts.disabled)
24
+ return NOOP_LOG;
25
+ const dir = opts.logDir && opts.logDir.length > 0 ? opts.logDir : defaultLogDir();
26
+ const path = `${dir.replace(/\/$/, '')}/${opts.sessionId}.ndjson`;
27
+ const io = opts.io ?? { existsSync, mkdirSync, openSync, writeSync, closeSync };
28
+ if (!io.existsSync(dir))
29
+ io.mkdirSync(dir, { recursive: true });
30
+ // Also defensively ensure the parent of `path` exists when the session id
31
+ // contains a '/' — disallowed by hardening, but cheap to guard.
32
+ const parent = dirname(path);
33
+ if (parent && !io.existsSync(parent))
34
+ io.mkdirSync(parent, { recursive: true });
35
+ const fd = io.openSync(path, 'a');
36
+ let closed = false;
37
+ return {
38
+ path,
39
+ write(event) {
40
+ if (closed)
41
+ return;
42
+ io.writeSync(fd, JSON.stringify(event) + '\n');
43
+ },
44
+ close() {
45
+ if (closed)
46
+ return;
47
+ closed = true;
48
+ io.closeSync(fd);
49
+ },
50
+ };
51
+ }
52
+ //# sourceMappingURL=session-log.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-log.js","sourceRoot":"","sources":["../../src/cli/session-log.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAChF,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQpC,MAAM,QAAQ,GAAe;IAC3B,IAAI,EAAE,IAAI;IACV,KAAK,KAAI,CAAC;IACV,KAAK,K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AK,CAAC,GAAG,IAAI,CAAC,CAAC;QACjD,CAAC;QACD,KAAK;YACH,IAAI,MAAM;gBAAE,OAAO;YACnB,MAAM,GAAG,IAAI,CAAC;YACd,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;QACnB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Single source of truth for the CLI command schema. Used for:
3
+ *
4
+ * - Runtime arg parsing (`parse.ts` consults this for option types
5
+ * and required-ness).
6
+ * - Schema introspection (`agent describe`, `agent schema`,
7
+ * `--help --json` all surface this verbatim).
8
+ * - Per-axis guarantees in the Agent DX CLI scale rubric:
9
+ * axis 3 (schema introspection): every command + option is here.
10
+ * axis 5 (input hardening): `validate` records the rules the
11
+ * parser must enforce.
12
+ * axis 6 (safety rails): the `mutating` flag marks where
13
+ * `--dry-run` MUST be honored.
14
+ */
15
+ export type OptionType = 'string' | 'number' | 'boolean' | 'string[]' | 'enum' | 'json' | 'path';
16
+ export interface OptionSpec {
17
+ name: string;
18
+ short?: string;
19
+ type: OptionType;
20
+ description: string;
21
+ default?: string | number | boolean | null;
22
+ required?: boolean;
23
+ /** For type === 'enum' */
24
+ choices?: readonly string[];
25
+ /** Hardening rules for type === 'string' | 'path' */
26
+ validate?: {
27
+ rejectControlChars?: boolean;
28
+ rejectPathTraversal?: boolean;
29
+ rejectQueryChars?: boolean;
30
+ maxLength?: number;
31
+ pattern?: string;
32
+ };
33
+ /** When true, supplying this option is destructive — covered by --dry-run. */
34
+ mutating?: boolean;
35
+ }
36
+ export interface CommandSpec {
37
+ name: string;
38
+ description: string;
39
+ /** Whether this command can change side-effects (writes session log, runs LLM, etc). */
40
+ mutating: boolean;
41
+ options: readonly OptionSpec[];
42
+ /** Free-form positional after options; documented but not destructured. */
43
+ positional?: {
44
+ name: string;
45
+ description: string;
46
+ };
47
+ examples?: readonly {
48
+ input: string;
49
+ description: string;
50
+ }[];
51
+ }
52
+ export interface CliSpec {
53
+ name: string;
54
+ version: string;
55
+ description: string;
56
+ /** Global options that apply to every subcommand. */
57
+ globalOptions: readonly OptionSpec[];
58
+ commands: readonly CommandSpec[];
59
+ }
60
+ export declare const CLI_SPEC: CliSpec;
61
+ export declare function findCommand(name: string): CommandSpec | undefined;
62
+ //# sourceMappingURL=spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spec.d.ts","sourceRoot":"","sources":["../../src/cli/spec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAEjG,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,UAAU,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;IAC3C,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,0BAA0B;IAC1B,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,qDAAqD;IACrD,QAAQ,CAAC,EAAE;QACT,kBAAkB,CAAC,EAAE,OAAO,CAAC;QAC7B,mBAAmB,CAAC,EAAE,OAAO,CAAC;QAC9B,gBAAgB,CAAC,EAAE,OAAO,CAAC;QAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,wFAAwF;IACxF,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,SAAS,UAAU,EAAE,CAAC;IA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