Skip to content

Commit 9a9a503

Browse files
committed
ignore: rm slop commnand (only for opencode repo this isnt shipping)
1 parent 767a81f commit 9a9a503

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

.opencode/command/hello.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

.opencode/command/rmslop.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
description: Remove AI code slop
3+
---
4+
5+
Check the diff against dev, and remove all AI generated slop introduced in this branch.
6+
7+
This includes:
8+
- Extra comments that a human wouldn't add or is inconsistent with the rest of the file
9+
- Extra defensive checks or try/catch blocks that are abnormal for that area of the codebase (especially if called by trusted / validated codepaths)
10+
- Casts to any to get around type issues
11+
- Any other style that is inconsistent with the file
12+
13+
Report at the end with only a 1-3 sentence summary of what you changed

packages/opencode/src/project/project.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { $ } from "bun"
55
import { Storage } from "../storage/storage"
66
import { Log } from "../util/log"
77
import { Flag } from "@/flag/flag"
8+
import { Global } from "../global"
9+
import fs from "fs/promises"
810

911
export namespace Project {
1012
const log = Log.create({ service: "project" })
@@ -77,6 +79,10 @@ export namespace Project {
7779
.text()
7880
.then((x) => path.resolve(worktree, x.trim()))
7981
const projectID = id || "global"
82+
// Migrate sessions from "global" project if this repo just got its first commit
83+
if (id) {
84+
await migrateFromGlobal(id, worktree)
85+
}
8086
const project: Info = {
8187
id: projectID,
8288
worktree,
@@ -90,6 +96,32 @@ export namespace Project {
9096
return project
9197
}
9298

99+
async function migrateFromGlobal(newProjectID: string, worktree: string) {
100+
const globalProject = await Storage.read<Info>(["project", "global"]).catch(() => null)
101+
if (!globalProject || globalProject.worktree !== worktree) return
102+
103+
const dir = path.join(Global.Path.data, "storage")
104+
const globalSessionsDir = path.join(dir, "session", "global")
105+
if (!(await fs.stat(globalSessionsDir).catch(() => null))) return
106+
107+
log.info("migrating sessions from global", { newProjectID, worktree })
108+
const newSessionsDir = path.join(dir, "session", newProjectID)
109+
110+
for await (const file of new Bun.Glob("*.json").scan({ cwd: globalSessionsDir, absolute: true })) {
111+
const session = await Bun.file(file).json()
112+
// Only migrate sessions that belong to this worktree
113+
if (session.directory && !session.directory.startsWith(worktree)) continue
114+
115+
session.projectID = newProjectID
116+
const dest = path.join(newSessionsDir, path.basename(file))
117+
log.info("migrating session", { from: file, to: dest })
118+
await Bun.write(dest, JSON.stringify(session, null, 2))
119+
await Bun.file(file)
120+
.unlink()
121+
.catch(() => {})
122+
}
123+
}
124+
93125
export async function setInitialized(projectID: string) {
94126
await Storage.update<Info>(["project", projectID], (draft) => {
95127
draft.time.initialized = Date.now()

0 commit comments

Comments
 (0)