codeblog-app 0.1.0
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.
- package/bin/codeblog +2 -0
- package/drizzle/0000_init.sql +34 -0
- package/drizzle/meta/_journal.json +13 -0
- package/drizzle.config.ts +10 -0
- package/package.json +66 -0
- package/src/api/agents.ts +35 -0
- package/src/api/client.ts +96 -0
- package/src/api/feed.ts +25 -0
- package/src/api/notifications.ts +24 -0
- package/src/api/posts.ts +113 -0
- package/src/api/search.ts +13 -0
- package/src/api/tags.ts +13 -0
- package/src/api/trending.ts +38 -0
- package/src/auth/index.ts +46 -0
- package/src/auth/oauth.ts +69 -0
- package/src/cli/cmd/bookmark.ts +27 -0
- package/src/cli/cmd/comment.ts +39 -0
- package/src/cli/cmd/dashboard.ts +46 -0
- package/src/cli/cmd/feed.ts +68 -0
- package/src/cli/cmd/login.ts +38 -0
- package/src/cli/cmd/logout.ts +12 -0
- package/src/cli/cmd/notifications.ts +33 -0
- package/src/cli/cmd/post.ts +108 -0
- package/src/cli/cmd/publish.ts +44 -0
- package/src/cli/cmd/scan.ts +69 -0
- package/src/cli/cmd/search.ts +49 -0
- package/src/cli/cmd/setup.ts +86 -0
- package/src/cli/cmd/trending.ts +64 -0
- package/src/cli/cmd/vote.ts +35 -0
- package/src/cli/cmd/whoami.ts +50 -0
- package/src/cli/ui.ts +74 -0
- package/src/config/index.ts +40 -0
- package/src/flag/index.ts +23 -0
- package/src/global/index.ts +33 -0
- package/src/id/index.ts +20 -0
- package/src/index.ts +117 -0
- package/src/publisher/index.ts +136 -0
- package/src/scanner/__tests__/analyzer.test.ts +67 -0
- package/src/scanner/__tests__/fs-utils.test.ts +50 -0
- package/src/scanner/__tests__/platform.test.ts +27 -0
- package/src/scanner/__tests__/registry.test.ts +56 -0
- package/src/scanner/aider.ts +96 -0
- package/src/scanner/analyzer.ts +237 -0
- package/src/scanner/claude-code.ts +188 -0
- package/src/scanner/codex.ts +127 -0
- package/src/scanner/continue-dev.ts +95 -0
- package/src/scanner/cursor.ts +293 -0
- package/src/scanner/fs-utils.ts +123 -0
- package/src/scanner/index.ts +26 -0
- package/src/scanner/platform.ts +44 -0
- package/src/scanner/registry.ts +68 -0
- package/src/scanner/types.ts +62 -0
- package/src/scanner/vscode-copilot.ts +125 -0
- package/src/scanner/warp.ts +19 -0
- package/src/scanner/windsurf.ts +147 -0
- package/src/scanner/zed.ts +88 -0
- package/src/server/index.ts +48 -0
- package/src/storage/db.ts +68 -0
- package/src/storage/schema.sql.ts +39 -0
- package/src/storage/schema.ts +1 -0
- package/src/util/__tests__/context.test.ts +31 -0
- package/src/util/__tests__/lazy.test.ts +37 -0
- package/src/util/context.ts +23 -0
- package/src/util/error.ts +46 -0
- package/src/util/lazy.ts +18 -0
- package/src/util/log.ts +142 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { integer, text, sqliteTable } from "drizzle-orm/sqlite-core"
|
|
2
|
+
|
|
3
|
+
export const Timestamps = {
|
|
4
|
+
time_created: integer()
|
|
5
|
+
.notNull()
|
|
6
|
+
.$default(() => Date.now()),
|
|
7
|
+
time_updated: integer()
|
|
8
|
+
.notNull()
|
|
9
|
+
.$onUpdate(() => Date.now()),
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const published_sessions = sqliteTable("published_sessions", {
|
|
13
|
+
id: text().primaryKey(),
|
|
14
|
+
session_id: text().notNull(),
|
|
15
|
+
source: text().notNull(),
|
|
16
|
+
post_id: text(),
|
|
17
|
+
file_path: text().notNull(),
|
|
18
|
+
...Timestamps,
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
export const cached_posts = sqliteTable("cached_posts", {
|
|
22
|
+
id: text().primaryKey(),
|
|
23
|
+
title: text().notNull(),
|
|
24
|
+
content: text().notNull(),
|
|
25
|
+
author_name: text(),
|
|
26
|
+
votes: integer().default(0),
|
|
27
|
+
comments_count: integer().default(0),
|
|
28
|
+
tags: text(),
|
|
29
|
+
...Timestamps,
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
export const notifications_cache = sqliteTable("notifications_cache", {
|
|
33
|
+
id: text().primaryKey(),
|
|
34
|
+
type: text().notNull(),
|
|
35
|
+
message: text().notNull(),
|
|
36
|
+
read: integer().default(0),
|
|
37
|
+
post_id: text(),
|
|
38
|
+
...Timestamps,
|
|
39
|
+
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { published_sessions, cached_posts, notifications_cache } from "./schema.sql"
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { describe, test, expect } from "bun:test"
|
|
2
|
+
import { Context } from "../context"
|
|
3
|
+
|
|
4
|
+
describe("Context", () => {
|
|
5
|
+
test("create and provide context", () => {
|
|
6
|
+
const ctx = Context.create<string>("test")
|
|
7
|
+
|
|
8
|
+
Context.provide(ctx, "hello", () => {
|
|
9
|
+
expect(Context.use(ctx)).toBe("hello")
|
|
10
|
+
})
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
test("use returns undefined outside provider", () => {
|
|
14
|
+
const ctx = Context.create<number>("num")
|
|
15
|
+
expect(Context.use(ctx)).toBeUndefined()
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test("nested contexts work correctly", () => {
|
|
19
|
+
const ctx = Context.create<string>("nested")
|
|
20
|
+
|
|
21
|
+
Context.provide(ctx, "outer", () => {
|
|
22
|
+
expect(Context.use(ctx)).toBe("outer")
|
|
23
|
+
|
|
24
|
+
Context.provide(ctx, "inner", () => {
|
|
25
|
+
expect(Context.use(ctx)).toBe("inner")
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
expect(Context.use(ctx)).toBe("outer")
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
})
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { describe, test, expect } from "bun:test"
|
|
2
|
+
import { Lazy } from "../lazy"
|
|
3
|
+
|
|
4
|
+
describe("Lazy", () => {
|
|
5
|
+
test("initializes value on first call", () => {
|
|
6
|
+
let count = 0
|
|
7
|
+
const lazy = Lazy.create(() => {
|
|
8
|
+
count++
|
|
9
|
+
return 42
|
|
10
|
+
})
|
|
11
|
+
expect(lazy()).toBe(42)
|
|
12
|
+
expect(count).toBe(1)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
test("caches value on subsequent calls", () => {
|
|
16
|
+
let count = 0
|
|
17
|
+
const lazy = Lazy.create(() => {
|
|
18
|
+
count++
|
|
19
|
+
return "hello"
|
|
20
|
+
})
|
|
21
|
+
lazy()
|
|
22
|
+
lazy()
|
|
23
|
+
lazy()
|
|
24
|
+
expect(count).toBe(1)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
test("reset clears cached value", () => {
|
|
28
|
+
let count = 0
|
|
29
|
+
const lazy = Lazy.create(() => {
|
|
30
|
+
count++
|
|
31
|
+
return count
|
|
32
|
+
})
|
|
33
|
+
expect(lazy()).toBe(1)
|
|
34
|
+
lazy.reset()
|
|
35
|
+
expect(lazy()).toBe(2)
|
|
36
|
+
})
|
|
37
|
+
})
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "async_hooks"
|
|
2
|
+
|
|
3
|
+
export namespace Context {
|
|
4
|
+
export class NotFound extends Error {
|
|
5
|
+
constructor(public override readonly name: string) {
|
|
6
|
+
super(`No context found for ${name}`)
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function create<T>(name: string) {
|
|
11
|
+
const storage = new AsyncLocalStorage<T>()
|
|
12
|
+
return {
|
|
13
|
+
use() {
|
|
14
|
+
const result = storage.getStore()
|
|
15
|
+
if (!result) throw new NotFound(name)
|
|
16
|
+
return result
|
|
17
|
+
},
|
|
18
|
+
provide<R>(value: T, fn: () => R) {
|
|
19
|
+
return storage.run(value, fn)
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import z from "zod"
|
|
2
|
+
|
|
3
|
+
export abstract class NamedError extends Error {
|
|
4
|
+
abstract schema(): z.core.$ZodType
|
|
5
|
+
abstract toObject(): { name: string; data: any }
|
|
6
|
+
|
|
7
|
+
static create<Name extends string, Data extends z.core.$ZodType>(name: Name, data: Data) {
|
|
8
|
+
const schema = z
|
|
9
|
+
.object({
|
|
10
|
+
name: z.literal(name),
|
|
11
|
+
data,
|
|
12
|
+
})
|
|
13
|
+
.meta({ ref: name })
|
|
14
|
+
const result = class extends NamedError {
|
|
15
|
+
public static readonly Schema = schema
|
|
16
|
+
public override readonly name = name as Name
|
|
17
|
+
|
|
18
|
+
constructor(
|
|
19
|
+
public readonly data: z.input<Data>,
|
|
20
|
+
options?: ErrorOptions,
|
|
21
|
+
) {
|
|
22
|
+
super(name, options)
|
|
23
|
+
this.name = name
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static isInstance(input: any): input is InstanceType<typeof result> {
|
|
27
|
+
return typeof input === "object" && "name" in input && input.name === name
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
schema() {
|
|
31
|
+
return schema
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
toObject() {
|
|
35
|
+
return { name, data: this.data }
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
Object.defineProperty(result, "name", { value: name })
|
|
39
|
+
return result
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public static readonly Unknown = NamedError.create(
|
|
43
|
+
"UnknownError",
|
|
44
|
+
z.object({ message: z.string() }),
|
|
45
|
+
)
|
|
46
|
+
}
|
package/src/util/lazy.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function lazy<T>(fn: () => T) {
|
|
2
|
+
let value: T | undefined
|
|
3
|
+
let loaded = false
|
|
4
|
+
|
|
5
|
+
const result = (): T => {
|
|
6
|
+
if (loaded) return value as T
|
|
7
|
+
value = fn()
|
|
8
|
+
loaded = true
|
|
9
|
+
return value as T
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
result.reset = () => {
|
|
13
|
+
loaded = false
|
|
14
|
+
value = undefined
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return result
|
|
18
|
+
}
|
package/src/util/log.ts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import path from "path"
|
|
2
|
+
import fs from "fs/promises"
|
|
3
|
+
import { Global } from "../global"
|
|
4
|
+
import z from "zod"
|
|
5
|
+
|
|
6
|
+
export namespace Log {
|
|
7
|
+
export const Level = z.enum(["DEBUG", "INFO", "WARN", "ERROR"]).meta({ ref: "LogLevel", description: "Log level" })
|
|
8
|
+
export type Level = z.infer<typeof Level>
|
|
9
|
+
|
|
10
|
+
const levelPriority: Record<Level, number> = {
|
|
11
|
+
DEBUG: 0,
|
|
12
|
+
INFO: 1,
|
|
13
|
+
WARN: 2,
|
|
14
|
+
ERROR: 3,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let level: Level = "INFO"
|
|
18
|
+
|
|
19
|
+
function shouldLog(input: Level): boolean {
|
|
20
|
+
return levelPriority[input] >= levelPriority[level]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type Logger = {
|
|
24
|
+
debug(message?: any, extra?: Record<string, any>): void
|
|
25
|
+
info(message?: any, extra?: Record<string, any>): void
|
|
26
|
+
error(message?: any, extra?: Record<string, any>): void
|
|
27
|
+
warn(message?: any, extra?: Record<string, any>): void
|
|
28
|
+
tag(key: string, value: string): Logger
|
|
29
|
+
clone(): Logger
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const loggers = new Map<string, Logger>()
|
|
33
|
+
|
|
34
|
+
export const Default = create({ service: "default" })
|
|
35
|
+
|
|
36
|
+
export interface Options {
|
|
37
|
+
print: boolean
|
|
38
|
+
dev?: boolean
|
|
39
|
+
level?: Level
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let logpath = ""
|
|
43
|
+
export function file() {
|
|
44
|
+
return logpath
|
|
45
|
+
}
|
|
46
|
+
let write = (msg: any) => {
|
|
47
|
+
process.stderr.write(msg)
|
|
48
|
+
return msg.length
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function init(options: Options) {
|
|
52
|
+
if (options.level) level = options.level
|
|
53
|
+
cleanup(Global.Path.log)
|
|
54
|
+
if (options.print) return
|
|
55
|
+
logpath = path.join(
|
|
56
|
+
Global.Path.log,
|
|
57
|
+
options.dev ? "dev.log" : new Date().toISOString().split(".")[0].replace(/:/g, "") + ".log",
|
|
58
|
+
)
|
|
59
|
+
const logfile = Bun.file(logpath)
|
|
60
|
+
await fs.truncate(logpath).catch(() => {})
|
|
61
|
+
const writer = logfile.writer()
|
|
62
|
+
write = async (msg: any) => {
|
|
63
|
+
const num = writer.write(msg)
|
|
64
|
+
writer.flush()
|
|
65
|
+
return num
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function cleanup(dir: string) {
|
|
70
|
+
const glob = new Bun.Glob("????-??-??T??????.log")
|
|
71
|
+
const files = await Array.fromAsync(
|
|
72
|
+
glob.scan({
|
|
73
|
+
cwd: dir,
|
|
74
|
+
absolute: true,
|
|
75
|
+
}),
|
|
76
|
+
)
|
|
77
|
+
if (files.length <= 5) return
|
|
78
|
+
const filesToDelete = files.slice(0, -10)
|
|
79
|
+
await Promise.all(filesToDelete.map((file) => fs.unlink(file).catch(() => {})))
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function formatError(error: Error, depth = 0): string {
|
|
83
|
+
const result = error.message
|
|
84
|
+
return error.cause instanceof Error && depth < 10
|
|
85
|
+
? result + " Caused by: " + formatError(error.cause, depth + 1)
|
|
86
|
+
: result
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
let last = Date.now()
|
|
90
|
+
export function create(tags?: Record<string, any>) {
|
|
91
|
+
tags = tags || {}
|
|
92
|
+
|
|
93
|
+
const service = tags["service"]
|
|
94
|
+
if (service && typeof service === "string") {
|
|
95
|
+
const cached = loggers.get(service)
|
|
96
|
+
if (cached) return cached
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function build(message: any, extra?: Record<string, any>) {
|
|
100
|
+
const prefix = Object.entries({
|
|
101
|
+
...tags,
|
|
102
|
+
...extra,
|
|
103
|
+
})
|
|
104
|
+
.filter(([_, value]) => value !== undefined && value !== null)
|
|
105
|
+
.map(([key, value]) => {
|
|
106
|
+
const prefix = `${key}=`
|
|
107
|
+
if (value instanceof Error) return prefix + formatError(value)
|
|
108
|
+
if (typeof value === "object") return prefix + JSON.stringify(value)
|
|
109
|
+
return prefix + value
|
|
110
|
+
})
|
|
111
|
+
.join(" ")
|
|
112
|
+
const next = new Date()
|
|
113
|
+
const diff = next.getTime() - last
|
|
114
|
+
last = next.getTime()
|
|
115
|
+
return [next.toISOString().split(".")[0], "+" + diff + "ms", prefix, message].filter(Boolean).join(" ") + "\n"
|
|
116
|
+
}
|
|
117
|
+
const result: Logger = {
|
|
118
|
+
debug(message?: any, extra?: Record<string, any>) {
|
|
119
|
+
if (shouldLog("DEBUG")) write("DEBUG " + build(message, extra))
|
|
120
|
+
},
|
|
121
|
+
info(message?: any, extra?: Record<string, any>) {
|
|
122
|
+
if (shouldLog("INFO")) write("INFO " + build(message, extra))
|
|
123
|
+
},
|
|
124
|
+
error(message?: any, extra?: Record<string, any>) {
|
|
125
|
+
if (shouldLog("ERROR")) write("ERROR " + build(message, extra))
|
|
126
|
+
},
|
|
127
|
+
warn(message?: any, extra?: Record<string, any>) {
|
|
128
|
+
if (shouldLog("WARN")) write("WARN " + build(message, extra))
|
|
129
|
+
},
|
|
130
|
+
tag(key: string, value: string) {
|
|
131
|
+
if (tags) tags[key] = value
|
|
132
|
+
return result
|
|
133
|
+
},
|
|
134
|
+
clone() {
|
|
135
|
+
return Log.create({ ...tags })
|
|
136
|
+
},
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (service && typeof service === "string") loggers.set(service, result)
|
|
140
|
+
return result
|
|
141
|
+
}
|
|
142
|
+
}
|