@agimon-ai/po-workflow 0.0.0-alpha.212 → 0.0.0-alpha.214

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.
@@ -2740,18 +2740,18 @@ var WorkflowRegistryService = class {
2740
2740
  }
2741
2741
  /**
2742
2742
  * List the current generation of every run across all workspaces or a single workspace.
2743
+ * `mentioning` skips latest runs whose saved state never names that text; callers still scope.
2744
+ * An invalid newest generation hides its key rather than resurrecting an older one.
2743
2745
  */
2744
- async listRuns(workspace) {
2746
+ async listRuns(workspace, mentioning) {
2745
2747
  const runs = await this.store.listRuns({
2746
2748
  authorityId: this.authorityId,
2747
- ...workspace ? { workspaceId: this.resolveWorkspace(workspace) } : {}
2749
+ ...workspace ? { workspaceId: this.resolveWorkspace(workspace) } : {},
2750
+ latestPerKey: true,
2751
+ ...mentioning === void 0 ? {} : { mentioning }
2748
2752
  });
2749
2753
  const records = [];
2750
- const seen = /* @__PURE__ */ new Set();
2751
2754
  for (const run of runs) {
2752
- const key = JSON.stringify([run.workspaceId, run.runKey]);
2753
- if (seen.has(key)) continue;
2754
- seen.add(key);
2755
2755
  const record = this.tryRecord(run);
2756
2756
  if (record) records.push(this.inspectRunning(record));
2757
2757
  }
@@ -12770,7 +12770,10 @@ function unreadable(record, command, result) {
12770
12770
  * Registry homes come from the workflow store, never from scanning folders.
12771
12771
  */
12772
12772
  async function readWorkflowRuns(runtime, options = {}) {
12773
- if (options.homeDir === void 0) return (await Promise.all((options.locations ?? await workflowRunLocations(runtime)).map((location) => readWorkflowRuns(runtime, { ...location })))).flat();
12773
+ if (options.homeDir === void 0) return (await Promise.all((options.locations ?? await workflowRunLocations(runtime)).map((location) => readWorkflowRuns(runtime, {
12774
+ ...location,
12775
+ ...options.scope ? { scope: options.scope } : {}
12776
+ })))).flat();
12774
12777
  const parser = new require_workflowHost.WorkflowParserService(runtime);
12775
12778
  const homeDir = options.homeDir;
12776
12779
  const ownerSessionId = options.ownerSessionId ?? workflowHomeOwner(homeDir);
@@ -12787,10 +12790,12 @@ async function readWorkflowRuns(runtime, options = {}) {
12787
12790
  plans.set(workflowPath, plan);
12788
12791
  return plan;
12789
12792
  };
12793
+ const scope = options.scope;
12790
12794
  const runs = [];
12791
- for (const record of await registry.listRuns()) {
12795
+ for (const record of await registry.listRuns(void 0, scope?.sessionId)) {
12792
12796
  const parsed = parseWorkflowRunRecord(JSON.stringify(record));
12793
12797
  if (parsed === void 0) continue;
12798
+ if (scope && !runBelongsToSession(parsed, scope.sessionId) && !(scope.launched && runLaunchedBySession(parsed, scope.sessionId))) continue;
12794
12799
  const jobs = foldWorkflowProgress(await registry.readProgress(record.runId), await planFor(parsed.view.workflowPath));
12795
12800
  const owner = registry.runRef(record)?.ownerSessionId ?? ownerSessionId;
12796
12801
  runs.push({
@@ -14195,9 +14200,27 @@ var PoDbWorkflowStoreService = class PoDbWorkflowStoreService {
14195
14200
  return (await this.db.database.get("SELECT revision FROM workflow_runs WHERE run_id = ?", runId))?.revision;
14196
14201
  }
14197
14202
  async listRuns(input) {
14198
- return (await this.db.database.all(`SELECT * FROM workflow_runs WHERE authority_id = ? AND (? IS NULL OR workspace_id = ?)
14203
+ const filters = [
14204
+ input.authorityId,
14205
+ input.workspaceId ?? null,
14206
+ input.workspaceId ?? null,
14207
+ input.lifecycle ?? null,
14208
+ input.lifecycle ?? null,
14209
+ input.includeTombstoned ? 1 : 0
14210
+ ];
14211
+ if (!input.latestPerKey) return (await this.db.database.all(`SELECT * FROM workflow_runs WHERE authority_id = ? AND (? IS NULL OR workspace_id = ?)
14199
14212
  AND (? IS NULL OR lifecycle = ?) AND (? = 1 OR tombstoned_at IS NULL)
14200
- ORDER BY created_at DESC, generation DESC`, input.authorityId, input.workspaceId ?? null, input.workspaceId ?? null, input.lifecycle ?? null, input.lifecycle ?? null, input.includeTombstoned ? 1 : 0)).map(runFrom);
14213
+ ORDER BY created_at DESC, generation DESC`, ...filters)).map(runFrom);
14214
+ const needle = input.mentioning !== void 0 && JSON.stringify(input.mentioning) === `"${input.mentioning}"` ? input.mentioning : null;
14215
+ return (await this.db.database.all(`SELECT runs.* FROM (
14216
+ SELECT rowid AS run_rowid, ROW_NUMBER() OVER (PARTITION BY workspace_id, run_key
14217
+ ORDER BY created_at DESC, generation DESC, run_id DESC) AS row_rank
14218
+ FROM workflow_runs WHERE authority_id = ? AND (? IS NULL OR workspace_id = ?)
14219
+ AND (? IS NULL OR lifecycle = ?) AND (? = 1 OR tombstoned_at IS NULL)
14220
+ ) AS ranked
14221
+ JOIN workflow_runs AS runs ON runs.rowid = ranked.run_rowid
14222
+ WHERE ranked.row_rank = 1 AND (? IS NULL OR instr(runs.state, ?) > 0)
14223
+ ORDER BY runs.created_at DESC, runs.generation DESC, runs.run_id DESC`, ...filters, needle, needle)).map(runFrom);
14201
14224
  }
14202
14225
  async latestRun(input) {
14203
14226
  const row = await this.db.database.get(`SELECT * FROM workflow_runs WHERE authority_id = ? AND workspace_id = ? AND run_key = ? AND tombstoned_at IS NULL
@@ -20435,10 +20458,14 @@ function createWorkflowServerRuntime(host, serverHost, runtime, resolveSecrets,
20435
20458
  const childReports = () => serverScope?.resolve(_agimon_ai_po_core_hubChannel.PO_CHILD_REPORT_CONTRACT);
20436
20459
  /** Every registry home the store knows, led by this session's own and those it already serves. */
20437
20460
  const knownLocations = () => workflowRunLocations(runtime, [ownHome, ...features.keys()]);
20438
- const snapshot = async () => {
20439
- const runs = await readWorkflowRuns(runtime, { locations: await knownLocations() });
20461
+ /** With a scope, other sessions' runs are skipped before enrichment; callers still filter what comes back. */
20462
+ const snapshot = async (scope) => {
20463
+ const runs = await readWorkflowRuns(runtime, {
20464
+ locations: await knownLocations(),
20465
+ ...scope ? { scope } : {}
20466
+ });
20440
20467
  const stale = /* @__PURE__ */ new Map();
20441
- for (const home of new Set(runs.filter((run) => run.view.stage === "running").map((run) => run.registryHome ?? ownHome))) for (const record of await featureFor(home).registry.listRuns()) if (record.stale) stale.set(`${home}/${record.workspace}/${record.runKey}`, record.staleReason);
20468
+ for (const home of new Set(runs.filter((run) => run.view.stage === "running").map((run) => run.registryHome ?? ownHome))) for (const record of await featureFor(home).registry.listRuns(void 0, scope?.sessionId)) if (record.stale) stale.set(`${home}/${record.workspace}/${record.runKey}`, record.staleReason);
20442
20469
  return runs.map((run) => run.view.stage === "running" && stale.has(`${run.registryHome ?? ownHome}/${run.view.workspace}/${run.view.runKey}`) ? {
20443
20470
  ...run,
20444
20471
  view: {
@@ -20576,7 +20603,10 @@ function createWorkflowServerRuntime(host, serverHost, runtime, resolveSecrets,
20576
20603
  const publishRuns = async (executionContext) => {
20577
20604
  if (!historyRead) return false;
20578
20605
  const revision = ++runsReadRevision;
20579
- const records = (await snapshot()).filter((run) => runBelongsToSession(run, executionContext.sessionId) || runLaunchedBySession(run, executionContext.sessionId));
20606
+ const records = (await snapshot({
20607
+ sessionId: executionContext.sessionId,
20608
+ launched: true
20609
+ })).filter((run) => runBelongsToSession(run, executionContext.sessionId) || runLaunchedBySession(run, executionContext.sessionId));
20580
20610
  if (disposed || revision !== runsReadRevision) return activeRunCount > 0 || pendingCompletions.size > 0;
20581
20611
  for (const record of records) {
20582
20612
  const view = record.view;
@@ -21010,7 +21040,10 @@ function createWorkflowServerRuntime(host, serverHost, runtime, resolveSecrets,
21010
21040
  if (disposed) throw new Error(RUNTIME_DISPOSED_MESSAGE);
21011
21041
  if (refusal !== void 0) return textResult(`Error: ${refusal}`, true);
21012
21042
  const self = host.context.sessionId;
21013
- const running = (await snapshot()).filter((run) => run.view.stage === "running" && run.view.stale !== true && (runBelongsToSession(run, self) || runLaunchedBySession(run, self))).length;
21043
+ const running = (await snapshot({
21044
+ sessionId: self,
21045
+ launched: true
21046
+ })).filter((run) => run.view.stage === "running" && run.view.stale !== true && (runBelongsToSession(run, self) || runLaunchedBySession(run, self))).length;
21014
21047
  const ceiling = resolveMaxConcurrent(host.context.environment);
21015
21048
  if (running >= ceiling) return textResult(`Error: This session is at capacity: ${String(running)}/${String(ceiling)} workflows running.`, true);
21016
21049
  const workflowPath = (0, node_path.resolve)(where.cwd, input.workflowPath);
@@ -21227,7 +21260,10 @@ function createWorkflowServerRuntime(host, serverHost, runtime, resolveSecrets,
21227
21260
  return ownedControl;
21228
21261
  }
21229
21262
  if (disposed) throw new Error(RUNTIME_DISPOSED_MESSAGE);
21230
- const homes = /* @__PURE__ */ new Set([ownHome, ...(await snapshot()).filter((run) => runBelongsToSession(run, host.context.sessionId) || runLaunchedBySession(run, host.context.sessionId)).map((run) => run.registryHome ?? ownHome)]);
21263
+ const homes = /* @__PURE__ */ new Set([ownHome, ...(await snapshot({
21264
+ sessionId: host.context.sessionId,
21265
+ launched: true
21266
+ })).filter((run) => runBelongsToSession(run, host.context.sessionId) || runLaunchedBySession(run, host.context.sessionId)).map((run) => run.registryHome ?? ownHome)]);
21231
21267
  if (disposed) throw new Error(RUNTIME_DISPOSED_MESSAGE);
21232
21268
  const currentHome = [...features].find(([, candidate]) => candidate === feature)[0];
21233
21269
  homes.add(currentHome);
@@ -21872,7 +21908,10 @@ function createWorkflowServerRuntime(host, serverHost, runtime, resolveSecrets,
21872
21908
  resources: [{
21873
21909
  name: "workflow-session",
21874
21910
  kind: "context",
21875
- read: async (executionContext) => workflowSession ? workflowSessionBrief(presentWorkflowRuns((await snapshot()).filter((run) => runBelongsToSession(run, executionContext.sessionId)).map((run) => run.view), Date.now())) : ""
21911
+ read: async (executionContext) => workflowSession ? workflowSessionBrief(presentWorkflowRuns((await snapshot({
21912
+ sessionId: executionContext.sessionId,
21913
+ launched: false
21914
+ })).filter((run) => runBelongsToSession(run, executionContext.sessionId)).map((run) => run.view), Date.now())) : ""
21876
21915
  }],
21877
21916
  activities: [{
21878
21917
  name: SOURCE,