GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(core): archive projects via project.update and dedupe same-canon… · neumark/opencode@8b04ded

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages
    • client/src
      • effect
        • api
          • api.ts
        • generated
          • client.ts
      • promise/generated
        • client.ts
        • types.ts
    • core
      • src
        • project.ts
      • test
        • project.test.ts
    • schema/src
      • project.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/client/src/effect/api/api.ts‎

Copy file name to clipboardExpand all lines: packages/client/src/effect/api/api.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,6 +1707,7 @@ export type ProjectUpdateInput = {
17071707
readonly name?: string | undefined
17081708
readonly icon?: Project.Icon | undefined
17091709
readonly commands?: Project.Commands | undefined
1710+
readonly archived?: boolean | undefined
17101711
}
17111712
export type ProjectUpdateOutput = Project.Info
17121713
export type ProjectUpdateOperation<E = never> = (input: ProjectUpdateInput) => Effect.Effect<ProjectUpdateOutput, E>
Collapse file

‎packages/client/src/effect/generated/client.ts‎

Copy file name to clipboardExpand all lines: packages/client/src/effect/generated/client.ts
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,13 @@ const EndpointProjectUpdate = (raw: RawClient["server.project"]) => (input: Proj
11341134
preserveEffect<ProjectUpdateOutput>()(
11351135
raw["project.update"]({
11361136
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+
},
11381144
}).pipe(Effect.mapError(mapClientError)),
11391145
)
11401146

Collapse file

‎packages/client/src/promise/generated/client.ts‎

Copy file name to clipboardExpand all lines: packages/client/src/promise/generated/client.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,6 +1520,7 @@ export function make(options: ClientOptions) {
15201520
name: input["name"],
15211521
icon: input["icon"],
15221522
commands: input["commands"],
1523+
archived: input["archived"],
15231524
},
15241525
successStatus: 200,
15251526
declaredStatuses: [400, 401, 404],
Collapse file

‎packages/client/src/promise/generated/types.ts‎

Copy file name to clipboardExpand all lines: packages/client/src/promise/generated/types.ts
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5351,25 +5351,36 @@ export type ProjectUpdateInput = {
53515351
readonly name?: string
53525352
readonly icon?: { readonly url?: string; readonly override?: string; readonly color?: string }
53535353
readonly commands?: { readonly start?: string }
5354+
readonly archived?: boolean
53545355
}["canonical"]
53555356
readonly name?: {
53565357
readonly canonical?: string
53575358
readonly name?: string
53585359
readonly icon?: { readonly url?: string; readonly override?: string; readonly color?: string }
53595360
readonly commands?: { readonly start?: string }
5361+
readonly archived?: boolean
53605362
}["name"]
53615363
readonly icon?: {
53625364
readonly canonical?: string
53635365
readonly name?: string
53645366
readonly icon?: { readonly url?: string; readonly override?: string; readonly color?: string }
53655367
readonly commands?: { readonly start?: string }
5368+
readonly archived?: boolean
53665369
}["icon"]
53675370
readonly commands?: {
53685371
readonly canonical?: string
53695372
readonly name?: string
53705373
readonly icon?: { readonly url?: string; readonly override?: string; readonly color?: string }
53715374
readonly commands?: { readonly start?: string }
5375+
readonly archived?: boolean
53725376
}["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"]
53735384
}
53745385

53755386
export type ProjectUpdateOutput = Project
Collapse file

‎packages/core/src/project.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/project.ts
+29-1Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ const layer = Layer.effect(
243243
: input.commands.start
244244
? { start: input.commands.start }
245245
: null,
246+
time_archived:
247+
input.archived === undefined ? undefined : input.archived ? Date.now() : null,
246248
time_updated: Date.now(),
247249
})
248250
.where(eq(ProjectTable.id, input.projectID))
@@ -406,7 +408,7 @@ const layer = Layer.effect(
406408
lt(ProjectTable.time_active, cutoff),
407409
)
408410
const projects = yield* db
409-
.select({ id: ProjectTable.id, canonical: ProjectTable.worktree })
411+
.select({ id: ProjectTable.id, canonical: ProjectTable.worktree, active: ProjectTable.time_active })
410412
.from(ProjectTable)
411413
.where(and(idle, ne(ProjectTable.id, ID.global)))
412414
.all()
@@ -440,6 +442,32 @@ const layer = Layer.effect(
440442
}),
441443
{ concurrency: 8, discard: true },
442444
)
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+
)
443471
})
444472

445473
return Service.of({ list, update, activate, resolve, sweep })
Collapse file

‎packages/core/test/project.test.ts‎

Copy file name to clipboardExpand all lines: packages/core/test/project.test.ts
+45Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,51 @@ describe("Project archiving", () => {
171171
}),
172172
)
173173

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+
174219
it.live("archives projects whose directories are gone and unarchives them on resolve", () =>
175220
Effect.gen(function* () {
176221
const tmp = yield* Effect.acquireRelease(
Collapse file

‎packages/schema/src/project.ts‎

Copy file name to clipboardExpand all lines: packages/schema/src/project.ts
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export const UpdateInput = Schema.Struct({
5555
name: optional(Schema.String),
5656
icon: optional(Icon),
5757
commands: optional(Commands),
58+
/** Archives the Project (archived Projects are excluded from lists until unarchived). */
59+
archived: optional(Schema.Boolean),
5860
}).annotate({ identifier: "Project.UpdateInput" })
5961
export interface UpdateInput extends Schema.Schema.Type<typeof UpdateInput> {}
6062

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.