@equinor/fusion-framework-cli-plugin-copilot 1.0.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.
- package/CHANGELOG.md +24 -0
- package/LICENSE +21 -0
- package/README.md +228 -0
- package/dist/esm/commands/app/command.js +176 -0
- package/dist/esm/commands/app/command.js.map +1 -0
- package/dist/esm/commands/app/eval.js +92 -0
- package/dist/esm/commands/app/eval.js.map +1 -0
- package/dist/esm/commands/app/format.js +93 -0
- package/dist/esm/commands/app/format.js.map +1 -0
- package/dist/esm/commands/app/login.js +71 -0
- package/dist/esm/commands/app/login.js.map +1 -0
- package/dist/esm/commands/app/prompts/execute-step.prompt.js +44 -0
- package/dist/esm/commands/app/prompts/execute-step.prompt.js.map +1 -0
- package/dist/esm/commands/app/prompts/judge.prompt.js +116 -0
- package/dist/esm/commands/app/prompts/judge.prompt.js.map +1 -0
- package/dist/esm/commands/app/prompts/plan.prompt.js +47 -0
- package/dist/esm/commands/app/prompts/plan.prompt.js.map +1 -0
- package/dist/esm/commands/app/prompts/step.prompt.js +42 -0
- package/dist/esm/commands/app/prompts/step.prompt.js.map +1 -0
- package/dist/esm/commands/app/prompts/system.dev-server.prompt.js +21 -0
- package/dist/esm/commands/app/prompts/system.dev-server.prompt.js.map +1 -0
- package/dist/esm/commands/app/prompts/system.prompt.js +77 -0
- package/dist/esm/commands/app/prompts/system.prompt.js.map +1 -0
- package/dist/esm/commands/app/server.js +83 -0
- package/dist/esm/commands/app/server.js.map +1 -0
- package/dist/esm/commands/app/session-logger.js +171 -0
- package/dist/esm/commands/app/session-logger.js.map +1 -0
- package/dist/esm/commands/app/tools/click.js +27 -0
- package/dist/esm/commands/app/tools/click.js.map +1 -0
- package/dist/esm/commands/app/tools/errors.js +24 -0
- package/dist/esm/commands/app/tools/errors.js.map +1 -0
- package/dist/esm/commands/app/tools/eval-js.js +36 -0
- package/dist/esm/commands/app/tools/eval-js.js.map +1 -0
- package/dist/esm/commands/app/tools/fill.js +28 -0
- package/dist/esm/commands/app/tools/fill.js.map +1 -0
- package/dist/esm/commands/app/tools/find.js +44 -0
- package/dist/esm/commands/app/tools/find.js.map +1 -0
- package/dist/esm/commands/app/tools/get-styles.js +36 -0
- package/dist/esm/commands/app/tools/get-styles.js.map +1 -0
- package/dist/esm/commands/app/tools/get-url.js +24 -0
- package/dist/esm/commands/app/tools/get-url.js.map +1 -0
- package/dist/esm/commands/app/tools/go-back.js +15 -0
- package/dist/esm/commands/app/tools/go-back.js.map +1 -0
- package/dist/esm/commands/app/tools/hover.js +24 -0
- package/dist/esm/commands/app/tools/hover.js.map +1 -0
- package/dist/esm/commands/app/tools/index.js +32 -0
- package/dist/esm/commands/app/tools/index.js.map +1 -0
- package/dist/esm/commands/app/tools/navigate.js +31 -0
- package/dist/esm/commands/app/tools/navigate.js.map +1 -0
- package/dist/esm/commands/app/tools/press-key.js +24 -0
- package/dist/esm/commands/app/tools/press-key.js.map +1 -0
- package/dist/esm/commands/app/tools/read-file.js +98 -0
- package/dist/esm/commands/app/tools/read-file.js.map +1 -0
- package/dist/esm/commands/app/tools/registry.js +34 -0
- package/dist/esm/commands/app/tools/registry.js.map +1 -0
- package/dist/esm/commands/app/tools/reload.js +15 -0
- package/dist/esm/commands/app/tools/reload.js.map +1 -0
- package/dist/esm/commands/app/tools/screenshot.js +133 -0
- package/dist/esm/commands/app/tools/screenshot.js.map +1 -0
- package/dist/esm/commands/app/tools/scroll.js +41 -0
- package/dist/esm/commands/app/tools/scroll.js.map +1 -0
- package/dist/esm/commands/app/tools/select.js +25 -0
- package/dist/esm/commands/app/tools/select.js.map +1 -0
- package/dist/esm/commands/app/tools/snapshot.js +24 -0
- package/dist/esm/commands/app/tools/snapshot.js.map +1 -0
- package/dist/esm/commands/app/tools/type-text.js +29 -0
- package/dist/esm/commands/app/tools/type-text.js.map +1 -0
- package/dist/esm/commands/app/tools/types.js +2 -0
- package/dist/esm/commands/app/tools/types.js.map +1 -0
- package/dist/esm/commands/app/tools/wait.js +39 -0
- package/dist/esm/commands/app/tools/wait.js.map +1 -0
- package/dist/esm/commands/app/tools/write-file.js +98 -0
- package/dist/esm/commands/app/tools/write-file.js.map +1 -0
- package/dist/esm/commands/app/types.js +2 -0
- package/dist/esm/commands/app/types.js.map +1 -0
- package/dist/esm/eval-resolve.js +83 -0
- package/dist/esm/eval-resolve.js.map +1 -0
- package/dist/esm/index.js +18 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/utils/agent-browser.js +67 -0
- package/dist/esm/utils/agent-browser.js.map +1 -0
- package/dist/esm/utils/browser-poll.js +26 -0
- package/dist/esm/utils/browser-poll.js.map +1 -0
- package/dist/esm/utils/daemon.js +83 -0
- package/dist/esm/utils/daemon.js.map +1 -0
- package/dist/esm/utils/index.js +6 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/utils/process.js +30 -0
- package/dist/esm/utils/process.js.map +1 -0
- package/dist/esm/utils/server.js +65 -0
- package/dist/esm/utils/server.js.map +1 -0
- package/dist/esm/version.js +3 -0
- package/dist/esm/version.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/commands/app/command.d.ts +7 -0
- package/dist/types/commands/app/eval.d.ts +9 -0
- package/dist/types/commands/app/format.d.ts +14 -0
- package/dist/types/commands/app/login.d.ts +14 -0
- package/dist/types/commands/app/prompts/execute-step.prompt.d.ts +13 -0
- package/dist/types/commands/app/prompts/judge.prompt.d.ts +15 -0
- package/dist/types/commands/app/prompts/plan.prompt.d.ts +13 -0
- package/dist/types/commands/app/prompts/step.prompt.d.ts +12 -0
- package/dist/types/commands/app/prompts/system.dev-server.prompt.d.ts +12 -0
- package/dist/types/commands/app/prompts/system.prompt.d.ts +12 -0
- package/dist/types/commands/app/server.d.ts +26 -0
- package/dist/types/commands/app/session-logger.d.ts +14 -0
- package/dist/types/commands/app/tools/click.d.ts +9 -0
- package/dist/types/commands/app/tools/errors.d.ts +9 -0
- package/dist/types/commands/app/tools/eval-js.d.ts +13 -0
- package/dist/types/commands/app/tools/fill.d.ts +9 -0
- package/dist/types/commands/app/tools/find.d.ts +9 -0
- package/dist/types/commands/app/tools/get-styles.d.ts +13 -0
- package/dist/types/commands/app/tools/get-url.d.ts +9 -0
- package/dist/types/commands/app/tools/go-back.d.ts +9 -0
- package/dist/types/commands/app/tools/hover.d.ts +9 -0
- package/dist/types/commands/app/tools/index.d.ts +9 -0
- package/dist/types/commands/app/tools/navigate.d.ts +9 -0
- package/dist/types/commands/app/tools/press-key.d.ts +9 -0
- package/dist/types/commands/app/tools/read-file.d.ts +13 -0
- package/dist/types/commands/app/tools/registry.d.ts +28 -0
- package/dist/types/commands/app/tools/reload.d.ts +9 -0
- package/dist/types/commands/app/tools/screenshot.d.ts +9 -0
- package/dist/types/commands/app/tools/scroll.d.ts +9 -0
- package/dist/types/commands/app/tools/select.d.ts +9 -0
- package/dist/types/commands/app/tools/snapshot.d.ts +9 -0
- package/dist/types/commands/app/tools/type-text.d.ts +9 -0
- package/dist/types/commands/app/tools/types.d.ts +12 -0
- package/dist/types/commands/app/tools/wait.d.ts +9 -0
- package/dist/types/commands/app/tools/write-file.d.ts +19 -0
- package/dist/types/commands/app/types.d.ts +68 -0
- package/dist/types/eval-resolve.d.ts +31 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/utils/agent-browser.d.ts +26 -0
- package/dist/types/utils/browser-poll.d.ts +9 -0
- package/dist/types/utils/daemon.d.ts +16 -0
- package/dist/types/utils/index.d.ts +5 -0
- package/dist/types/utils/process.d.ts +21 -0
- package/dist/types/utils/server.d.ts +26 -0
- package/dist/types/version.d.ts +1 -0
- package/package.json +57 -0
- package/src/commands/app/command.ts +204 -0
- package/src/commands/app/eval.ts +114 -0
- package/src/commands/app/format.ts +110 -0
- package/src/commands/app/login.ts +92 -0
- package/src/commands/app/prompts/execute-step.prompt.ts +48 -0
- package/src/commands/app/prompts/judge.prompt.ts +121 -0
- package/src/commands/app/prompts/plan.prompt.ts +48 -0
- package/src/commands/app/prompts/step.prompt.ts +45 -0
- package/src/commands/app/prompts/system.dev-server.prompt.ts +22 -0
- package/src/commands/app/prompts/system.prompt.ts +78 -0
- package/src/commands/app/server.ts +105 -0
- package/src/commands/app/session-logger.ts +187 -0
- package/src/commands/app/tools/click.ts +28 -0
- package/src/commands/app/tools/errors.ts +26 -0
- package/src/commands/app/tools/eval-js.ts +40 -0
- package/src/commands/app/tools/fill.ts +29 -0
- package/src/commands/app/tools/find.ts +49 -0
- package/src/commands/app/tools/get-styles.ts +40 -0
- package/src/commands/app/tools/get-url.ts +26 -0
- package/src/commands/app/tools/go-back.ts +16 -0
- package/src/commands/app/tools/hover.ts +25 -0
- package/src/commands/app/tools/index.ts +57 -0
- package/src/commands/app/tools/navigate.ts +32 -0
- package/src/commands/app/tools/press-key.ts +25 -0
- package/src/commands/app/tools/read-file.ts +113 -0
- package/src/commands/app/tools/registry.ts +38 -0
- package/src/commands/app/tools/reload.ts +16 -0
- package/src/commands/app/tools/screenshot.ts +168 -0
- package/src/commands/app/tools/scroll.ts +45 -0
- package/src/commands/app/tools/select.ts +26 -0
- package/src/commands/app/tools/snapshot.ts +27 -0
- package/src/commands/app/tools/type-text.ts +30 -0
- package/src/commands/app/tools/types.ts +15 -0
- package/src/commands/app/tools/wait.ts +43 -0
- package/src/commands/app/tools/write-file.ts +104 -0
- package/src/commands/app/types.ts +76 -0
- package/src/eval-resolve.ts +113 -0
- package/src/index.ts +20 -0
- package/src/utils/agent-browser.ts +66 -0
- package/src/utils/browser-poll.ts +27 -0
- package/src/utils/daemon.ts +84 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/process.ts +33 -0
- package/src/utils/server.ts +66 -0
- package/src/version.ts +2 -0
- package/tsconfig.json +13 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { existsSync, readdirSync, statSync } from 'node:fs';
|
|
2
|
+
import { basename, dirname, extname, isAbsolute, join, resolve } from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* Prints a CLI resolution error and exits the current process.
|
|
5
|
+
*
|
|
6
|
+
* @param message - Primary error message.
|
|
7
|
+
* @param detail - Optional follow-up detail shown on the next line.
|
|
8
|
+
* @returns This function never returns because the process exits.
|
|
9
|
+
*/
|
|
10
|
+
function exitWithResolutionError(message, detail) {
|
|
11
|
+
console.error(`❌ ${message}`);
|
|
12
|
+
if (detail) {
|
|
13
|
+
console.error(` ${detail}`);
|
|
14
|
+
}
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Resolves the positional `copilot app eval` argument.
|
|
19
|
+
*
|
|
20
|
+
* Supports both application directory paths and direct paths to markdown files
|
|
21
|
+
* inside an application's `eval/` directory.
|
|
22
|
+
*
|
|
23
|
+
* @param inputPath - Positional CLI argument passed to the eval command.
|
|
24
|
+
* @returns Normalized application path and optional direct eval file path.
|
|
25
|
+
*/
|
|
26
|
+
export function resolveEvalCommandInput(inputPath) {
|
|
27
|
+
const absInput = resolve(inputPath);
|
|
28
|
+
if (extname(absInput) !== '.md') {
|
|
29
|
+
return { appPath: absInput };
|
|
30
|
+
}
|
|
31
|
+
if (!existsSync(absInput)) {
|
|
32
|
+
exitWithResolutionError(`Eval file not found: ${absInput}`);
|
|
33
|
+
}
|
|
34
|
+
if (!statSync(absInput).isFile()) {
|
|
35
|
+
exitWithResolutionError(`Eval path is not a file: ${absInput}`);
|
|
36
|
+
}
|
|
37
|
+
const evalDir = dirname(absInput);
|
|
38
|
+
if (basename(evalDir) !== 'eval') {
|
|
39
|
+
exitWithResolutionError(`Direct eval file path must point to a markdown file inside an eval directory: ${absInput}`);
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
appPath: dirname(evalDir),
|
|
43
|
+
evalFile: absInput,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Resolves eval markdown files for a Fusion application.
|
|
48
|
+
*
|
|
49
|
+
* @param appPath - Path to the Fusion application directory
|
|
50
|
+
* @param evalOpt - Value of the `--eval` CLI option (name, path, or `undefined`)
|
|
51
|
+
* @returns Array of absolute paths to eval markdown files
|
|
52
|
+
*/
|
|
53
|
+
export function resolveEvalFiles(appPath, evalOpt) {
|
|
54
|
+
const absApp = resolve(appPath);
|
|
55
|
+
if (!evalOpt) {
|
|
56
|
+
const evalDir = join(absApp, 'eval');
|
|
57
|
+
if (!existsSync(evalDir)) {
|
|
58
|
+
exitWithResolutionError(`No eval directory found at ${evalDir}`, 'Create eval/*.md files or use --eval <file>');
|
|
59
|
+
}
|
|
60
|
+
const files = readdirSync(evalDir)
|
|
61
|
+
.filter((f) => f.endsWith('.md'))
|
|
62
|
+
.sort()
|
|
63
|
+
.map((f) => join(evalDir, f));
|
|
64
|
+
if (files.length === 0) {
|
|
65
|
+
exitWithResolutionError(`No .md files found in ${evalDir}`);
|
|
66
|
+
}
|
|
67
|
+
return files;
|
|
68
|
+
}
|
|
69
|
+
if (isAbsolute(evalOpt) || evalOpt.includes('/') || evalOpt.includes('\\')) {
|
|
70
|
+
const absPath = isAbsolute(evalOpt) ? evalOpt : resolve(evalOpt);
|
|
71
|
+
if (!existsSync(absPath)) {
|
|
72
|
+
exitWithResolutionError(`Eval file not found: ${absPath}`);
|
|
73
|
+
}
|
|
74
|
+
return [absPath];
|
|
75
|
+
}
|
|
76
|
+
const evalFileName = extname(evalOpt) === '.md' ? evalOpt : `${evalOpt}.md`;
|
|
77
|
+
const evalFile = join(absApp, 'eval', evalFileName);
|
|
78
|
+
if (!existsSync(evalFile)) {
|
|
79
|
+
exitWithResolutionError(`Eval file not found: ${evalFile}`);
|
|
80
|
+
}
|
|
81
|
+
return [evalFile];
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=eval-resolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eval-resolve.js","sourceRoot":"","sources":["../../src/eval-resolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ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AC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,KAAK,CAAC;IAC5E,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;IACpD,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1B,uBAAuB,CAAC,wBAAwB,QAAQ,EAAE,CAAC,CAAC;IAC9D,CAAC;IACD,OAAO,CAAC,QAAQ,CAAC,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { copilotCommand } from './commands/app/command.js';
|
|
2
|
+
/**
|
|
3
|
+
* Registers the `copilot` CLI plugin with the Fusion Framework CLI.
|
|
4
|
+
*
|
|
5
|
+
* Attaches the top-level `copilot` command group, providing Copilot SDK
|
|
6
|
+
* powered evaluation tools with agent-browser.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* ffc copilot app eval ./cookbooks/app-react
|
|
10
|
+
* ffc copilot app eval . --eval smoke --model claude-sonnet-4
|
|
11
|
+
*
|
|
12
|
+
* @param program - The root Commander program instance
|
|
13
|
+
*/
|
|
14
|
+
export function registerCopilotPlugin(program) {
|
|
15
|
+
program.addCommand(copilotCommand);
|
|
16
|
+
}
|
|
17
|
+
export default registerCopilotPlugin;
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAgB;IACpD,OAAO,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;AACrC,CAAC;AAED,eAAe,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, unlinkSync } from 'node:fs';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
/** Persistent Chrome profile directory used across agent-browser sessions. */
|
|
6
|
+
export const PROFILE_DIR = `${homedir()}/.fusion-smoke-profile`;
|
|
7
|
+
/**
|
|
8
|
+
* Runs an agent-browser command with the persistent Chrome profile.
|
|
9
|
+
*
|
|
10
|
+
* Calls the `agent-browser` binary resolved from `PATH` (homebrew or npm global).
|
|
11
|
+
* Every invocation automatically injects `--profile <PROFILE_DIR>` so browser
|
|
12
|
+
* state (cookies, session storage, MSAL tokens) persists across calls.
|
|
13
|
+
*
|
|
14
|
+
* @param args - Subcommand and arguments passed directly to `agent-browser`
|
|
15
|
+
* @param timeoutMs - Maximum execution time in milliseconds (default: 30 000)
|
|
16
|
+
* @returns Trimmed stdout from the command
|
|
17
|
+
* @throws {Error} When `agent-browser` exits with a non-zero code or times out
|
|
18
|
+
*/
|
|
19
|
+
export function ab(args, timeoutMs = 30_000) {
|
|
20
|
+
// Remove stale SingletonLock left by a previous Chrome crash to prevent
|
|
21
|
+
// "Failed to create SingletonLock: File exists" errors.
|
|
22
|
+
const lockPath = join(PROFILE_DIR, 'SingletonLock');
|
|
23
|
+
if (existsSync(lockPath)) {
|
|
24
|
+
try {
|
|
25
|
+
unlinkSync(lockPath);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
// Best-effort — if we can't remove it Chrome will fail with a clear message anyway.
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const fullArgs = ['--profile', PROFILE_DIR, ...args];
|
|
32
|
+
return execFileSync('agent-browser', fullArgs, {
|
|
33
|
+
encoding: 'utf-8',
|
|
34
|
+
timeout: timeoutMs,
|
|
35
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
36
|
+
cwd: process.cwd(),
|
|
37
|
+
}).trim();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Extracts the user-facing error message from an agent-browser failure.
|
|
41
|
+
*
|
|
42
|
+
* Strips ANSI escape codes from stderr and returns only the diagnostic
|
|
43
|
+
* lines prefixed with `✗` or `⚠`. Falls back to the first 200 characters
|
|
44
|
+
* of the error message when no diagnostic lines are found.
|
|
45
|
+
*
|
|
46
|
+
* @param err - The caught error (typically from {@link ab})
|
|
47
|
+
* @returns A single-line summary suitable for console output
|
|
48
|
+
*/
|
|
49
|
+
export function abErrorMessage(err) {
|
|
50
|
+
if (!(err instanceof Error))
|
|
51
|
+
return String(err);
|
|
52
|
+
const e = err;
|
|
53
|
+
if (e.stderr) {
|
|
54
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: stripping ANSI escape sequences
|
|
55
|
+
const ansiPattern = /\x1B\[[0-9;]*m/g;
|
|
56
|
+
const lines = e.stderr
|
|
57
|
+
.replace(ansiPattern, '')
|
|
58
|
+
.split('\n')
|
|
59
|
+
.map((l) => l.trim())
|
|
60
|
+
.filter((l) => l.startsWith('✗') || l.startsWith('⚠'));
|
|
61
|
+
if (lines.length)
|
|
62
|
+
return lines.join(' | ');
|
|
63
|
+
}
|
|
64
|
+
const match = e.message.match(/[✗⚠].+/);
|
|
65
|
+
return match ? match[0] : e.message.slice(0, 200);
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=agent-browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-browser.js","sourceRoot":"","sources":["../../../src/utils/agent-browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,8EAA8E;AAC9E,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,OAAO,EAAE,wBAAwB,CAAC;AAEhE;;;;;;;;;;;GAWG;AACH,MAA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AG,CAAC,CAAC,CAAC;QACzD,IAAI,KAAK,CAAC,MAAM;YAAE,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7C,CAAC;IACD,MAAM,KAAK,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACxC,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ab } from './agent-browser.js';
|
|
2
|
+
import { sleep } from './process.js';
|
|
3
|
+
/**
|
|
4
|
+
* Polls the browser's console log output until a predicate returns `true`
|
|
5
|
+
* or the timeout expires.
|
|
6
|
+
*
|
|
7
|
+
* @param predicate - Callback receiving the raw console log text; return `true` to stop
|
|
8
|
+
* @param timeoutMs - Maximum polling duration in milliseconds
|
|
9
|
+
* @returns `true` if the predicate matched before timeout, `false` otherwise
|
|
10
|
+
*/
|
|
11
|
+
export async function pollConsole(predicate, timeoutMs) {
|
|
12
|
+
const deadline = Date.now() + timeoutMs;
|
|
13
|
+
while (Date.now() < deadline) {
|
|
14
|
+
try {
|
|
15
|
+
const logs = ab(['console']);
|
|
16
|
+
if (predicate(logs))
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
// Browser not ready — retry
|
|
21
|
+
}
|
|
22
|
+
await sleep(2000);
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=browser-poll.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-poll.js","sourceRoot":"","sources":["../../../src/utils/browser-poll.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAErC;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,SAAoC,EACpC,SAAiB;IAEjB,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;IACxC,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;QAC7B,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;YAC7B,IAAI,SAAS,CAAC,IAAI,CAAC;gBAAE,OAAO,IAAI,CAAC;QACnC,CAAC;QAAC,MAAM,CAAC;YACP,4BAA4B;QAC9B,CAAC;QACD,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { execFileSync, execSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, readFileSync, rmSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import { ab, PROFILE_DIR } from './agent-browser.js';
|
|
6
|
+
/** PID file written by the agent-browser daemon to track its own process. */
|
|
7
|
+
const DAEMON_PID_FILE = join(homedir(), '.agent-browser', 'default.pid');
|
|
8
|
+
/**
|
|
9
|
+
* Kills any running agent-browser daemon and its Chrome children,
|
|
10
|
+
* then removes stale state files so the next run starts clean.
|
|
11
|
+
*
|
|
12
|
+
* Cleanup sequence:
|
|
13
|
+
* 1. Graceful `agent-browser close` (5 s timeout)
|
|
14
|
+
* 2. Force-kill the daemon PID read from {@link DAEMON_PID_FILE}
|
|
15
|
+
* 3. `pkill` leftover headless Chrome processes
|
|
16
|
+
* 4. Delete Session Storage to clear stuck MSAL `interaction.status` flags
|
|
17
|
+
*/
|
|
18
|
+
export function resetDaemon() {
|
|
19
|
+
// 1. Try graceful close first
|
|
20
|
+
try {
|
|
21
|
+
execFileSync('agent-browser', ['close'], {
|
|
22
|
+
encoding: 'utf-8',
|
|
23
|
+
timeout: 5_000,
|
|
24
|
+
stdio: 'ignore',
|
|
25
|
+
});
|
|
26
|
+
console.log('🔄 Closed agent-browser daemon');
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// Daemon not responding — fall through to force-kill
|
|
30
|
+
}
|
|
31
|
+
// 2. Kill the daemon process tracked by agent-browser's own pid file
|
|
32
|
+
if (existsSync(DAEMON_PID_FILE)) {
|
|
33
|
+
try {
|
|
34
|
+
const pid = parseInt(readFileSync(DAEMON_PID_FILE, 'utf-8').trim(), 10);
|
|
35
|
+
if (pid > 0)
|
|
36
|
+
process.kill(pid);
|
|
37
|
+
console.log('🔄 Killed agent-browser daemon (pid %d)', pid);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// Process already dead — acceptable
|
|
41
|
+
}
|
|
42
|
+
rmSync(DAEMON_PID_FILE, { force: true });
|
|
43
|
+
}
|
|
44
|
+
// 3. Force-kill any leftover headless Chrome processes
|
|
45
|
+
try {
|
|
46
|
+
execSync("pkill -f 'Google Chrome for Testing.*--headless'", {
|
|
47
|
+
stdio: 'ignore',
|
|
48
|
+
timeout: 3_000,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// No matching processes — acceptable
|
|
53
|
+
}
|
|
54
|
+
// 4. Remove stale SingletonLock left by crashed Chrome
|
|
55
|
+
const lockPath = join(PROFILE_DIR, 'SingletonLock');
|
|
56
|
+
if (existsSync(lockPath)) {
|
|
57
|
+
try {
|
|
58
|
+
rmSync(lockPath, { force: true });
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
// Best-effort
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// 5. Clear Session Storage to remove stuck MSAL interaction.status flags
|
|
65
|
+
const sessionStorage = join(PROFILE_DIR, 'Default', 'Session Storage');
|
|
66
|
+
if (existsSync(sessionStorage)) {
|
|
67
|
+
rmSync(sessionStorage, { recursive: true, force: true });
|
|
68
|
+
console.log('🔄 Cleared Session Storage (MSAL interaction flags)');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Clears the MSAL `interaction.status` flag from `sessionStorage` in the
|
|
73
|
+
* running browser via `agent-browser eval`.
|
|
74
|
+
*/
|
|
75
|
+
export function clearMsalInteraction() {
|
|
76
|
+
try {
|
|
77
|
+
ab(['eval', 'sessionStorage.removeItem("msal.interaction.status")'], 5_000);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
// Browser may not be ready yet — non-fatal
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=daemon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"daemon.js","sourceRoot":"","sources":["../../../src/utils/daemon.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,OAAO,EAAE,EAAE,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAErD,6EAA6E;AAC7E,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,gBAAgB,EAAE,aAAa,CAAC,CAAC;AAEzE;;;;;;;;;GASG;AACH,MAAM,UAAU,WAAW;IACzB,8BAA8B;IAC9B,IAAI,CAAC;QACH,YAAY,CAAC,eAAe,EAAE,CAAC,OAAO,CAAC,EAAE;YACvC,QAAQ,EAAE,OAAO;YACjB,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,QAAQ;SAChB,CAAC,CAAC;QACH,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,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E,CAAC,CAAC;QACzD,OAAO,CAAC,GAAG,CAAC,qDAAqD,CAAC,CAAC;IACrE,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB;IAClC,IAAI,CAAC;QACH,EAAE,CAAC,CAAC,MAAM,EAAE,sDAAsD,CAAC,EAAE,KAAK,CAAC,CAAC;IAC9E,CAAC;IAAC,MAAM,CAAC;QACP,2CAA2C;IAC7C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { ab, abErrorMessage, PROFILE_DIR } from './agent-browser.js';
|
|
2
|
+
export { resetDaemon, clearMsalInteraction } from './daemon.js';
|
|
3
|
+
export { cleanup, sleep, stripAnsi } from './process.js';
|
|
4
|
+
export { createRunDir, resolveAppKey, waitForServer } from './server.js';
|
|
5
|
+
export { pollConsole } from './browser-poll.js';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sends `SIGTERM` to a child process if it is still running.
|
|
3
|
+
*
|
|
4
|
+
* @param proc - The child process to terminate (no-op when `undefined` or already killed)
|
|
5
|
+
*/
|
|
6
|
+
export function cleanup(proc) {
|
|
7
|
+
if (proc && !proc.killed) {
|
|
8
|
+
proc.kill('SIGTERM');
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Returns a promise that resolves after the given delay.
|
|
13
|
+
*
|
|
14
|
+
* @param ms - Delay in milliseconds
|
|
15
|
+
* @returns A promise that resolves after `ms` milliseconds
|
|
16
|
+
*/
|
|
17
|
+
export function sleep(ms) {
|
|
18
|
+
return new Promise((r) => setTimeout(r, ms));
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Strips ANSI escape codes (color / formatting) from a string.
|
|
22
|
+
*
|
|
23
|
+
* @param s - The string potentially containing ANSI sequences
|
|
24
|
+
* @returns The input string with all ANSI escape sequences removed
|
|
25
|
+
*/
|
|
26
|
+
export function stripAnsi(s) {
|
|
27
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: stripping ANSI escape sequences
|
|
28
|
+
return s.replace(/\x1b\[[0-9;]*m/g, '');
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.js","sourceRoot":"","sources":["../../../src/utils/process.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,IAAmB;IACzC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QACzB,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACvB,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAC,EAAU;IAC9B,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,CAAS;IACjC,2FAA2F;IAC3F,OAAO,CAAC,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { mkdirSync } from 'node:fs';
|
|
3
|
+
import { join, relative, resolve } from 'node:path';
|
|
4
|
+
import { sleep } from './process.js';
|
|
5
|
+
/**
|
|
6
|
+
* Creates a timestamped, run-specific output directory for eval artifacts.
|
|
7
|
+
*
|
|
8
|
+
* @param title - Human label used as the directory name prefix (slugified)
|
|
9
|
+
* @param baseDir - Optional parent directory override
|
|
10
|
+
* @returns Absolute path to the newly created directory
|
|
11
|
+
*/
|
|
12
|
+
export function createRunDir(title, baseDir) {
|
|
13
|
+
const now = new Date();
|
|
14
|
+
const time = [now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds()]
|
|
15
|
+
.map((n) => String(n).padStart(2, '0'))
|
|
16
|
+
.join('');
|
|
17
|
+
const ms = String(now.getUTCMilliseconds()).padStart(3, '0');
|
|
18
|
+
const slug = title.replace(/[^a-zA-Z0-9_-]/g, '-').replace(/-+/g, '-');
|
|
19
|
+
const parent = baseDir ? resolve(baseDir) : resolve('.tmp', 'copilot');
|
|
20
|
+
const dir = join(parent, `${slug}_${time}${ms}`);
|
|
21
|
+
mkdirSync(dir, { recursive: true });
|
|
22
|
+
console.log(`📁 Run dir: ${relative(process.cwd(), dir)}`);
|
|
23
|
+
return dir;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Resolves the Fusion `appKey` by running `ffc app manifest --silent`
|
|
27
|
+
* in the given application directory and parsing the JSON output.
|
|
28
|
+
*
|
|
29
|
+
* @param appDir - Absolute path to the Fusion application
|
|
30
|
+
* @returns The `appKey` string from the manifest
|
|
31
|
+
* @throws {Error} When `ffc app manifest` fails or returns invalid JSON
|
|
32
|
+
*/
|
|
33
|
+
export function resolveAppKey(appDir) {
|
|
34
|
+
const output = execFileSync('ffc', ['app', 'manifest', '--silent'], {
|
|
35
|
+
cwd: appDir,
|
|
36
|
+
encoding: 'utf-8',
|
|
37
|
+
timeout: 30_000,
|
|
38
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
39
|
+
});
|
|
40
|
+
const manifest = JSON.parse(output);
|
|
41
|
+
return manifest.appKey;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Polls a server URL until it responds with a non-5xx status or the
|
|
45
|
+
* timeout is reached.
|
|
46
|
+
*
|
|
47
|
+
* @param url - The URL to poll (e.g. `http://localhost:3000`)
|
|
48
|
+
* @param timeoutSeconds - Maximum number of seconds to wait
|
|
49
|
+
* @returns `true` if the server responded before timeout, `false` otherwise
|
|
50
|
+
*/
|
|
51
|
+
export async function waitForServer(url, timeoutSeconds) {
|
|
52
|
+
for (let i = 0; i < timeoutSeconds; i++) {
|
|
53
|
+
try {
|
|
54
|
+
const res = await fetch(url, { signal: AbortSignal.timeout(2000) });
|
|
55
|
+
if (res.ok || res.status < 500)
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// Server not ready yet — retry
|
|
60
|
+
}
|
|
61
|
+
await sleep(1000);
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/utils/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpD,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAErC;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,KAAa,EAAE,OAAgB;IAC1D,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,GAAG,CAAC,aAAa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