screw-bugs 0.1.1 → 0.1.2
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/README.md +69 -19
- package/dist/browser-playwright/launch.js +3 -1
- package/dist/browser-playwright/page.d.ts +3 -11
- package/dist/browser-playwright/page.js +17 -1
- package/dist/browser-playwright/sign-in.d.ts +77 -0
- package/dist/browser-playwright/sign-in.js +217 -0
- package/dist/build-info.json +3 -3
- package/dist/cli/app.js +4 -1
- package/dist/cli/commands.js +68 -3
- package/dist/cli/exit-codes.d.ts +6 -0
- package/dist/cli/exit-codes.js +6 -0
- package/dist/cli/mcp.js +17 -3
- package/dist/cli/operations.d.ts +31 -3
- package/dist/cli/operations.js +95 -3
- package/dist/cli/sign-in.d.ts +79 -0
- package/dist/cli/sign-in.js +305 -0
- package/dist/core/accounts.d.ts +40 -0
- package/dist/core/accounts.js +95 -0
- package/dist/core/engine.d.ts +4 -3
- package/dist/core/engine.js +30 -8
- package/dist/core/errors.d.ts +19 -0
- package/dist/core/errors.js +6 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +1 -0
- package/dist/core/services.d.ts +77 -8
- package/dist/core/services.js +4 -1
- package/dist/report/bug.d.ts +2 -2
- package/dist/report/bug.js +5 -4
- package/dist/report/html.d.ts +1 -1
- package/dist/report/icons.d.ts +1 -0
- package/dist/report/icons.js +1 -0
- package/dist/report/index.d.ts +1 -0
- package/dist/report/index.js +1 -0
- package/dist/report/markup.d.ts +2 -0
- package/dist/report/markup.js +5 -4
- package/dist/report/player.d.ts +7 -2
- package/dist/report/player.js +16 -5
- package/dist/report/sign-in.d.ts +41 -0
- package/dist/report/sign-in.js +591 -0
- package/dist/report/styles.js +1 -1
- package/dist/report/walkthrough.d.ts +3 -2
- package/dist/report/walkthrough.js +47 -38
- package/dist/schema/accounts.d.ts +137 -0
- package/dist/schema/accounts.js +112 -0
- package/dist/schema/index.d.ts +1 -0
- package/dist/schema/index.js +1 -0
- package/dist/schema/job.d.ts +27 -6
- package/dist/schema/job.js +12 -2
- package/dist/schema/ledger.d.ts +5 -1
- package/dist/store-local/accounts.d.ts +8 -4
- package/dist/store-local/accounts.js +82 -7
- package/dist/store-local/paths.d.ts +4 -1
- package/dist/store-local/paths.js +4 -1
- package/package.json +1 -1
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import { Layer } from 'effect';
|
|
1
|
+
import { FileSystem, Layer, Path } from 'effect';
|
|
2
2
|
import { AccountBook } from '../core/index.js';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* The account book on disk: `.screw-bugs/accounts.json` lists the accounts (no secrets), and
|
|
5
|
+
* `.screw-bugs/accounts/<label>.json` holds each one's session, written with mode 0600 in a folder
|
|
6
|
+
* with mode 0700, so only the user can read them. (On Windows modes do not apply; the files get
|
|
7
|
+
* the folder's access, like everything else in `.screw-bugs/`.) The whole folder ignores itself
|
|
8
|
+
* for git. Changes in this process are one at a time; a change in another process at the same
|
|
9
|
+
* moment may be lost, never half written.
|
|
6
10
|
*/
|
|
7
|
-
export declare const AccountBookLocal: (
|
|
11
|
+
export declare const AccountBookLocal: (projectRoot: string) => Layer.Layer<AccountBook, never, FileSystem.FileSystem | Path.Path>;
|
|
@@ -1,9 +1,84 @@
|
|
|
1
|
-
import { Effect, Layer } from 'effect';
|
|
2
|
-
import { AccountBook,
|
|
1
|
+
import { Effect, FileSystem, Layer, Path, PlatformError, Random, Schema, Semaphore } from 'effect';
|
|
2
|
+
import { AccountBook, StorageFailed } from '../core/index.js';
|
|
3
|
+
import { AccountsFile, SavedSession } from '../schema/index.js';
|
|
4
|
+
import { accountsDir, accountsFile, ensureDataDir } from './paths.js';
|
|
5
|
+
const isMissing = (error) => error instanceof PlatformError.PlatformError && error.reason._tag === 'NotFound';
|
|
6
|
+
const randomHex = Random.nextIntBetween(0, 2 ** 32 - 1).pipe(Effect.map((n) => n.toString(16).padStart(8, '0')));
|
|
7
|
+
const decodeFile = Schema.decodeUnknownEffect(Schema.fromJsonString(AccountsFile));
|
|
8
|
+
const decodeSession = Schema.decodeUnknownEffect(Schema.fromJsonString(SavedSession));
|
|
9
|
+
const decodeObject = Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.Record(Schema.String, Schema.Unknown)));
|
|
3
10
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
11
|
+
* The account book on disk: `.screw-bugs/accounts.json` lists the accounts (no secrets), and
|
|
12
|
+
* `.screw-bugs/accounts/<label>.json` holds each one's session, written with mode 0600 in a folder
|
|
13
|
+
* with mode 0700, so only the user can read them. (On Windows modes do not apply; the files get
|
|
14
|
+
* the folder's access, like everything else in `.screw-bugs/`.) The whole folder ignores itself
|
|
15
|
+
* for git. Changes in this process are one at a time; a change in another process at the same
|
|
16
|
+
* moment may be lost, never half written.
|
|
6
17
|
*/
|
|
7
|
-
export const AccountBookLocal = (
|
|
8
|
-
|
|
9
|
-
|
|
18
|
+
export const AccountBookLocal = (projectRoot) => Layer.effect(AccountBook, Effect.gen(function* () {
|
|
19
|
+
const fs = yield* FileSystem.FileSystem;
|
|
20
|
+
const path = yield* Path.Path;
|
|
21
|
+
const file = yield* accountsFile(projectRoot);
|
|
22
|
+
const dir = yield* accountsDir(projectRoot);
|
|
23
|
+
const lock = yield* Semaphore.make(1);
|
|
24
|
+
const sessionPath = (label) => path.join(dir, `${label}.json`);
|
|
25
|
+
const failed = (message) => (cause) => new StorageFailed({ message, cause });
|
|
26
|
+
/** Writes through a temporary file and a rename; `mode` is the new file's. */
|
|
27
|
+
const writeAtomic = (target, text, mode) => Effect.gen(function* () {
|
|
28
|
+
const temporary = `${target}.${yield* randomHex}.tmp`;
|
|
29
|
+
yield* fs.writeFileString(temporary, text, { flag: 'wx', mode });
|
|
30
|
+
yield* fs.rename(temporary, target);
|
|
31
|
+
}).pipe(Effect.mapError(failed(`Could not write ${target}.`)));
|
|
32
|
+
const read = fs.readFileString(file).pipe(Effect.flatMap(decodeFile), Effect.catchIf(isMissing, () => Effect.succeed({ version: 1, accounts: [] })), Effect.mapError(failed(`${file} is unreadable or not valid.`)));
|
|
33
|
+
const write = (accounts) => Effect.gen(function* () {
|
|
34
|
+
yield* ensureDataDir(projectRoot).pipe(Effect.provideService(FileSystem.FileSystem, fs), Effect.provideService(Path.Path, path), Effect.mapError(failed(`Could not create the folder of ${file}.`)));
|
|
35
|
+
const sorted = [...accounts].sort((a, b) => a.label.localeCompare(b.label));
|
|
36
|
+
const value = { version: 1, accounts: sorted };
|
|
37
|
+
yield* writeAtomic(file, `${JSON.stringify(value, null, 2)}\n`, 0o644);
|
|
38
|
+
});
|
|
39
|
+
return AccountBook.of({
|
|
40
|
+
file,
|
|
41
|
+
list: read.pipe(Effect.map((book) => book.accounts)),
|
|
42
|
+
find: (label) => Effect.gen(function* () {
|
|
43
|
+
const listed = (yield* read).accounts.find((a) => a.label === label);
|
|
44
|
+
if (listed === undefined)
|
|
45
|
+
return undefined;
|
|
46
|
+
const file = yield* fs.readFileString(sessionPath(label)).pipe(Effect.flatMap((text) => decodeSession(text).pipe(Effect.map((session) => ({ text, session })))), Effect.orElseSucceed(() => undefined));
|
|
47
|
+
// Where and when come from the session file itself, written with it in one rename:
|
|
48
|
+
// the list may be behind (a save in progress, or one whose list write failed).
|
|
49
|
+
const own = file?.session.account.label === label ? file : undefined;
|
|
50
|
+
return {
|
|
51
|
+
entry: own === undefined
|
|
52
|
+
? listed
|
|
53
|
+
: {
|
|
54
|
+
...listed,
|
|
55
|
+
origin: own.session.account.origin,
|
|
56
|
+
savedAt: own.session.account.savedAt,
|
|
57
|
+
},
|
|
58
|
+
sessionPath: sessionPath(label),
|
|
59
|
+
session: own?.session,
|
|
60
|
+
sessionText: own?.text,
|
|
61
|
+
};
|
|
62
|
+
}),
|
|
63
|
+
save: (entry, session) => Effect.gen(function* () {
|
|
64
|
+
yield* fs
|
|
65
|
+
.makeDirectory(dir, { recursive: true, mode: 0o700 })
|
|
66
|
+
.pipe(Effect.mapError(failed(`Could not create ${dir}.`)));
|
|
67
|
+
// A folder made by an older copy, or by hand, is made private too.
|
|
68
|
+
yield* fs.chmod(dir, 0o700).pipe(Effect.ignore);
|
|
69
|
+
const state = yield* decodeObject(session).pipe(Effect.mapError(failed('The session to save is not a JSON object.')));
|
|
70
|
+
const account = { label: entry.label, origin: entry.origin, savedAt: entry.savedAt };
|
|
71
|
+
yield* writeAtomic(sessionPath(entry.label), `${JSON.stringify({ ...state, account }, null, 2)}\n`, 0o600);
|
|
72
|
+
const others = (yield* read).accounts.filter((a) => a.label !== entry.label);
|
|
73
|
+
yield* write([...others, entry]);
|
|
74
|
+
}).pipe(Semaphore.withPermit(lock)),
|
|
75
|
+
remove: (label) => Effect.gen(function* () {
|
|
76
|
+
const book = yield* read;
|
|
77
|
+
const found = book.accounts.some((a) => a.label === label);
|
|
78
|
+
if (found)
|
|
79
|
+
yield* write(book.accounts.filter((a) => a.label !== label));
|
|
80
|
+
const removed = yield* fs.remove(sessionPath(label)).pipe(Effect.as(true), Effect.catchIf(isMissing, () => Effect.succeed(false)), Effect.mapError(failed(`Could not remove ${sessionPath(label)}.`)));
|
|
81
|
+
return found || removed;
|
|
82
|
+
}).pipe(Semaphore.withPermit(lock)),
|
|
83
|
+
});
|
|
84
|
+
}));
|
|
@@ -6,5 +6,8 @@ import { Effect, FileSystem, Path } from 'effect';
|
|
|
6
6
|
*/
|
|
7
7
|
export declare const dataDir: (projectRoot: string) => Effect.Effect<string, never, Path.Path>;
|
|
8
8
|
export declare const runsDir: (projectRoot: string) => Effect.Effect<string, never, Path.Path>;
|
|
9
|
-
|
|
9
|
+
/** The saved test accounts, for agents to pick from: labels and what each user is, no secrets. */
|
|
10
|
+
export declare const accountsFile: (projectRoot: string) => Effect.Effect<string, never, Path.Path>;
|
|
11
|
+
/** One session file per account, readable by the user alone. */
|
|
12
|
+
export declare const accountsDir: (projectRoot: string) => Effect.Effect<string, never, Path.Path>;
|
|
10
13
|
export declare const ensureDataDir: (projectRoot: string) => Effect.Effect<string, import("effect/PlatformError").PlatformError, FileSystem.FileSystem | Path.Path>;
|
|
@@ -6,7 +6,10 @@ import { Effect, FileSystem, Path } from 'effect';
|
|
|
6
6
|
*/
|
|
7
7
|
export const dataDir = (projectRoot) => Path.Path.useSync((path) => path.join(projectRoot, '.screw-bugs'));
|
|
8
8
|
export const runsDir = (projectRoot) => Path.Path.useSync((path) => path.join(projectRoot, '.screw-bugs', 'runs'));
|
|
9
|
-
|
|
9
|
+
/** The saved test accounts, for agents to pick from: labels and what each user is, no secrets. */
|
|
10
|
+
export const accountsFile = (projectRoot) => Path.Path.useSync((path) => path.join(projectRoot, '.screw-bugs', 'accounts.json'));
|
|
11
|
+
/** One session file per account, readable by the user alone. */
|
|
12
|
+
export const accountsDir = (projectRoot) => Path.Path.useSync((path) => path.join(projectRoot, '.screw-bugs', 'accounts'));
|
|
10
13
|
export const ensureDataDir = (projectRoot) => Effect.gen(function* () {
|
|
11
14
|
const fs = yield* FileSystem.FileSystem;
|
|
12
15
|
const path = yield* Path.Path;
|