@kkelly-offical/kkcode 0.1.7 → 0.2.1
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/LICENSE +674 -674
- package/README.md +452 -387
- package/package.json +50 -46
- package/src/agent/agent.mjs +228 -220
- package/src/agent/custom-agent-loader.mjs +6 -3
- package/src/agent/generator.mjs +2 -2
- package/src/agent/prompt/assistant.txt +12 -0
- package/src/agent/prompt/bug-hunter.txt +89 -89
- package/src/agent/prompt/frontend-designer.txt +58 -58
- package/src/agent/prompt/guide.txt +1 -1
- package/src/agent/prompt/longagent-blueprint-agent.txt +83 -83
- package/src/agent/prompt/longagent-coding-agent.txt +37 -37
- package/src/agent/prompt/longagent-debugging-agent.txt +46 -46
- package/src/agent/prompt/longagent-preview-agent.txt +63 -63
- package/src/command/custom-commands.mjs +2 -2
- package/src/commands/agent.mjs +1 -1
- package/src/commands/background.mjs +145 -4
- package/src/commands/chat.mjs +117 -76
- package/src/commands/config.mjs +148 -1
- package/src/commands/doctor.mjs +30 -6
- package/src/commands/init.mjs +32 -6
- package/src/commands/longagent.mjs +117 -0
- package/src/commands/mcp.mjs +275 -43
- package/src/commands/permission.mjs +1 -1
- package/src/commands/session.mjs +195 -140
- package/src/commands/skill.mjs +63 -0
- package/src/commands/theme.mjs +1 -1
- package/src/config/defaults.mjs +280 -260
- package/src/config/import-config.mjs +1 -1
- package/src/config/load-config.mjs +61 -4
- package/src/config/schema.mjs +591 -574
- package/src/context.mjs +4 -1
- package/src/core/constants.mjs +97 -91
- package/src/core/types.mjs +1 -1
- package/src/github/api.mjs +78 -78
- package/src/github/auth.mjs +294 -286
- package/src/github/flow.mjs +298 -298
- package/src/github/workspace.mjs +225 -212
- package/src/index.mjs +84 -82
- package/src/knowledge/frontend-aesthetics.txt +38 -38
- package/src/mcp/client-http.mjs +139 -141
- package/src/mcp/client-sse.mjs +297 -288
- package/src/mcp/client-stdio.mjs +534 -533
- package/src/mcp/constants.mjs +2 -2
- package/src/mcp/registry.mjs +498 -479
- package/src/mcp/stdio-framing.mjs +135 -133
- package/src/mcp/tool-result.mjs +24 -24
- package/src/observability/edit-diagnostics.mjs +449 -0
- package/src/observability/index.mjs +42 -42
- package/src/observability/metrics.mjs +165 -137
- package/src/observability/tracer.mjs +137 -137
- package/src/onboarding.mjs +209 -0
- package/src/orchestration/background-manager.mjs +567 -372
- package/src/orchestration/background-worker.mjs +419 -305
- package/src/orchestration/interruption-reason.mjs +21 -0
- package/src/orchestration/longagent-manager.mjs +197 -171
- package/src/orchestration/stage-scheduler.mjs +733 -728
- package/src/orchestration/subagent-router.mjs +7 -1
- package/src/orchestration/task-scheduler.mjs +219 -7
- package/src/permission/engine.mjs +1 -1
- package/src/permission/exec-policy.mjs +370 -370
- package/src/permission/file-edit-policy.mjs +108 -0
- package/src/permission/prompt.mjs +1 -1
- package/src/permission/rules.mjs +116 -7
- package/src/plugin/builtin-hooks/post-edit-format.mjs +2 -1
- package/src/plugin/builtin-hooks/post-edit-typecheck.mjs +104 -40
- package/src/plugin/hook-bus.mjs +19 -5
- package/src/plugin/manifest-loader.mjs +222 -0
- package/src/provider/anthropic.mjs +396 -390
- package/src/provider/ollama.mjs +7 -1
- package/src/provider/openai.mjs +382 -340
- package/src/provider/retry-policy.mjs +74 -68
- package/src/provider/router.mjs +242 -241
- package/src/provider/sse.mjs +104 -104
- package/src/provider/wizard.mjs +556 -0
- package/src/repl/capability-facade.mjs +30 -0
- package/src/repl/command-surface.mjs +23 -0
- package/src/repl/controller-entry.mjs +40 -0
- package/src/repl/core-shell.mjs +208 -0
- package/src/repl/dialog-router.mjs +87 -0
- package/src/repl/input-engine.mjs +76 -0
- package/src/repl/keymap.mjs +7 -0
- package/src/repl/operator-surface.mjs +15 -0
- package/src/repl/permission-flow.mjs +49 -0
- package/src/repl/runtime-facade.mjs +36 -0
- package/src/repl/slash-router.mjs +62 -0
- package/src/repl/state-store.mjs +29 -0
- package/src/repl/turn-controller.mjs +58 -0
- package/src/repl/verification.mjs +23 -0
- package/src/repl.mjs +3368 -2981
- package/src/rules/load-rules.mjs +3 -3
- package/src/runtime.mjs +1 -1
- package/src/session/agent-transaction.mjs +86 -0
- package/src/session/checkpoint.mjs +302 -302
- package/src/session/compaction.mjs +298 -298
- package/src/session/engine.mjs +417 -232
- package/src/session/longagent-4stage.mjs +467 -460
- package/src/session/longagent-hybrid.mjs +1344 -1097
- package/src/session/longagent-plan.mjs +376 -365
- package/src/session/longagent-project-memory.mjs +53 -53
- package/src/session/longagent-scaffold.mjs +291 -291
- package/src/session/longagent-task-bus.mjs +138 -54
- package/src/session/longagent-utils.mjs +828 -472
- package/src/session/longagent.mjs +911 -900
- package/src/session/loop.mjs +1005 -930
- package/src/session/prompt/agent.txt +25 -25
- package/src/session/prompt/anthropic.txt +150 -150
- package/src/session/prompt/beast.txt +1 -1
- package/src/session/prompt/plan.txt +31 -31
- package/src/session/prompt/qwen.txt +46 -46
- package/src/session/recovery.mjs +21 -0
- package/src/session/rollback.mjs +196 -195
- package/src/session/routing-observability.mjs +72 -0
- package/src/session/runtime-state.mjs +47 -0
- package/src/session/store.mjs +523 -519
- package/src/session/system-prompt.mjs +308 -273
- package/src/session/task-validator.mjs +267 -267
- package/src/session/usability-gates.mjs +2 -2
- package/src/skill/builtin/commit.mjs +64 -64
- package/src/skill/builtin/design.mjs +76 -76
- package/src/skill/generator.mjs +18 -2
- package/src/skill/registry.mjs +642 -390
- package/src/storage/audit-store.mjs +18 -11
- package/src/storage/event-log.mjs +7 -1
- package/src/storage/ghost-commit-store.mjs +243 -245
- package/src/storage/paths.mjs +13 -0
- package/src/theme/default-theme.mjs +1 -1
- package/src/theme/markdown.mjs +4 -0
- package/src/theme/schema.mjs +1 -1
- package/src/theme/status-bar.mjs +162 -158
- package/src/tool/audit-wrapper.mjs +18 -2
- package/src/tool/edit-transaction.mjs +23 -0
- package/src/tool/executor.mjs +26 -1
- package/src/tool/file-read-state.mjs +65 -0
- package/src/tool/git-auto.mjs +526 -526
- package/src/tool/git-full-auto.mjs +487 -478
- package/src/tool/mutation-guard.mjs +54 -0
- package/src/tool/prompt/edit.txt +3 -3
- package/src/tool/prompt/multiedit.txt +1 -0
- package/src/tool/prompt/notebookedit.txt +2 -1
- package/src/tool/prompt/patch.txt +25 -24
- package/src/tool/prompt/read.txt +3 -3
- package/src/tool/prompt/sysinfo.txt +29 -0
- package/src/tool/prompt/task.txt +66 -4
- package/src/tool/prompt/write.txt +2 -2
- package/src/tool/question-prompt.mjs +99 -93
- package/src/tool/registry.mjs +1701 -1343
- package/src/tool/task-tool.mjs +14 -6
- package/src/ui/activity-renderer.mjs +667 -664
- package/src/ui/repl-background-panel.mjs +7 -0
- package/src/ui/repl-capability-panel.mjs +9 -0
- package/src/ui/repl-dashboard.mjs +54 -4
- package/src/ui/repl-help.mjs +110 -0
- package/src/ui/repl-operator-panel.mjs +12 -0
- package/src/ui/repl-route-feedback.mjs +35 -0
- package/src/ui/repl-status-view.mjs +76 -0
- package/src/ui/repl-task-panel.mjs +5 -0
- package/src/ui/repl-transcript-panel.mjs +56 -0
- package/src/ui/repl-turn-summary.mjs +135 -0
- package/src/usage/pricing.mjs +122 -121
- package/src/usage/usage-meter.mjs +1 -0
- package/src/util/git.mjs +562 -519
- package/src/util/template.mjs +6 -1
package/src/context.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { configureSessionStore } from "./session/store.mjs"
|
|
|
4
4
|
import { configureEventLog } from "./storage/event-log.mjs"
|
|
5
5
|
import { configureAuditStore } from "./storage/audit-store.mjs"
|
|
6
6
|
import { checkWorkspaceTrust } from "./permission/workspace-trust.mjs"
|
|
7
|
+
import { loadProfile } from "./onboarding.mjs"
|
|
7
8
|
|
|
8
9
|
export async function buildContext(options = {}) {
|
|
9
10
|
const configState = await loadConfig(options.cwd ?? process.cwd())
|
|
@@ -23,10 +24,12 @@ export async function buildContext(options = {}) {
|
|
|
23
24
|
const themeState = await loadTheme(configState, options.themeFile ?? null)
|
|
24
25
|
const cwd = options.cwd ?? process.cwd()
|
|
25
26
|
const trustState = options.trustState ?? await checkWorkspaceTrust({ cwd, cliTrust: Boolean(options.trust), isTTY: process.stdin.isTTY })
|
|
27
|
+
const profile = await loadProfile()
|
|
26
28
|
return {
|
|
27
29
|
configState,
|
|
28
30
|
themeState,
|
|
29
|
-
trustState
|
|
31
|
+
trustState,
|
|
32
|
+
profile
|
|
30
33
|
}
|
|
31
34
|
}
|
|
32
35
|
|
package/src/core/constants.mjs
CHANGED
|
@@ -1,91 +1,97 @@
|
|
|
1
|
-
export const MODES = ["
|
|
2
|
-
|
|
3
|
-
export const TOOL_STATUSES = ["running", "completed", "error", "cancelled"]
|
|
4
|
-
|
|
5
|
-
export const PERMISSION_DECISIONS = ["allow_once", "allow_session", "deny"]
|
|
6
|
-
|
|
7
|
-
export const DEFAULT_MAX_STEPS = 8
|
|
8
|
-
export const DEFAULT_REQUEST_TIMEOUT_MS = 120000
|
|
9
|
-
export const DEFAULT_RETRY_ATTEMPTS = 3
|
|
10
|
-
export const DEFAULT_LONGAGENT_RETRY_STORM_THRESHOLD = 3
|
|
11
|
-
export const DEFAULT_LONGAGENT_TOKEN_ALERT_THRESHOLD = 120000
|
|
12
|
-
|
|
13
|
-
export const LONGAGENT_4STAGE_STAGES = {
|
|
14
|
-
PREVIEW: "preview",
|
|
15
|
-
BLUEPRINT: "blueprint",
|
|
16
|
-
CODING: "coding",
|
|
17
|
-
DEBUGGING: "debugging"
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const EVENT_TYPES = {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
1
|
+
export const MODES = ["assistant", "plan", "agent", "longagent"]
|
|
2
|
+
|
|
3
|
+
export const TOOL_STATUSES = ["running", "completed", "error", "cancelled"]
|
|
4
|
+
|
|
5
|
+
export const PERMISSION_DECISIONS = ["allow_once", "allow_session", "deny"]
|
|
6
|
+
|
|
7
|
+
export const DEFAULT_MAX_STEPS = 8
|
|
8
|
+
export const DEFAULT_REQUEST_TIMEOUT_MS = 120000
|
|
9
|
+
export const DEFAULT_RETRY_ATTEMPTS = 3
|
|
10
|
+
export const DEFAULT_LONGAGENT_RETRY_STORM_THRESHOLD = 3
|
|
11
|
+
export const DEFAULT_LONGAGENT_TOKEN_ALERT_THRESHOLD = 120000
|
|
12
|
+
|
|
13
|
+
export const LONGAGENT_4STAGE_STAGES = {
|
|
14
|
+
PREVIEW: "preview",
|
|
15
|
+
BLUEPRINT: "blueprint",
|
|
16
|
+
CODING: "coding",
|
|
17
|
+
DEBUGGING: "debugging"
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const EVENT_TYPES = {
|
|
21
|
+
ROUTE_DECISION: "route.decision",
|
|
22
|
+
AGENT_CONTINUATION_INTERRUPTED: "agent.continuation.interrupted",
|
|
23
|
+
AGENT_CONTINUATION_RESUMED: "agent.continuation.resumed",
|
|
24
|
+
TURN_START: "turn.start",
|
|
25
|
+
TURN_STEP_START: "turn.step.start",
|
|
26
|
+
TURN_STEP_FINISH: "turn.step.finish",
|
|
27
|
+
TURN_FINISH: "turn.finish",
|
|
28
|
+
TURN_ERROR: "turn.error",
|
|
29
|
+
TOOL_START: "tool.start",
|
|
30
|
+
TOOL_FINISH: "tool.finish",
|
|
31
|
+
TOOL_ERROR: "tool.error",
|
|
32
|
+
PERMISSION_ASKED: "permission.asked",
|
|
33
|
+
PERMISSION_DECIDED: "permission.decided",
|
|
34
|
+
REVIEW_DECISION: "review.decision",
|
|
35
|
+
MCP_HEALTH: "mcp.health",
|
|
36
|
+
MCP_REQUEST: "mcp.request",
|
|
37
|
+
MCP_RECONNECT: "mcp.reconnect",
|
|
38
|
+
MCP_CIRCUIT_OPEN: "mcp.circuit_open",
|
|
39
|
+
MCP_CIRCUIT_CLOSE: "mcp.circuit_close",
|
|
40
|
+
LONGAGENT_HEARTBEAT: "longagent.heartbeat",
|
|
41
|
+
LONGAGENT_ALERT: "longagent.alert",
|
|
42
|
+
LONGAGENT_PHASE_CHANGED: "longagent.phase.changed",
|
|
43
|
+
LONGAGENT_GATE_CHECKED: "longagent.gate.checked",
|
|
44
|
+
LONGAGENT_RECOVERY_ENTERED: "longagent.recovery.entered",
|
|
45
|
+
LONGAGENT_INTAKE_STARTED: "longagent.intake.started",
|
|
46
|
+
LONGAGENT_PLAN_FROZEN: "longagent.plan.frozen",
|
|
47
|
+
LONGAGENT_STAGE_STARTED: "longagent.stage.started",
|
|
48
|
+
LONGAGENT_STAGE_TASK_DISPATCHED: "longagent.stage.task.dispatched",
|
|
49
|
+
LONGAGENT_STAGE_TASK_FINISHED: "longagent.stage.task.finished",
|
|
50
|
+
LONGAGENT_STAGE_FINISHED: "longagent.stage.finished",
|
|
51
|
+
LONGAGENT_SCAFFOLD_COMPLETE: "longagent.scaffold.complete",
|
|
52
|
+
LONGAGENT_GIT_BRANCH_CREATED: "longagent.git.branch.created",
|
|
53
|
+
LONGAGENT_GIT_STAGE_COMMITTED: "longagent.git.stage.committed",
|
|
54
|
+
LONGAGENT_GIT_MERGED: "longagent.git.merged",
|
|
55
|
+
LONGAGENT_4STAGE_PREVIEW_START: "longagent.4stage.preview.start",
|
|
56
|
+
LONGAGENT_4STAGE_PREVIEW_COMPLETE: "longagent.4stage.preview.complete",
|
|
57
|
+
LONGAGENT_4STAGE_BLUEPRINT_START: "longagent.4stage.blueprint.start",
|
|
58
|
+
LONGAGENT_4STAGE_BLUEPRINT_COMPLETE: "longagent.4stage.blueprint.complete",
|
|
59
|
+
LONGAGENT_4STAGE_CODING_START: "longagent.4stage.coding.start",
|
|
60
|
+
LONGAGENT_4STAGE_CODING_COMPLETE: "longagent.4stage.coding.complete",
|
|
61
|
+
LONGAGENT_4STAGE_DEBUGGING_START: "longagent.4stage.debugging.start",
|
|
62
|
+
LONGAGENT_4STAGE_DEBUGGING_COMPLETE: "longagent.4stage.debugging.complete",
|
|
63
|
+
LONGAGENT_4STAGE_RETURN_TO_CODING: "longagent.4stage.return_to_coding",
|
|
64
|
+
LONGAGENT_HYBRID_PREVIEW_START: "longagent.hybrid.preview.start",
|
|
65
|
+
LONGAGENT_HYBRID_PREVIEW_COMPLETE: "longagent.hybrid.preview.complete",
|
|
66
|
+
LONGAGENT_HYBRID_BLUEPRINT_START: "longagent.hybrid.blueprint.start",
|
|
67
|
+
LONGAGENT_HYBRID_BLUEPRINT_COMPLETE: "longagent.hybrid.blueprint.complete",
|
|
68
|
+
LONGAGENT_HYBRID_DEBUGGING_START: "longagent.hybrid.debugging.start",
|
|
69
|
+
LONGAGENT_HYBRID_DEBUGGING_COMPLETE: "longagent.hybrid.debugging.complete",
|
|
70
|
+
LONGAGENT_HYBRID_RETURN_TO_CODING: "longagent.hybrid.return_to_coding",
|
|
71
|
+
LONGAGENT_HYBRID_BLUEPRINT_REVIEW: "longagent.hybrid.blueprint.review",
|
|
72
|
+
LONGAGENT_HYBRID_BLUEPRINT_VALIDATED: "longagent.hybrid.blueprint.validated",
|
|
73
|
+
LONGAGENT_HYBRID_CROSS_REVIEW: "longagent.hybrid.cross_review",
|
|
74
|
+
LONGAGENT_HYBRID_INCREMENTAL_GATE: "longagent.hybrid.incremental_gate",
|
|
75
|
+
LONGAGENT_HYBRID_CONTEXT_COMPRESSED: "longagent.hybrid.context_compressed",
|
|
76
|
+
LONGAGENT_HYBRID_BUDGET_WARNING: "longagent.hybrid.budget_warning",
|
|
77
|
+
LONGAGENT_HYBRID_CHECKPOINT_RESUMED: "longagent.hybrid.checkpoint_resumed",
|
|
78
|
+
LONGAGENT_HYBRID_REPLAN: "longagent.hybrid.replan",
|
|
79
|
+
LONGAGENT_HYBRID_MEMORY_LOADED: "longagent.hybrid.memory_loaded",
|
|
80
|
+
LONGAGENT_HYBRID_MEMORY_SAVED: "longagent.hybrid.memory_saved",
|
|
81
|
+
SESSION_COMPACTED: "session.compacted",
|
|
82
|
+
TURN_USAGE_UPDATE: "turn.usage.update",
|
|
83
|
+
ROUTE_DECISION: "route.decision",
|
|
84
|
+
AGENT_CONTINUATION_RESUMED: "agent.continuation.resumed",
|
|
85
|
+
STREAM_TEXT_START: "stream.text.start",
|
|
86
|
+
STREAM_THINKING_START: "stream.thinking.start",
|
|
87
|
+
LONGAGENT_DEGRADATION_APPLIED: "longagent.degradation.applied",
|
|
88
|
+
LONGAGENT_WRITE_LOOP_DETECTED: "longagent.write_loop.detected",
|
|
89
|
+
LONGAGENT_SEMANTIC_ERROR_REPEATED: "longagent.semantic_error.repeated",
|
|
90
|
+
LONGAGENT_PHASE_TIMEOUT: "longagent.phase.timeout",
|
|
91
|
+
LONGAGENT_GIT_CONFLICT_RESOLUTION: "longagent.git.conflict_resolution",
|
|
92
|
+
LONGAGENT_CHECKPOINT_CLEANED: "longagent.checkpoint.cleaned",
|
|
93
|
+
LONGAGENT_HYBRID_CHECKPOINT_INVALID: "longagent.hybrid.checkpoint_invalid",
|
|
94
|
+
LONGAGENT_STAGE_TASK_SKIPPED: "longagent.stage.task.skipped",
|
|
95
|
+
LONGAGENT_STOP_REQUESTED: "longagent.stop.requested",
|
|
96
|
+
PROVIDER_FALLBACK: "provider.fallback"
|
|
97
|
+
}
|
package/src/core/types.mjs
CHANGED
package/src/github/api.mjs
CHANGED
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
const API_BASE = "https://api.github.com"
|
|
2
|
-
|
|
3
|
-
function headers(token) {
|
|
4
|
-
return {
|
|
5
|
-
Authorization: `Bearer ${token}`,
|
|
6
|
-
Accept: "application/vnd.github+json",
|
|
7
|
-
"X-GitHub-Api-Version": "2022-11-28"
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
async function ghFetch(token, path, params = {}) {
|
|
12
|
-
const url = new URL(`${API_BASE}${path}`)
|
|
13
|
-
for (const [k, v] of Object.entries(params)) {
|
|
14
|
-
if (v !== undefined && v !== null) url.searchParams.set(k, String(v))
|
|
15
|
-
}
|
|
16
|
-
const res = await fetch(url.href, { headers: headers(token) })
|
|
17
|
-
if (!res.ok) {
|
|
18
|
-
const body = await res.text().catch(() => "")
|
|
19
|
-
throw new Error(`GitHub API ${res.status}: ${path} — ${body.slice(0, 200)}`)
|
|
20
|
-
}
|
|
21
|
-
return res.json()
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export async function listUserRepos(token, { page = 1, perPage = 20, sort = "pushed" } = {}) {
|
|
25
|
-
const repos = await ghFetch(token, "/user/repos", {
|
|
26
|
-
sort,
|
|
27
|
-
per_page: perPage,
|
|
28
|
-
page,
|
|
29
|
-
affiliation: "owner,collaborator,organization_member"
|
|
30
|
-
})
|
|
31
|
-
return repos.map((r) => ({
|
|
32
|
-
full_name: r.full_name,
|
|
33
|
-
name: r.name,
|
|
34
|
-
owner: r.owner.login,
|
|
35
|
-
description: r.description || "",
|
|
36
|
-
default_branch: r.default_branch,
|
|
37
|
-
stars: r.stargazers_count,
|
|
38
|
-
pushed_at: r.pushed_at,
|
|
39
|
-
private: r.private
|
|
40
|
-
}))
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export async function searchRepos(token, query, login) {
|
|
44
|
-
const q = login ? `${query} user:${login}` : query
|
|
45
|
-
const data = await ghFetch(token, "/search/repositories", { q, per_page: 20, sort: "updated" })
|
|
46
|
-
return (data.items || []).map((r) => ({
|
|
47
|
-
full_name: r.full_name,
|
|
48
|
-
name: r.name,
|
|
49
|
-
owner: r.owner.login,
|
|
50
|
-
description: r.description || "",
|
|
51
|
-
default_branch: r.default_branch,
|
|
52
|
-
stars: r.stargazers_count,
|
|
53
|
-
pushed_at: r.pushed_at,
|
|
54
|
-
private: r.private
|
|
55
|
-
}))
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export async function listBranches(token, owner, repo) {
|
|
59
|
-
const branches = await ghFetch(token, `/repos/${owner}/${repo}/branches`, { per_page: 100 })
|
|
60
|
-
return branches.map((b) => ({
|
|
61
|
-
name: b.name,
|
|
62
|
-
protected: b.protected
|
|
63
|
-
}))
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export async function getRepo(token, owner, repo) {
|
|
67
|
-
const r = await ghFetch(token, `/repos/${owner}/${repo}`)
|
|
68
|
-
return {
|
|
69
|
-
full_name: r.full_name,
|
|
70
|
-
name: r.name,
|
|
71
|
-
owner: r.owner.login,
|
|
72
|
-
description: r.description || "",
|
|
73
|
-
default_branch: r.default_branch,
|
|
74
|
-
stars: r.stargazers_count,
|
|
75
|
-
pushed_at: r.pushed_at,
|
|
76
|
-
private: r.private
|
|
77
|
-
}
|
|
78
|
-
}
|
|
1
|
+
const API_BASE = "https://api.github.com"
|
|
2
|
+
|
|
3
|
+
function headers(token) {
|
|
4
|
+
return {
|
|
5
|
+
Authorization: `Bearer ${token}`,
|
|
6
|
+
Accept: "application/vnd.github+json",
|
|
7
|
+
"X-GitHub-Api-Version": "2022-11-28"
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async function ghFetch(token, path, params = {}) {
|
|
12
|
+
const url = new URL(`${API_BASE}${path}`)
|
|
13
|
+
for (const [k, v] of Object.entries(params)) {
|
|
14
|
+
if (v !== undefined && v !== null) url.searchParams.set(k, String(v))
|
|
15
|
+
}
|
|
16
|
+
const res = await fetch(url.href, { headers: headers(token) })
|
|
17
|
+
if (!res.ok) {
|
|
18
|
+
const body = await res.text().catch(() => "")
|
|
19
|
+
throw new Error(`GitHub API ${res.status}: ${path} — ${body.slice(0, 200)}`)
|
|
20
|
+
}
|
|
21
|
+
return res.json()
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function listUserRepos(token, { page = 1, perPage = 20, sort = "pushed" } = {}) {
|
|
25
|
+
const repos = await ghFetch(token, "/user/repos", {
|
|
26
|
+
sort,
|
|
27
|
+
per_page: perPage,
|
|
28
|
+
page,
|
|
29
|
+
affiliation: "owner,collaborator,organization_member"
|
|
30
|
+
})
|
|
31
|
+
return repos.map((r) => ({
|
|
32
|
+
full_name: r.full_name,
|
|
33
|
+
name: r.name,
|
|
34
|
+
owner: r.owner.login,
|
|
35
|
+
description: r.description || "",
|
|
36
|
+
default_branch: r.default_branch,
|
|
37
|
+
stars: r.stargazers_count,
|
|
38
|
+
pushed_at: r.pushed_at,
|
|
39
|
+
private: r.private
|
|
40
|
+
}))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function searchRepos(token, query, login) {
|
|
44
|
+
const q = login ? `${query} user:${login}` : query
|
|
45
|
+
const data = await ghFetch(token, "/search/repositories", { q, per_page: 20, sort: "updated" })
|
|
46
|
+
return (data.items || []).map((r) => ({
|
|
47
|
+
full_name: r.full_name,
|
|
48
|
+
name: r.name,
|
|
49
|
+
owner: r.owner.login,
|
|
50
|
+
description: r.description || "",
|
|
51
|
+
default_branch: r.default_branch,
|
|
52
|
+
stars: r.stargazers_count,
|
|
53
|
+
pushed_at: r.pushed_at,
|
|
54
|
+
private: r.private
|
|
55
|
+
}))
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function listBranches(token, owner, repo) {
|
|
59
|
+
const branches = await ghFetch(token, `/repos/${owner}/${repo}/branches`, { per_page: 100 })
|
|
60
|
+
return branches.map((b) => ({
|
|
61
|
+
name: b.name,
|
|
62
|
+
protected: b.protected
|
|
63
|
+
}))
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function getRepo(token, owner, repo) {
|
|
67
|
+
const r = await ghFetch(token, `/repos/${owner}/${repo}`)
|
|
68
|
+
return {
|
|
69
|
+
full_name: r.full_name,
|
|
70
|
+
name: r.name,
|
|
71
|
+
owner: r.owner.login,
|
|
72
|
+
description: r.description || "",
|
|
73
|
+
default_branch: r.default_branch,
|
|
74
|
+
stars: r.stargazers_count,
|
|
75
|
+
pushed_at: r.pushed_at,
|
|
76
|
+
private: r.private
|
|
77
|
+
}
|
|
78
|
+
}
|