poe-code 3.0.258 → 3.0.259-beta.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.
Files changed (76) hide show
  1. package/dist/cli/commands/gaslight.js +84 -1
  2. package/dist/cli/commands/gaslight.js.map +1 -1
  3. package/dist/cli/poe-theme.d.ts +1 -0
  4. package/dist/cli/poe-theme.js +5 -0
  5. package/dist/cli/poe-theme.js.map +1 -0
  6. package/dist/cli/program.js +1 -0
  7. package/dist/cli/program.js.map +1 -1
  8. package/dist/index.d.ts +1 -1
  9. package/dist/index.js +2753 -1123
  10. package/dist/index.js.map +4 -4
  11. package/dist/metafile.json +1 -1
  12. package/dist/sdk/gaslight.d.ts +1 -1
  13. package/dist/sdk/gaslight.js +1 -1
  14. package/dist/sdk/gaslight.js.map +1 -1
  15. package/package.json +3 -1
  16. package/packages/agent-gaslight/dist/config.d.ts +5 -1
  17. package/packages/agent-gaslight/dist/config.js +32 -11
  18. package/packages/agent-gaslight/dist/index.d.ts +3 -2
  19. package/packages/agent-gaslight/dist/index.js +2 -1
  20. package/packages/agent-gaslight/dist/ingest.d.ts +2 -0
  21. package/packages/agent-gaslight/dist/ingest.js +486 -0
  22. package/packages/agent-gaslight/dist/run.js +1 -1
  23. package/packages/agent-gaslight/dist/types.d.ts +41 -6
  24. package/packages/agent-harness/dist/loader/run.js +6 -21
  25. package/packages/agent-script/dist/cli.d.ts +2 -3
  26. package/packages/agent-script/dist/cli.js +70 -36
  27. package/packages/agent-script/dist/example-runner.d.ts +2 -3
  28. package/packages/agent-script/dist/example-runner.js +69 -56
  29. package/packages/agent-script/dist/interp/exceptions.js +1 -1
  30. package/packages/agent-script/dist/interp/globals/object-array.d.ts +1 -1
  31. package/packages/agent-script/dist/interp/globals/object-array.js +39 -20
  32. package/packages/agent-script/dist/interp/host-bridge.js +1 -1
  33. package/packages/agent-script/dist/interp/interpreter.js +83 -17
  34. package/packages/agent-script/dist/interp/methods/array.js +25 -2
  35. package/packages/agent-script/dist/interp/methods/regex.js +1 -1
  36. package/packages/agent-script/dist/interp/promise-tracker.d.ts +16 -0
  37. package/packages/agent-script/dist/interp/promise-tracker.js +58 -0
  38. package/packages/agent-script/dist/interp/promise.js +38 -7
  39. package/packages/agent-script/dist/interp/scope.d.ts +1 -0
  40. package/packages/agent-script/dist/interp/scope.js +3 -0
  41. package/packages/agent-script/dist/interp/values.js +2 -0
  42. package/packages/agent-script/dist/lint/index.d.ts +2 -0
  43. package/packages/agent-script/dist/lint/index.js +2 -0
  44. package/packages/agent-script/dist/lint/rules/AS-export-import-meta.d.ts +6 -1
  45. package/packages/agent-script/dist/lint/rules/AS-export-import-meta.js +33 -4
  46. package/packages/agent-script/dist/modules/agent.js +10 -1
  47. package/packages/agent-script/dist/modules/log.js +5 -1
  48. package/packages/agent-script/dist/modules/registry.js +9 -3
  49. package/packages/agent-script/dist/output-stream.d.ts +12 -0
  50. package/packages/agent-script/dist/output-stream.js +50 -0
  51. package/packages/agent-script/dist/parse/parser.d.ts +1 -1
  52. package/packages/agent-script/dist/parse/parser.js +151 -45
  53. package/packages/agent-script/dist/parse/tokenizer.js +26 -3
  54. package/packages/agent-script/dist/run.js +14 -3
  55. package/packages/agent-script/dist/runner/run-harness.js +28 -5
  56. package/packages/agent-traces/dist/collect.d.ts +4 -0
  57. package/packages/agent-traces/dist/collect.js +102 -0
  58. package/packages/agent-traces/dist/index.d.ts +4 -0
  59. package/packages/agent-traces/dist/index.js +3 -0
  60. package/packages/agent-traces/dist/jsonl.d.ts +2 -0
  61. package/packages/agent-traces/dist/jsonl.js +7 -0
  62. package/packages/agent-traces/dist/line-json.d.ts +4 -0
  63. package/packages/agent-traces/dist/line-json.js +40 -0
  64. package/packages/agent-traces/dist/readers/claude.d.ts +2 -0
  65. package/packages/agent-traces/dist/readers/claude.js +192 -0
  66. package/packages/agent-traces/dist/readers/codex.d.ts +2 -0
  67. package/packages/agent-traces/dist/readers/codex.js +266 -0
  68. package/packages/agent-traces/dist/readers/index.d.ts +5 -0
  69. package/packages/agent-traces/dist/readers/index.js +4 -0
  70. package/packages/agent-traces/dist/types.d.ts +84 -0
  71. package/packages/agent-traces/dist/types.js +1 -0
  72. package/packages/package-lint/dist/model.js +5 -1
  73. package/packages/package-lint/dist/source-imports.d.ts +11 -1
  74. package/packages/package-lint/dist/source-imports.js +30 -4
  75. package/packages/tiny-stdio-mcp-test-server/dist/cli.js +41 -0
  76. package/packages/tiny-stdio-mcp-test-server/dist/index.js +8 -0
