GeezerVison is showing github.com — feat(server): add status filter to experimental job list · anomalyco/opencode@e1f45df
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/client/src/effect/api/api.ts +1Lines changed: 1 addition & 0 deletions Collapse file Copy file name to clipboardExpand all lines: packages/client/src/effect/generated/client.ts +6-1Lines changed: 6 additions & 1 deletion Collapse file Copy file name to clipboardExpand all lines: packages/client/src/promise/generated/client.ts +6-1Lines changed: 6 additions & 1 deletion Collapse file Copy file name to clipboardExpand all lines: packages/client/src/promise/generated/types.ts +1Lines changed: 1 addition & 0 deletions Collapse file Copy file name to clipboardExpand all lines: packages/core/src/session/background.ts +8-3Lines changed: 8 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | export * as SessionBackground from "./background.js" | 2 | 2 |
| 3 | | -import type { Kind } from "@opencode/schema/job" | | 3 | +import type { Kind, Status } from "@opencode/schema/job" | 4 | 4 | import { Effect } from "effect" | 5 | 5 | import type { Job } from "../job.js" | 6 | 6 | import type { SessionSchema } from "./schema.js" | @@ -12,6 +12,7 @@ export type Lookup = { | 12 | 12 | export type ListFilter = { | 13 | 13 | readonly sessionID?: SessionSchema.ID | 14 | 14 | readonly kind?: Kind | | 15 | + readonly status?: Status | 15 | 16 | readonly descendants?: boolean | 16 | 17 | } | 17 | 18 |
| @@ -49,13 +50,17 @@ export const outstanding = Effect.fnUntraced(function* ( | 49 | 50 | }) | 50 | 51 | }) | 51 | 52 |
| 52 | | -/** Active and unconsumed background jobs matching the requested Session, kind, and descendant scope. */ | | 53 | +/** Active and unconsumed background jobs matching the requested Session, kind, status, and descendant scope. */ | 53 | 54 | export const list = Effect.fn("SessionBackground.list")(function* ( | 54 | 55 | jobs: Pick<Job.Interface, "backgroundJobs">, | 55 | 56 | store: Lookup, | 56 | 57 | filter: ListFilter = {}, | 57 | 58 | ) { | 58 | | - const items = (yield* jobs.backgroundJobs).filter((item) => filter.kind === undefined || item.kind === filter.kind) | | 59 | + const items = (yield* jobs.backgroundJobs).filter( | | 60 | + (item) => | | 61 | + (filter.kind === undefined || item.kind === filter.kind) && | | 62 | + (filter.status === undefined || item.status === filter.status), | | 63 | + ) | 59 | 64 | if (filter.sessionID === undefined) return items | 60 | 65 | const sessionID = filter.sessionID | 61 | 66 | if (!filter.descendants) return items.filter((item) => item.sessionID === sessionID) | |
Collapse file Copy file name to clipboardExpand all lines: packages/protocol/openapi.json +13-9Lines changed: 13 additions & 9 deletions Collapse file Copy file name to clipboardExpand all lines: packages/protocol/src/groups/job.ts +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -18,6 +18,9 @@ export const ListQuery = Schema.Struct({ | 18 | 18 | kind: Schema.optional(Job.Kind).annotate({ | 19 | 19 | description: "Filter by background job kind (shell, subagent, or image).", | 20 | 20 | }), | | 21 | + status: Schema.optional(Job.Status).annotate({ | | 22 | + description: "Filter by job status (running, completed, error, or cancelled).", | | 23 | + }), | 21 | 24 | descendants: Schema.optional(BooleanFromString).annotate({ | 22 | 25 | description: "When sessionID is set, also include background jobs owned by child and nested subagent sessions.", | 23 | 26 | }), | |
Collapse file Copy file name to clipboardExpand all lines: packages/server/test/job.test.ts +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -160,6 +160,16 @@ it.live("lists background jobs by session, kind, and descendants until completio | 160 | 160 | time: { started: expect.any(Number), completed: expect.any(Number) }, | 161 | 161 | }, | 162 | 162 | ]) | | 163 | + expect( | | 164 | + (yield* Effect.promise(() => api.experimental.job.list({ sessionID: root.id, status: "running" }))).map( | | 165 | + (item) => item.id, | | 166 | + ), | | 167 | + ).toEqual([child.id]) | | 168 | + expect( | | 169 | + (yield* Effect.promise(() => api.experimental.job.list({ sessionID: root.id, status: "completed" }))).map( | | 170 | + (item) => item.id, | | 171 | + ), | | 172 | + ).toEqual(["sh_root"]) | 163 | 173 |
| 164 | 174 | if (shellBg?.notificationID) yield* jobs.completeBackground(shellBg.notificationID) | 165 | 175 | expect(yield* Effect.promise(() => api.experimental.job.list({ sessionID: root.id, kind: "shell" }))).toEqual([]) | |
|