GeezerVison is showing github.com — feat(core): archive projects via project.update and dedupe same-canon… · neumark/opencode@8b04ded
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 | Original file line number | Diff line number | Diff line change |
|---|
@@ -1707,6 +1707,7 @@ export type ProjectUpdateInput = { | 1707 | 1707 | readonly name?: string | undefined | 1708 | 1708 | readonly icon?: Project.Icon | undefined | 1709 | 1709 | readonly commands?: Project.Commands | undefined | | 1710 | + readonly archived?: boolean | undefined | 1710 | 1711 | } | 1711 | 1712 | export type ProjectUpdateOutput = Project.Info | 1712 | 1713 | export type ProjectUpdateOperation<E = never> = (input: ProjectUpdateInput) => Effect.Effect<ProjectUpdateOutput, E> | |
Collapse file Copy file name to clipboardExpand all lines: packages/client/src/effect/generated/client.ts +7-1Lines changed: 7 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1134,7 +1134,13 @@ const EndpointProjectUpdate = (raw: RawClient["server.project"]) => (input: Proj | 1134 | 1134 | preserveEffect<ProjectUpdateOutput>()( | 1135 | 1135 | raw["project.update"]({ | 1136 | 1136 | params: { projectID: input["projectID"] }, | 1137 | | - payload: { canonical: input["canonical"], name: input["name"], icon: input["icon"], commands: input["commands"] }, | | 1137 | + payload: { | | 1138 | + canonical: input["canonical"], | | 1139 | + name: input["name"], | | 1140 | + icon: input["icon"], | | 1141 | + commands: input["commands"], | | 1142 | + archived: input["archived"], | | 1143 | + }, | 1138 | 1144 | }).pipe(Effect.mapError(mapClientError)), | 1139 | 1145 | ) | 1140 | 1146 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/client/src/promise/generated/client.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1520,6 +1520,7 @@ export function make(options: ClientOptions) { | 1520 | 1520 | name: input["name"], | 1521 | 1521 | icon: input["icon"], | 1522 | 1522 | commands: input["commands"], | | 1523 | + archived: input["archived"], | 1523 | 1524 | }, | 1524 | 1525 | successStatus: 200, | 1525 | 1526 | declaredStatuses: [400, 401, 404], | |
Collapse file Copy file name to clipboardExpand all lines: packages/client/src/promise/generated/types.ts +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5351,25 +5351,36 @@ export type ProjectUpdateInput = { | 5351 | 5351 | readonly name?: string | 5352 | 5352 | readonly icon?: { readonly url?: string; readonly override?: string; readonly color?: string } | 5353 | 5353 | readonly commands?: { readonly start?: string } | | 5354 | + readonly archived?: boolean | 5354 | 5355 | }["canonical"] | 5355 | 5356 | readonly name?: { | 5356 | 5357 | readonly canonical?: string | 5357 | 5358 | readonly name?: string | 5358 | 5359 | readonly icon?: { readonly url?: string; readonly override?: string; readonly color?: string } | 5359 | 5360 | readonly commands?: { readonly start?: string } | | 5361 | + readonly archived?: boolean | 5360 | 5362 | }["name"] | 5361 | 5363 | readonly icon?: { | 5362 | 5364 | readonly canonical?: string | 5363 | 5365 | readonly name?: string | 5364 | 5366 | readonly icon?: { readonly url?: string; readonly override?: string; readonly color?: string } | 5365 | 5367 | readonly commands?: { readonly start?: string } | | 5368 | + readonly archived?: boolean | 5366 | 5369 | }["icon"] | 5367 | 5370 | readonly commands?: { | 5368 | 5371 | readonly canonical?: string | 5369 | 5372 | readonly name?: string | 5370 | 5373 | readonly icon?: { readonly url?: string; readonly override?: string; readonly color?: string } | 5371 | 5374 | readonly commands?: { readonly start?: string } | | 5375 | + readonly archived?: boolean | 5372 | 5376 | }["commands"] | | 5377 | + readonly archived?: { | | 5378 | + readonly canonical?: string | | 5379 | + readonly name?: string | | 5380 | + readonly icon?: { readonly url?: string; readonly override?: string; readonly color?: string } | | 5381 | + readonly commands?: { readonly start?: string } | | 5382 | + readonly archived?: boolean | | 5383 | + }["archived"] | 5373 | 5384 | } | 5374 | 5385 |
| 5375 | 5386 | export type ProjectUpdateOutput = Project | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/src/project.ts +29-1Lines changed: 29 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -243,6 +243,8 @@ const layer = Layer.effect( | 243 | 243 | : input.commands.start | 244 | 244 | ? { start: input.commands.start } | 245 | 245 | : null, | | 246 | + time_archived: | | 247 | + input.archived === undefined ? undefined : input.archived ? Date.now() : null, | 246 | 248 | time_updated: Date.now(), | 247 | 249 | }) | 248 | 250 | .where(eq(ProjectTable.id, input.projectID)) | @@ -406,7 +408,7 @@ const layer = Layer.effect( | 406 | 408 | lt(ProjectTable.time_active, cutoff), | 407 | 409 | ) | 408 | 410 | const projects = yield* db | 409 | | - .select({ id: ProjectTable.id, canonical: ProjectTable.worktree }) | | 411 | + .select({ id: ProjectTable.id, canonical: ProjectTable.worktree, active: ProjectTable.time_active }) | 410 | 412 | .from(ProjectTable) | 411 | 413 | .where(and(idle, ne(ProjectTable.id, ID.global))) | 412 | 414 | .all() | @@ -440,6 +442,32 @@ const layer = Layer.effect( | 440 | 442 | }), | 441 | 443 | { concurrency: 8, discard: true }, | 442 | 444 | ) | | 445 | + // Same-canonical residue: rows that outlived an id change (the fallback id | | 446 | + // from before a remote or root commit was known, markerless adoption rows) | | 447 | + // linger beside the live row forever — directory existence can never | | 448 | + // archive them because the shared canonical still exists. Archive an idle | | 449 | + // row when another row claims the same canonical directory with newer | | 450 | + // activity; sessions keep their attribution through the archived row. | | 451 | + const rows = yield* db | | 452 | + .select({ id: ProjectTable.id, canonical: ProjectTable.worktree, active: ProjectTable.time_active }) | | 453 | + .from(ProjectTable) | | 454 | + .all() | | 455 | + .pipe(Effect.orDie) | | 456 | + yield* Effect.forEach( | | 457 | + projects, | | 458 | + Effect.fnUntraced(function* (project) { | | 459 | + if (!rows.some((row) => row.id !== project.id && row.canonical === project.canonical && row.active > project.active)) return | | 460 | + const row = yield* db | | 461 | + .update(ProjectTable) | | 462 | + .set({ time_archived: Date.now(), time_updated: sql`${ProjectTable.time_updated}` }) | | 463 | + .where(and(eq(ProjectTable.id, project.id), idle)) | | 464 | + .returning() | | 465 | + .get() | | 466 | + .pipe(Effect.orDie) | | 467 | + if (row) yield* bus.publish(ProjectSchema.Event.Updated, fromRow(row)) | | 468 | + }), | | 469 | + { concurrency: 8, discard: true }, | | 470 | + ) | 443 | 471 | }) | 444 | 472 |
| 445 | 473 | return Service.of({ list, update, activate, resolve, sweep }) | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/test/project.test.ts +45Lines changed: 45 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -171,6 +171,51 @@ describe("Project archiving", () => { | 171 | 171 | }), | 172 | 172 | ) | 173 | 173 |
| | 174 | + it.effect("archives and unarchives through project.update", () => | | 175 | + Effect.gen(function* () { | | 176 | + const db = (yield* Database.Service).db | | 177 | + const project = yield* Project.Service | | 178 | + yield* db | | 179 | + .insert(ProjectTable) | | 180 | + .values({ id: Project.ID.make("manual"), worktree: abs("/manual"), sandboxes: [], time_active: 2 }) | | 181 | + .run() | | 182 | + | | 183 | + const archived = yield* project.update({ projectID: Project.ID.make("manual"), archived: true }) | | 184 | + expect(archived.time.archived).toBeNumber() | | 185 | + expect((yield* project.list()).map((item) => item.id)).toEqual([]) | | 186 | + | | 187 | + const restored = yield* project.update({ projectID: Project.ID.make("manual"), archived: false }) | | 188 | + expect(restored.time.archived).toBeUndefined() | | 189 | + expect((yield* project.list()).map((item) => item.id)).toEqual([Project.ID.make("manual")]) | | 190 | + }), | | 191 | + ) | | 192 | + | | 193 | + it.live("archives same-canonical residue beside the live row", () => | | 194 | + Effect.gen(function* () { | | 195 | + const tmp = yield* Effect.acquireRelease( | | 196 | + Effect.promise(() => tmpdir()), | | 197 | + (tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()), | | 198 | + ) | | 199 | + const directory = path.join(tmp.path, "repo") | | 200 | + yield* Effect.promise(() => fs.mkdir(directory)) | | 201 | + const db = (yield* Database.Service).db | | 202 | + const project = yield* Project.Service | | 203 | + yield* db | | 204 | + .insert(ProjectTable) | | 205 | + .values([ | | 206 | + { id: Project.ID.make("stale"), worktree: abs(directory), sandboxes: [], time_active: 1, time_updated: 1 }, | | 207 | + { id: Project.ID.make("live"), worktree: abs(directory), sandboxes: [], time_active: 2, time_updated: 1 }, | | 208 | + ]) | | 209 | + .run() | | 210 | + | | 211 | + yield* project.sweep() | | 212 | + | | 213 | + expect((yield* project.list()).map((item) => item.id)).toEqual([Project.ID.make("live")]) | | 214 | + const stale = (yield* project.list({ archived: true })).find((item) => item.id === Project.ID.make("stale")) | | 215 | + expect(stale?.time.archived).toBeNumber() | | 216 | + }), | | 217 | + ) | | 218 | + | 174 | 219 | it.live("archives projects whose directories are gone and unarchives them on resolve", () => | 175 | 220 | Effect.gen(function* () { | 176 | 221 | const tmp = yield* Effect.acquireRelease( | |
Collapse file Copy file name to clipboardExpand all lines: packages/schema/src/project.ts +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -55,6 +55,8 @@ export const UpdateInput = Schema.Struct({ | 55 | 55 | name: optional(Schema.String), | 56 | 56 | icon: optional(Icon), | 57 | 57 | commands: optional(Commands), | | 58 | + /** Archives the Project (archived Projects are excluded from lists until unarchived). */ | | 59 | + archived: optional(Schema.Boolean), | 58 | 60 | }).annotate({ identifier: "Project.UpdateInput" }) | 59 | 61 | export interface UpdateInput extends Schema.Schema.Type<typeof UpdateInput> {} | 60 | 62 |
| |
|