@@ -0,0 +1,84 @@
1
+ export type AgentTraceSource = "claude" | "codex";
2
+ export interface AgentTraceFileSystem {
3
+ readFile(path: string, encoding: BufferEncoding): Promise<string>;
4
+ writeFile(path: string, data: string, options?: {
5
+ encoding?: BufferEncoding;
6
+ }): Promise<void>;
7
+ mkdir(path: string, options?: {
8
+ recursive?: boolean;
9
+ }): Promise<unknown>;
10
+ readdir(path: string): Promise<string[]>;
11
+ stat(path: string): Promise<{
12
+ isFile(): boolean;
13
+ isDirectory(): boolean;
14
+ mtime?: Date;
15
+ }>;
16
+ }
17
+ export interface SqliteTraceDatabase {
18
+ all(sql: string, params: unknown[]): unknown[] | Promise<unknown[]>;
19
+ close(): void | Promise<void>;
20
+ }
21
+ export type SqliteTraceDatabaseFactory = (path: string) => Promise<SqliteTraceDatabase>;
22
+ export interface TraceDiscoverOptions {
23
+ cwd?: string;
24
+ homeDir: string;
25
+ since?: Date;
26
+ allWorkspaces?: boolean;
27
+ fs: AgentTraceFileSystem;
28
+ sqlite?: SqliteTraceDatabaseFactory;
29
+ }
30
+ export type TraceReadOptions = Pick<TraceDiscoverOptions, "fs">;
31
+ export interface TraceReference {
32
+ source: AgentTraceSource;
33
+ id: string;
34
+ path?: string;
35
+ cwd?: string;
36
+ updatedAt?: Date;
37
+ title?: string;
38
+ metadata?: Record<string, unknown>;
39
+ }
40
+ export interface NormalizedTrace {
41
+ source: AgentTraceSource;
42
+ id: string;
43
+ path?: string;
44
+ cwd?: string;
45
+ title?: string;
46
+ createdAt?: Date;
47
+ updatedAt?: Date;
48
+ turns: NormalizedTraceTurn[];
49
+ }
50
+ export interface NormalizedTraceTurn {
51
+ id?: string;
52
+ role: "human" | "assistant" | "tool" | "system";
53
+ text: string;
54
+ timestamp?: Date;
55
+ sourceKind?: string;
56
+ }
57
+ export interface HumanPromptRecord {
58
+ traceId: string;
59
+ source: AgentTraceSource;
60
+ cwd?: string;
61
+ title?: string;
62
+ timestamp?: string;
63
+ text: string;
64
+ }
65
+ export interface CollectHumanPromptsOptions {
66
+ sources?: AgentTraceSource[];
67
+ cwd?: string;
68
+ homeDir?: string;
69
+ since?: Date;
70
+ limit?: number;
71
+ allWorkspaces?: boolean;
72
+ fs?: AgentTraceFileSystem;
73
+ sqlite?: SqliteTraceDatabaseFactory;
74
+ }
75
+ export interface CollectHumanPromptsResult {
76
+ records: HumanPromptRecord[];
77
+ traceCount: number;
78
+ }
79
+ export interface TraceReader {
80
+ id: AgentTraceSource;
81
+ defaultRoots(homeDir: string): string[];
82
+ discover(options: TraceDiscoverOptions): Promise<TraceReference[]>;
83
+ read(reference: TraceReference, options: TraceReadOptions): Promise<NormalizedTrace>;
84
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -190,7 +190,11 @@ export async function loadWorkspace(fs, rootDir) {
190
190
  for (const p of packages)
191
191
  byDir.set(p.dir, p);
192
192
  const { shippedDirs, binTargets } = deriveShipped(root);
193
- const sourceImports = await scanSourceImports(fs, rootDir, packages.map((p) => p.dir));
193
+ const workspaceNames = new Set(packages.map((p) => p.name));
194
+ const sourceImports = await scanSourceImports(fs, rootDir, packages.map((pkg) => ({
195
+ dir: pkg.dir,
196
+ workspaceNames: new Set([...workspaceNames].filter((name) => name !== pkg.name))
197
+ })));
194
198
  return {
195
199
  root,
196
200
  packages,
@@ -17,10 +17,20 @@ export interface ImportRef {
17
17
  }
18
18
  /** Imports found in each workspace package, keyed by the package dir (posix). */
19
19
  export type SourceImportView = Map<string, ImportRef[]>;
20
+ interface RawImport {
21
+ specifier: string;
22
+ typeOnly: boolean;
23
+ }
24
+ export declare function extractRelevantImports(text: string, fileName: string): RawImport[];
25
+ export declare function mayContainRelevantImport(source: string, workspaceNames: ReadonlySet<string>): boolean;
20
26
  /**
21
27
  * Parse the real import graph of every workspace package's `src`, using the
22
28
  * TypeScript compiler's own parser (the engine typescript-eslint runs on). The
23
29
  * result feeds the import-driven rules — what code actually imports, not what
24
30
  * package.json declares.
25
31
  */
26
- export declare function scanSourceImports(fs: LintFs, rootDir: string, packageDirs: string[]): Promise<SourceImportView>;
32
+ export declare function scanSourceImports(fs: LintFs, rootDir: string, packages: Array<{
33
+ dir: string;
34
+ workspaceNames: ReadonlySet<string>;
35
+ }>): Promise<SourceImportView>;
36
+ export {};
@@ -14,7 +14,7 @@ function isTestFile(relFile) {
14
14
  const segments = relFile.split("/");
15
15
  return segments.some((s) => s === "test" || s === "tests" || s === "__tests__");
16
16
  }
17
- function extractImports(text, fileName) {
17
+ function extractImportsFromAst(text, fileName) {
18
18
  const sourceFile = ts.createSourceFile(fileName, text, ts.ScriptTarget.Latest, false, fileName.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
19
19
  const out = [];
20
20
  for (const statement of sourceFile.statements) {
@@ -61,6 +61,15 @@ function extractImports(text, fileName) {
61
61
  visit(sourceFile);
62
62
  return out;
63
63
  }
64
+ export function extractRelevantImports(text, fileName) {
65
+ if (text.includes("import type") || text.includes("export type") || text.includes("{ type ")) {
66
+ return extractImportsFromAst(text, fileName);
67
+ }
68
+ return ts.preProcessFile(text, true, true).importedFiles.map(({ fileName: specifier }) => ({
69
+ specifier,
70
+ typeOnly: false
71
+ }));
72
+ }
64
73
  async function listSourceFiles(fs, dir) {
65
74
  let entries;
66
75
  try {
@@ -82,6 +91,20 @@ async function listSourceFiles(fs, dir) {
82
91
  }
83
92
  return files;
84
93
  }
94
+ export function mayContainRelevantImport(source, workspaceNames) {
95
+ const imports = ts.preProcessFile(source, true, true).importedFiles;
96
+ for (const { fileName } of imports) {
97
+ if (fileName.startsWith("../")) {
98
+ return true;
99
+ }
100
+ for (const packageName of workspaceNames) {
101
+ if (fileName === packageName || fileName.startsWith(`${packageName}/`)) {
102
+ return true;
103
+ }
104
+ }
105
+ }
106
+ return false;
107
+ }
85
108
  function classify(raw, rootDir, packageDir, absFile, relFile) {
86
109
  const base = {
87
110
  file: relFile,
@@ -116,9 +139,9 @@ function classify(raw, rootDir, packageDir, absFile, relFile) {
116
139
  * result feeds the import-driven rules — what code actually imports, not what
117
140
  * package.json declares.
118
141
  */
119
- export async function scanSourceImports(fs, rootDir, packageDirs) {
142
+ export async function scanSourceImports(fs, rootDir, packages) {
120
143
  const view = new Map();
121
- await Promise.all(packageDirs.map(async (packageDir) => {
144
+ await Promise.all(packages.map(async ({ dir: packageDir, workspaceNames }) => {
122
145
  const srcDir = path.join(rootDir, packageDir, "src");
123
146
  const files = await listSourceFiles(fs, srcDir);
124
147
  const refs = [];
@@ -130,8 +153,11 @@ export async function scanSourceImports(fs, rootDir, packageDirs) {
130
153
  catch {
131
154
  continue;
132
155
  }
156
+ if (!mayContainRelevantImport(text, workspaceNames)) {
157
+ continue;
158
+ }
133
159
  const relFile = toPosix(path.relative(rootDir, absFile));
134
- for (const raw of extractImports(text, absFile)) {
160
+ for (const raw of extractRelevantImports(text, absFile)) {
135
161
  refs.push(classify(raw, rootDir, packageDir, absFile, relFile));
136
162
  }
137
163
  }
@@ -2,6 +2,8 @@
2
2
 
3
3
  // packages/tiny-stdio-mcp-test-server/src/cli.ts
4
4
  import { Command } from "commander";
5
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
6
+ import { access } from "node:fs/promises";
5
7
 
6
8
  // packages/tiny-stdio-mcp-test-server/package.json
7
9
  var package_default = {
@@ -1223,6 +1225,7 @@ function defineSchema(definition) {
1223
1225
  }
1224
1226
 
1225
1227
  // packages/tiny-stdio-mcp-test-server/src/index.ts
1228
+ import { appendFileSync } from "node:fs";
1226
1229
  var SERVER_NAME = "tiny-stdio-mcp-test-server";
1227
1230
  var SERVER_VERSION = package_default.version;
1228
1231
  var caesarCipherSchema = defineSchema({
@@ -1262,11 +1265,19 @@ function createEncryptServer() {
1262
1265
  "Encrypts text using the Caesar cipher",
1263
1266
  caesarCipherSchema,
1264
1267
  ({ text, shift }) => {
1268
+ recordToolCall("caesar_cipher_encrypt");
1265
1269
  const actualShift = shift ?? 3;
1266
1270
  return caesarEncrypt(text, actualShift);
1267
1271
  }
1268
1272
  );
1269
1273
  }
1274
+ function recordToolCall(name) {
1275
+ const filePath = process.env.TOOLCRAFT_TEST_TOOL_CALL_FILE;
1276
+ if (filePath !== void 0) {
1277
+ appendFileSync(filePath, `${name}
1278
+ `);
1279
+ }
1280
+ }
1270
1281
  function createWordOfTheDayServer() {
1271
1282
  return createServer({
1272
1283
  name: SERVER_NAME,
@@ -1285,6 +1296,15 @@ function createWordOfTheDayServer() {
1285
1296
  var program = new Command();
1286
1297
  program.name("tiny-stdio-mcp-test-server").description("Test MCP server with example tools for integration testing").version(package_default.version);
1287
1298
  program.command("serve").description("Start an MCP server on stdin/stdout").argument("<tool>", "Tool to serve (encrypt, word-of-the-day)").action(async (tool) => {
1299
+ recordProcessStart();
1300
+ const startupDelayMs = Number(process.env.TOOLCRAFT_TEST_STARTUP_DELAY_MS ?? "0");
1301
+ if (startupDelayMs > 0) {
1302
+ await new Promise((resolve) => setTimeout(resolve, startupDelayMs));
1303
+ }
1304
+ const startupGateFile = process.env.TOOLCRAFT_TEST_STARTUP_GATE_FILE;
1305
+ if (startupGateFile !== void 0) {
1306
+ await waitForFile(startupGateFile);
1307
+ }
1288
1308
  const servers = /* @__PURE__ */ Object.create(null);
1289
1309
  Object.assign(servers, {
1290
1310
  encrypt: () => createEncryptServer().listen(),
@@ -1299,3 +1319,24 @@ program.command("serve").description("Start an MCP server on stdin/stdout").argu
1299
1319
  await start();
1300
1320
  });
1301
1321
  program.parse();
1322
+ function recordProcessStart() {
1323
+ const countFile = process.env.TOOLCRAFT_TEST_SPAWN_COUNT_FILE;
1324
+ if (countFile !== void 0) {
1325
+ const previousCount = existsSync(countFile) ? Number.parseInt(readFileSync(countFile, "utf8").trim() || "0", 10) : 0;
1326
+ writeFileSync(countFile, String(previousCount + 1));
1327
+ }
1328
+ const pidFile = process.env.TOOLCRAFT_TEST_WRAPPER_PID_FILE;
1329
+ if (pidFile !== void 0) {
1330
+ writeFileSync(pidFile, String(process.pid));
1331
+ }
1332
+ }
1333
+ async function waitForFile(filePath) {
1334
+ while (true) {
1335
+ try {
1336
+ await access(filePath);
1337
+ return;
1338
+ } catch {
1339
+ await new Promise((resolve) => setTimeout(resolve, 5));
1340
+ }
1341
+ }
1342
+ }
@@ -1,4 +1,5 @@
1
1
  import { createServer, defineSchema } from "tiny-stdio-mcp-server";
2
+ import { appendFileSync } from "node:fs";
2
3
  import packageJson from "../package.json" with { type: "json" };
3
4
  const SERVER_NAME = "tiny-stdio-mcp-test-server";
4
5
  const SERVER_VERSION = packageJson.version;
@@ -34,10 +35,17 @@ export function createEncryptServer() {
34
35
  name: SERVER_NAME,
35
36
  version: SERVER_VERSION,
36
37
  }).tool("caesar_cipher_encrypt", "Encrypts text using the Caesar cipher", caesarCipherSchema, ({ text, shift }) => {
38
+ recordToolCall("caesar_cipher_encrypt");
37
39
  const actualShift = shift ?? 3;
38
40
  return caesarEncrypt(text, actualShift);
39
41
  });
40
42
  }
43
+ function recordToolCall(name) {
44
+ const filePath = process.env.TOOLCRAFT_TEST_TOOL_CALL_FILE;
45
+ if (filePath !== undefined) {
46
+ appendFileSync(filePath, `${name}\n`);
47
+ }
48
+ }
41
49
  export function createWordOfTheDayServer() {
42
50
  return createServer({
43
51
  name: SERVER_NAME,