gcf-aif-ext 0.23.0 → 0.25.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.
@@ -3,9 +3,9 @@ import { existsSync } from 'node:fs';
3
3
  import { readFile } from 'node:fs/promises';
4
4
  import path from 'node:path';
5
5
  import { gameMilestones } from './design-check.js';
6
- import { listItems, scalarOf, readConfig, firstBullet } from './gcf-paths.js';
6
+ import { listItems, scalarOf, firstBullet } from './gcf-paths.js';
7
+ import { buildOf } from './play.js';
7
8
  import { recordsOf } from './verdict-fs.js';
8
- import { runDod } from './verify.js';
9
9
 
10
10
  const ENVELOPE = /^\S+\.\.\S+ /;
11
11
 
@@ -50,8 +50,8 @@ export async function platformsOf(root) {
50
50
 
51
51
  /**
52
52
  * Playtest list (Methodology §5.3): every item waiting for its verdict, and every unplayed one,
53
- * with the question the play must answer, its milestone and where to play it (`play_on`, else
54
- * every line of `platforms`).
53
+ * with the question the play must answer, its milestone, where to play it (`play_on`, else every
54
+ * line of `platforms`) and its build (lib/play.js), null while it has none.
55
55
  */
56
56
  export async function playtestList(root) {
57
57
  const platforms = await platformsOf(root);
@@ -65,6 +65,7 @@ export async function playtestList(root) {
65
65
  system: c.data.system ?? [],
66
66
  milestone: c.data.milestone ?? null,
67
67
  play_on: c.data.play_on ?? platforms,
68
+ build: buildOf(path.dirname(root), String(c.data.id), c.data.status),
68
69
  question: scalarOf(c.body, 'miss_criterion') || '(miss_criterion is empty)',
69
70
  reach: recordsOf(c.body, 'behavior')
70
71
  .map((r) => r.input)
@@ -94,14 +95,11 @@ const git = (projectDir, args) => {
94
95
  };
95
96
 
96
97
  /**
97
- * `playtest session` (Methodology §5.3): one build of main and the checklist of everything that
98
+ * `playtest session` (Methodology §5.3): where main stands and the checklist of everything that
98
99
  * waits for play, grouped by subsystem — built from the items on every call, no file of its own.
99
- * `build` runs the project's `dod.build` first.
100
+ * Each item names its own build (lib/play.js).
100
101
  */
101
- export async function playtestSession(
102
- projectDir,
103
- { build = false, stdio = ['ignore', 2, 2] } = {},
104
- ) {
102
+ export async function playtestSession(projectDir) {
105
103
  const root = path.join(path.resolve(projectDir), 'gcf');
106
104
  const milestones = (await gameMilestones(root)) ?? [];
107
105
  // Milestones in game.md's order, then the items with none (or one game.md no longer has).
@@ -132,7 +130,6 @@ export async function playtestSession(
132
130
  commit: git(projectDir, ['rev-parse', '--short', 'HEAD']),
133
131
  // No commit (no repository, or none yet): the build is unknown, not clean.
134
132
  dirty: dirty === null ? null : Boolean(dirty),
135
- build: /** @type {Awaited<ReturnType<typeof runDod>> | null} */ (null),
136
133
  // Each milestone with something to play: its goal, the question its play answers, and how
137
134
  // much of it is still being built or blocked.
138
135
  milestones: milestones
@@ -152,7 +149,6 @@ export async function playtestSession(
152
149
  items,
153
150
  decisions: await decisionList(root),
154
151
  };
155
- if (build) session.build = await runDod(projectDir, await readConfig(root), 'build', stdio);
156
152
 
157
153
  return session;
158
154
  }
package/lib/safe-path.js CHANGED
@@ -32,7 +32,7 @@ const BUSY = new Set(['EPERM', 'EACCES', 'EBUSY']);
32
32
  // The board's writeAtomicSync budget: a scan of a fresh file often outlasts 200 ms.
33
33
  const RENAME_TRIES = 10;
34
34
 
35
- async function renameRetrying(from, to) {
35
+ export async function renameRetrying(from, to) {
36
36
  for (let attempt = 1; ; attempt++) {
37
37
  try {
38
38
  return await rename(from, to);
@@ -5,11 +5,12 @@
5
5
  // and the move that ends the run clears it. A mark nobody refreshed for SESSION_TTL_MS is a
6
6
  // session that stopped: the item reads as not running again. The mark names its owner, so a
7
7
  // second session cannot take an item the first one works.
8
- import { existsSync, readFileSync, rmSync, statSync, utimesSync } from 'node:fs';
8
+ import { existsSync, readdirSync, readFileSync, rmSync, statSync, utimesSync } from 'node:fs';
9
9
  import { mkdir, writeFile } from 'node:fs/promises';
10
10
  import path from 'node:path';
11
11
  import { excludeSession } from './integrate.js';
12
12
  import { alive, withMainLock } from './main-lock.js';
13
+ import { enterFolder } from './shelf.js';
13
14
 
14
15
  // A run's default timeout: an agent can implement for long without a gcf command. The harness
15
16
  // and its readset-guard hook refresh a live session's mark meanwhile.
@@ -45,19 +46,43 @@ export function ownsMark(projectDir, id, owner = ownerOf()) {
45
46
  return !held || held === owner;
46
47
  }
47
48
 
48
- /** Mark item `id` as worked by `owner`; refused while another owner's mark is fresh. */
49
- export async function claimSession(projectDir, id, owner = ownerOf()) {
49
+ /** Whether a session of another owner works another item in this folder now. */
50
+ function otherSessionLives(projectDir, id, owner) {
51
+ const runs = path.dirname(markOf(projectDir, id));
52
+ const held = (other) =>
53
+ sessionActive(projectDir, other) && ownerLine(projectDir, other) !== owner;
54
+
55
+ return readdirSync(runs).some(
56
+ (f) => f.endsWith('.session') && f !== `${id}.session` && held(f.slice(0, -'.session'.length)),
57
+ );
58
+ }
59
+
60
+ /**
61
+ * Mark item `id` as worked by `owner`; refused while another owner's mark is fresh. The folder
62
+ * changes hands here, the one door a harness run and a console session both pass: the work of
63
+ * the card that held it goes to its branch, and this card's own comes back (lib/shelf.js).
64
+ * @param {{step?: (name: string) => void, gitVersion?: string}} [opts] for a test
65
+ * @returns {Promise<ReturnType<typeof enterFolder>>} what moved
66
+ */
67
+ export async function claimSession(projectDir, id, owner = ownerOf(), opts = {}) {
50
68
  const file = markOf(projectDir, id);
51
69
  await excludeSession(projectDir);
52
70
  await mkdir(path.dirname(file), { recursive: true });
71
+
53
72
  // Under the main lock: two sessions claiming at once must not both pass the check.
54
- await withMainLock(projectDir, async () => {
73
+ return withMainLock(projectDir, async () => {
55
74
  if (!ownsMark(projectDir, id, owner))
56
75
  throw new Error(
57
76
  `${id} is worked by another agent session (${markOwner(projectDir, id)}): leave it to ` +
58
77
  `that session, or run ai-factory gcf release ${id} when no session works it`,
59
78
  );
79
+ const shared = otherSessionLives(projectDir, id, owner ?? null);
80
+ const moved = enterFolder(projectDir, id, { shared, ...opts });
81
+ // A shelved card is no running card, whoever held it.
82
+ if (moved.shelved) releaseSession(projectDir, moved.shelved.id);
60
83
  await writeFile(file, `${new Date().toISOString()}\n${owner ?? ''}\n`);
84
+
85
+ return moved;
61
86
  });
62
87
  }
63
88