@kenkaiiii/ggcoder 5.86.3 → 5.87.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/README.md +23 -31
- package/assets/skills/bulletproof/SKILL.md +2 -0
- package/assets/skills/compliance-guard/SKILL.md +1 -1
- package/assets/skills/lean/SKILL.md +2 -0
- package/dist/app-sidecar/progress-manager.d.ts +2 -20
- package/dist/app-sidecar/progress-manager.js +2 -15
- package/dist/app-sidecar/progress-manager.js.map +1 -1
- package/dist/app-sidecar/royale.d.ts +26 -24
- package/dist/app-sidecar/royale.js +85 -187
- package/dist/app-sidecar/royale.js.map +1 -1
- package/dist/app-sidecar.js +32 -40
- package/dist/app-sidecar.js.map +1 -1
- package/dist/core/autopilot-gate.js +2 -3
- package/dist/core/autopilot-gate.js.map +1 -1
- package/dist/core/bundled-agents.js +7 -27
- package/dist/core/bundled-agents.js.map +1 -1
- package/dist/core/checklist-items.d.ts +0 -8
- package/dist/core/checklist-items.js +0 -8
- package/dist/core/checklist-items.js.map +1 -1
- package/dist/core/code-retrieval.d.ts +1 -1
- package/dist/core/code-retrieval.js +2 -2
- package/dist/core/code-retrieval.js.map +1 -1
- package/dist/core/mcp/deferred-catalog.d.ts +1 -1
- package/dist/core/mcp/deferred-catalog.js +1 -1
- package/dist/core/skills.d.ts +6 -0
- package/dist/core/skills.js +11 -3
- package/dist/core/skills.js.map +1 -1
- package/dist/core/subagent-policy.d.ts +6 -0
- package/dist/core/subagent-policy.js +21 -2
- package/dist/core/subagent-policy.js.map +1 -1
- package/dist/core/subagent-receipt.d.ts +2 -2
- package/dist/core/subagent-receipt.js +5 -8
- package/dist/core/subagent-receipt.js.map +1 -1
- package/dist/core/trophies/catalog-more.js +0 -20
- package/dist/core/trophies/catalog-more.js.map +1 -1
- package/dist/core/trophies/engine.js +0 -4
- package/dist/core/trophies/engine.js.map +1 -1
- package/dist/core/trophies/types.d.ts +1 -1
- package/dist/core/trophies/types.js +0 -2
- package/dist/core/trophies/types.js.map +1 -1
- package/dist/goals-agent/goal-team.js +3 -4
- package/dist/goals-agent/goal-team.js.map +1 -1
- package/dist/modes/acp-mode.js +0 -1
- package/dist/modes/acp-mode.js.map +1 -1
- package/dist/tools/index.d.ts +0 -2
- package/dist/tools/index.js +0 -6
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/operations.js +1 -1
- package/dist/tools/operations.js.map +1 -1
- package/dist/tools/prompt-hints.js +0 -6
- package/dist/tools/prompt-hints.js.map +1 -1
- package/dist/tools/skill.js +11 -5
- package/dist/tools/skill.js.map +1 -1
- package/dist/tools/tool-tiers.d.ts +2 -1
- package/dist/tools/tool-tiers.js +2 -3
- package/dist/tools/tool-tiers.js.map +1 -1
- package/dist/ui/components/SkillsOverlay.js +2 -1
- package/dist/ui/components/SkillsOverlay.js.map +1 -1
- package/package.json +6 -5
- package/assets/skills/clarify/SKILL.md +0 -39
- package/assets/skills/code-review/SKILL.md +0 -82
- package/assets/skills/code-review/references/agent-diffs.md +0 -27
- package/assets/skills/code-review/references/tests.md +0 -19
- package/assets/skills/evidence-led-ui/LICENSES.md +0 -79
- package/assets/skills/evidence-led-ui/SKILL.md +0 -95
- package/assets/skills/evidence-led-ui/references/anti-defaults.md +0 -110
- package/assets/skills/evidence-led-ui/references/archetypes.md +0 -97
- package/assets/skills/evidence-led-ui/references/craft-rulings.md +0 -242
- package/assets/skills/evidence-led-ui/references/direction.md +0 -116
- package/assets/skills/evidence-led-ui/references/methodology.md +0 -64
- package/assets/skills/evidence-led-ui/references/observed-patterns.md +0 -68
- package/assets/skills/evidence-led-ui/references/production-contract.md +0 -148
- package/assets/skills/evidence-led-ui/references/provenance.md +0 -142
- package/assets/skills/evidence-led-ui/references/quality-rubric.md +0 -126
- package/assets/skills/evidence-led-ui/references/ui-libraries.md +0 -30
- package/assets/skills/refactoring/SKILL.md +0 -72
- package/assets/skills/refactoring/references/agent-pitfalls.md +0 -46
- package/assets/skills/refactoring/references/legacy.md +0 -70
- package/assets/skills/refactoring/references/smells.md +0 -71
- package/assets/skills/root-cause/SKILL.md +0 -46
- package/assets/skills/shared-language/SKILL.md +0 -32
- package/assets/skills/tdd/SKILL.md +0 -42
- package/dist/app-sidecar/royale-bug.d.ts +0 -19
- package/dist/app-sidecar/royale-bug.js +0 -112
- package/dist/app-sidecar/royale-bug.js.map +0 -1
- package/dist/app-sidecar/royale-deploy.d.ts +0 -5
- package/dist/app-sidecar/royale-deploy.js +0 -76
- package/dist/app-sidecar/royale-deploy.js.map +0 -1
- package/dist/tools/code-nav.d.ts +0 -29
- package/dist/tools/code-nav.js +0 -299
- package/dist/tools/code-nav.js.map +0 -1
- package/dist/tools/search-code.d.ts +0 -10
- package/dist/tools/search-code.js +0 -90
- package/dist/tools/search-code.js.map +0 -1
package/README.md
CHANGED
|
@@ -67,21 +67,21 @@ You can still add your own MCPs in `~/.gg/mcp.json` or `.gg/mcp.json`. But start
|
|
|
67
67
|
|
|
68
68
|
Switch mid-conversation with `/model`. Not locked to anyone.
|
|
69
69
|
|
|
70
|
-
| Provider | Models
|
|
71
|
-
| ----------------- |
|
|
72
|
-
| **Anthropic** | Claude Fable 5.1, Opus 5.5, Sonnet 5.5, Haiku 5.5
|
|
73
|
-
| **OpenAI** | GPT-6 Astra, GPT-6.1 Sol, GPT-6 Luna
|
|
74
|
-
| **Gemini** | Gemini 3.1 Pro (Preview), 3.8 Flash, 3.5 Flash, 3.5 Flash Lite, 3.1 Flash Lite
|
|
75
|
-
| **xAI (Grok)** | Grok 4.7
|
|
76
|
-
| **Moonshot** | Kimi K3, K2.8 Preview (Kimi sign-in), K2.7 Code, K2.7 Code HighSpeed
|
|
77
|
-
| **Z.AI (GLM)** | GLM-5.3, GLM-5.3-Flash
|
|
78
|
-
| **MiniMax** | MiniMax M3
|
|
79
|
-
| **Xiaomi (MiMo)** | MiMo-V2.6-Pro, MiMo-V2.6-Flash, MiMo-V2.6-Pro-UltraSpeed
|
|
80
|
-
| **DeepSeek** | DeepSeek V4 Pro, V4.1 Flash
|
|
81
|
-
| **Sakana (Fugu)** | Fugu, Fugu Max, Fugu Ultra
|
|
82
|
-
| **OpenRouter** | Qwen3.8 Max
|
|
83
|
-
| **Hugging Face** | Kimi K2.7 Code, DeepSeek V4.1 Flash, GPT-OSS 120B (Inference Providers router)
|
|
84
|
-
| **Local** | Any model on an OpenAI-compatible server: Ollama, LM Studio, llama.cpp, vLLM
|
|
70
|
+
| Provider | Models | Auth |
|
|
71
|
+
| ----------------- | ------------------------------------------------------------------------------ | ---------------- |
|
|
72
|
+
| **Anthropic** | Claude Fable 5.1, Opus 5.5, Sonnet 5.5, Haiku 5.5 | OAuth |
|
|
73
|
+
| **OpenAI** | GPT-6 Astra, GPT-6.1 Sol, GPT-6 Luna | OAuth |
|
|
74
|
+
| **Gemini** | Gemini 3.1 Pro (Preview), 3.8 Flash, 3.5 Flash, 3.5 Flash Lite, 3.1 Flash Lite | OAuth |
|
|
75
|
+
| **xAI (Grok)** | Grok 4.7 | OAuth or API key |
|
|
76
|
+
| **Moonshot** | Kimi K3, K2.8 Preview (Kimi sign-in), K2.7 Code, K2.7 Code HighSpeed | OAuth or API key |
|
|
77
|
+
| **Z.AI (GLM)** | GLM-5.3, GLM-5.3-Flash | API key |
|
|
78
|
+
| **MiniMax** | MiniMax M3 | API key |
|
|
79
|
+
| **Xiaomi (MiMo)** | MiMo-V2.6-Pro, MiMo-V2.6-Flash, MiMo-V2.6-Pro-UltraSpeed | API key |
|
|
80
|
+
| **DeepSeek** | DeepSeek V4 Pro, V4.1 Flash | API key |
|
|
81
|
+
| **Sakana (Fugu)** | Fugu, Fugu Max, Fugu Ultra | API key |
|
|
82
|
+
| **OpenRouter** | Qwen3.8 Max | API key |
|
|
83
|
+
| **Hugging Face** | Kimi K2.7 Code, DeepSeek V4.1 Flash, GPT-OSS 120B (Inference Providers router) | API key |
|
|
84
|
+
| **Local** | Any model on an OpenAI-compatible server: Ollama, LM Studio, llama.cpp, vLLM | None |
|
|
85
85
|
|
|
86
86
|
Every hosted model above except GLM-5.3, DeepSeek V4 Pro, and GPT-OSS 120B accepts images.
|
|
87
87
|
|
|
@@ -152,7 +152,6 @@ GG Coder comes with a focused set of tools. Only six core tools — `read`, `wri
|
|
|
152
152
|
| `skill` | Load a skill's instructions |
|
|
153
153
|
| `tool_search` | Load an on-demand tool by capability |
|
|
154
154
|
| `find` / `ls` | Find files by glob pattern / list a directory |
|
|
155
|
-
| `code_search` / `code_nav` | Find code by meaning / jump to exact definitions and callers |
|
|
156
155
|
| `web_fetch` / `web_search` | Fetch a URL / search the web |
|
|
157
156
|
| `steroids` | Find real production repos similar to yours and read how they do it |
|
|
158
157
|
| `source_path` | Locate an installed dependency's source |
|
|
@@ -203,21 +202,14 @@ Reusable behaviors across projects. Drop `.md` files in:
|
|
|
203
202
|
|
|
204
203
|
They get loaded into the system prompt automatically. The agent knows what it can do without you explaining it each session. <kbd>Ctrl+S</kbd> opens a pane to browse and toggle them.
|
|
205
204
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
| Skill | Fires on
|
|
209
|
-
| ------------------ |
|
|
210
|
-
| `
|
|
211
|
-
| `
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
| `durable` | User data must not be lost — first database/table, migrations, backfills/imports, destructive operations, backups and recovery; any store (Postgres, MySQL, SQLite, Mongo, serverless). |
|
|
215
|
-
| `evidence-led-ui` | Broad or design-sensitive UI work — new screens, redesigns, design systems, accessibility passes. |
|
|
216
|
-
| `lean` | Speed and resource efficiency — slow loading/startup, jank, high CPU, memory leaks and hogging, zombie/orphan processes, bundle bloat, dead code/styles, Core Web Vitals; while building anything that should stay fast, or a perf pass on an existing project. Any stack: web, backend, Electron, Tauri, mobile, native, game, ML. |
|
|
217
|
-
| `refactoring` | Restructuring existing code without changing behavior — "refactor", "clean up", "reduce tech debt", "modernize" or migrate legacy code; test-guarded steps, revert-on-red, characterization tests for untested code. |
|
|
218
|
-
| `root-cause` | A bug that resists the obvious fix, makes no sense, or keeps coming back — gated diagnosis from red repro to ranked hypotheses to regression test. |
|
|
219
|
-
| `shared-language` | Fuzzy or drifting domain vocabulary, recurring naming decisions, and hard-to-reverse decisions worth recording (glossary + decision records). |
|
|
220
|
-
| `tdd` | Test-driven development — red-green-refactor with pre-agreed seams, when the user asks for test-first work. |
|
|
205
|
+
Two ship built in, and route themselves when the work matches:
|
|
206
|
+
|
|
207
|
+
| Skill | Fires on |
|
|
208
|
+
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
209
|
+
| `compliance-guard` | Legal exposure — personal data, consent, marketing email/SMS, payments, UGC, minors, or a licensed/regulated feature. |
|
|
210
|
+
| `durable` | User data must not be lost — first database/table, migrations, backfills/imports, destructive operations, backups and recovery; any store (Postgres, MySQL, SQLite, Mongo, serverless). |
|
|
211
|
+
|
|
212
|
+
Two more, `bulletproof` (security) and `lean` (performance), are hidden from routine work and load only for the app's Checklist audits.
|
|
221
213
|
|
|
222
214
|
---
|
|
223
215
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: bulletproof
|
|
3
3
|
description: "Use for attacker-reachable code: auth, tokens, crypto, untrusted input, secrets, tenant data, CI, agent tools. Do NOT use for local scripts without auth or network."
|
|
4
|
+
# Checklist audits only (Security, Dependencies, Secrets / Performance); hidden from routine coding after the 27 Oct 2026 skill-value bench.
|
|
5
|
+
hidden: true
|
|
4
6
|
license: Apache-2.0. Content is defensive engineering guidance, not a security certification or a penetration test. See references/provenance.md.
|
|
5
7
|
compatibility: Works offline from the bundled references, a snapshot dated 22 October 2026. Versions, CVEs and incident details decay fast; re-verify date-sensitive claims with web access before stating them as current. Never certifies that software is secure.
|
|
6
8
|
---
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: compliance-guard
|
|
3
|
-
description: Use when shipping to real users risks legal exposure — privacy, cookies/tracking, payments, minors, AI features, user content, terms. Do NOT use for local-only work or pure security hardening.
|
|
3
|
+
description: Use when shipping to real users risks legal exposure — privacy, consent, cookies/tracking, marketing emails, payments, minors, AI features, user content, terms. Do NOT use for local-only work or pure security hardening.
|
|
4
4
|
license: Apache-2.0. Content is engineering guidance, not legal advice. See references/provenance.md.
|
|
5
5
|
compatibility: Static review works offline from the bundled references. Legal status changes constantly; date-sensitive claims must be re-verified with web access before being stated as current. Never certifies compliance.
|
|
6
6
|
---
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: lean
|
|
3
3
|
description: "Use when speed or resource use matters: slow pages or startup, memory leaks, high CPU, bundle size, N+1 queries. Do NOT use for correctness bugs."
|
|
4
|
+
# Checklist audits only (Security, Dependencies, Secrets / Performance); hidden from routine coding after the 27 Oct 2026 skill-value bench.
|
|
5
|
+
hidden: true
|
|
4
6
|
license: Performance engineering guidance, not a benchmark certification. Sources and snapshot date are recorded at the foot of each reference file.
|
|
5
7
|
compatibility: Snapshot dated 3 October 2026; Node release schedule, Core Web Vitals browser support and the current Next.js version re-verified 22 October 2026. Thresholds and tool names decay — re-verify before asserting them as current.
|
|
6
8
|
---
|
|
@@ -1,28 +1,10 @@
|
|
|
1
|
-
import type { RoyaleBugCategory } from "./royale-bug.js";
|
|
2
|
-
/** What a finished run did, beyond its commits, for GG Royale. */
|
|
3
|
-
export interface RunExtras {
|
|
4
|
-
/** The goal this run worked on (its coordinator's run), if any. */
|
|
5
|
-
goalId?: string | null;
|
|
6
|
-
/** The run handed work to workers (spawn_agent). */
|
|
7
|
-
workers?: boolean;
|
|
8
|
-
/** A deploy or publish command ran and succeeded. */
|
|
9
|
-
deployed?: boolean;
|
|
10
|
-
}
|
|
11
|
-
/** One run's outcome as GG Royale hears it (counts and labels only). */
|
|
12
|
-
export interface RunOutcome extends RunExtras {
|
|
13
|
-
commits: number;
|
|
14
|
-
bug?: RoyaleBugCategory | null;
|
|
15
|
-
}
|
|
16
1
|
import type { ProgressSnapshot } from "../core/progress/types.js";
|
|
17
2
|
export interface ProgressManager {
|
|
18
3
|
/** Current snapshot for GET /progress + the SSE ready path. */
|
|
19
4
|
snapshot: () => ProgressSnapshot;
|
|
20
5
|
/** Award XP for one successfully completed run (prompt + any new commits). */
|
|
21
|
-
awardRun: (cwd: string, runStartedAt: number, originId?: string
|
|
6
|
+
awardRun: (cwd: string, runStartedAt: number, originId?: string) => Promise<void>;
|
|
22
7
|
/** Close the ~/.gg fs.watch + clear any pending debounce (leak-free shutdown). */
|
|
23
8
|
dispose: () => void;
|
|
24
9
|
}
|
|
25
|
-
export declare function createProgressManager(agentDir: string, broadcastAll: (snapshot: ProgressSnapshot, originId?: string) => void
|
|
26
|
-
/** Optional: called after each successful run award with the number of newly
|
|
27
|
-
* detected commits (0 if none). Must not throw (GG Royale reporting). */
|
|
28
|
-
onRunAwarded?: (outcome: RunOutcome) => void): Promise<ProgressManager>;
|
|
10
|
+
export declare function createProgressManager(agentDir: string, broadcastAll: (snapshot: ProgressSnapshot, originId?: string) => void): Promise<ProgressManager>;
|
|
@@ -8,10 +8,7 @@ import { loadProgress, peekProgress, updateProgress } from "../core/progress/sto
|
|
|
8
8
|
import { awardPrompt, awardCommits } from "../core/progress/engine.js";
|
|
9
9
|
import { detectNewCommits, repoKey } from "../core/progress/git-xp.js";
|
|
10
10
|
import { rebuildFromSessions } from "../core/progress/rebuild.js";
|
|
11
|
-
export async function createProgressManager(agentDir, broadcastAll
|
|
12
|
-
/** Optional: called after each successful run award with the number of newly
|
|
13
|
-
* detected commits (0 if none). Must not throw (GG Royale reporting). */
|
|
14
|
-
onRunAwarded) {
|
|
11
|
+
export async function createProgressManager(agentDir, broadcastAll) {
|
|
15
12
|
// Boot: recovery chain main → backup → coding + chat session rebuild → empty.
|
|
16
13
|
const coderSessionsDir = path.join(agentDir, "sessions");
|
|
17
14
|
let file = await loadProgress({
|
|
@@ -29,10 +26,9 @@ onRunAwarded) {
|
|
|
29
26
|
function snapshot() {
|
|
30
27
|
return buildSnapshot(file);
|
|
31
28
|
}
|
|
32
|
-
async function awardRun(cwd, runStartedAt, originId
|
|
29
|
+
async function awardRun(cwd, runStartedAt, originId) {
|
|
33
30
|
try {
|
|
34
31
|
const now = Date.now();
|
|
35
|
-
let newCommits = 0;
|
|
36
32
|
const updated = await updateProgress(async (f) => {
|
|
37
33
|
const levelBefore = levelForXp(f.xp);
|
|
38
34
|
awardPrompt(f, now, cwd);
|
|
@@ -46,7 +42,6 @@ onRunAwarded) {
|
|
|
46
42
|
const detected = await detectNewCommits(cwd, lastHead, runStartedAt);
|
|
47
43
|
if (detected && detected.commits.length > 0) {
|
|
48
44
|
awardCommits(f, detected.commits, now, cwd);
|
|
49
|
-
newCommits = detected.commits.length;
|
|
50
45
|
}
|
|
51
46
|
}
|
|
52
47
|
f.repos[key] = { lastHead: probe.head };
|
|
@@ -62,14 +57,6 @@ onRunAwarded) {
|
|
|
62
57
|
file = updated;
|
|
63
58
|
lastSeenNonce = updated.lastEvent?.nonce ?? null;
|
|
64
59
|
broadcastAll(buildSnapshot(updated), originId);
|
|
65
|
-
try {
|
|
66
|
-
onRunAwarded?.({ commits: newCommits, ...(bug ? { bug } : {}), ...extras });
|
|
67
|
-
}
|
|
68
|
-
catch (err) {
|
|
69
|
-
log("DEBUG", "app-sidecar", "run outcome hook failed", {
|
|
70
|
-
message: err instanceof Error ? err.message : String(err),
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
60
|
}
|
|
74
61
|
catch (err) {
|
|
75
62
|
log("DEBUG", "app-sidecar", "progress award failed", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"progress-manager.js","sourceRoot":"","sources":["../../src/app-sidecar/progress-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,OAAO,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CA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AC;SAC1D,CAAC,CAAC;IACL,CAAC;IAED,2EAA2E;IAC3E,qEAAqE;IACrE,SAAS,OAAO;QACd,IAAI,aAAa,EAAE,CAAC;YAClB,YAAY,CAAC,aAAa,CAAC,CAAC;YAC5B,aAAa,GAAG,IAAI,CAAC;QACvB,CAAC;QACD,IAAI,CAAC;YACH,eAAe,EAAE,KAAK,EAAE,CAAC;QAC3B,CAAC;QAAC,MAAM,CAAC;YACP,iDAAiD;QACnD,CAAC;QACD,eAAe,GAAG,IAAI,CAAC;IACzB,CAAC;IAED,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;AACzC,CAAC"}
|
|
@@ -1,38 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/** The live GG World server. GG_WORLD_URL overrides it. */
|
|
2
|
+
export declare const DEFAULT_WORLD_URL = "https://gg-world.buzzbeamaustralia.workers.dev";
|
|
3
|
+
/** The retired GG Royale server. Links made with it belong to the live World
|
|
4
|
+
* server (same database), so they are never re-registered. */
|
|
5
|
+
export declare const LEGACY_ROYALE_URL = "https://gg-royale.buzzbeamaustralia.workers.dev";
|
|
5
6
|
export interface RoyaleFile {
|
|
6
7
|
serverUrl?: string;
|
|
7
8
|
playerId: string;
|
|
8
9
|
deviceToken: string;
|
|
9
10
|
linkedAt: number;
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
/**
|
|
13
|
+
* A World server reply, passed through for the app to read: `status` is the
|
|
14
|
+
* HTTP status (409 stale ver, 400 validation with `body.error`, ...), or 0
|
|
15
|
+
* when the server couldn't be reached. Never throws.
|
|
16
|
+
*/
|
|
17
|
+
export interface WorldResult {
|
|
18
|
+
status: number;
|
|
19
|
+
body: unknown;
|
|
14
20
|
}
|
|
15
|
-
export interface
|
|
16
|
-
claimable: number;
|
|
17
|
-
streak: number;
|
|
18
|
-
playing: number;
|
|
19
|
-
}
|
|
20
|
-
export interface RoyaleOptions {
|
|
21
|
+
export interface WorldLinkOptions {
|
|
21
22
|
agentDir: string;
|
|
22
23
|
version: string;
|
|
23
24
|
env?: NodeJS.ProcessEnv;
|
|
24
25
|
fetchImpl?: typeof fetch;
|
|
25
26
|
now?: () => number;
|
|
26
27
|
}
|
|
27
|
-
export interface
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
export interface WorldLink {
|
|
29
|
+
/** GET /api/world/profile. Signs up on first use. */
|
|
30
|
+
worldGet: () => Promise<WorldResult>;
|
|
31
|
+
/** PUT /api/world/profile with `{ ver, patch }`. */
|
|
32
|
+
worldPut: (ver: number, patch: unknown) => Promise<WorldResult>;
|
|
33
|
+
/** DELETE /api/world/me (the online save only). */
|
|
34
|
+
worldDelete: () => Promise<WorldResult>;
|
|
35
|
+
/** POST /api/world/live: a one-time live-world ticket `{ world, ticket, url }`. */
|
|
36
|
+
worldLive: () => Promise<WorldResult>;
|
|
37
|
+
/** DELETE /api/world/account; on success the local link file is removed. */
|
|
38
|
+
accountDelete: () => Promise<WorldResult>;
|
|
37
39
|
}
|
|
38
|
-
export declare function
|
|
40
|
+
export declare function createWorldLink(opts: WorldLinkOptions): WorldLink;
|
|
@@ -1,26 +1,27 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
1
|
import fs from "node:fs/promises";
|
|
3
2
|
import path from "node:path";
|
|
4
3
|
import { log } from "../core/logger.js";
|
|
5
|
-
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/** The
|
|
14
|
-
*
|
|
15
|
-
export const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
function count(v) {
|
|
19
|
-
return typeof v === "number" && Number.isSafeInteger(v) && v >= 0 ? v : 0;
|
|
20
|
-
}
|
|
4
|
+
// ── GG World device link ────────────────────────────────────────────────
|
|
5
|
+
// One device link per install, used only for GG World online save and the
|
|
6
|
+
// live world. It lives in ~/.gg/royale.json (the name is from GG Royale, now
|
|
7
|
+
// closed; the file and its format are unchanged so existing players keep
|
|
8
|
+
// their account). The device token is only ever sent to the server it was
|
|
9
|
+
// minted for.
|
|
10
|
+
/** The live GG World server. GG_WORLD_URL overrides it. */
|
|
11
|
+
export const DEFAULT_WORLD_URL = "https://gg-world.buzzbeamaustralia.workers.dev";
|
|
12
|
+
/** The retired GG Royale server. Links made with it belong to the live World
|
|
13
|
+
* server (same database), so they are never re-registered. */
|
|
14
|
+
export const LEGACY_ROYALE_URL = "https://gg-royale.buzzbeamaustralia.workers.dev";
|
|
15
|
+
const WORLD_TIMEOUT_MS = 8_000;
|
|
16
|
+
const REGISTER_TIMEOUT_MS = 10_000;
|
|
21
17
|
function stripSlashes(url) {
|
|
22
18
|
return url.replace(/\/+$/, "");
|
|
23
19
|
}
|
|
20
|
+
/** The server a saved link belongs to: missing or the old Royale URL = live World. */
|
|
21
|
+
function linkServer(file) {
|
|
22
|
+
const url = stripSlashes(file.serverUrl ?? DEFAULT_WORLD_URL);
|
|
23
|
+
return url === LEGACY_ROYALE_URL ? DEFAULT_WORLD_URL : url;
|
|
24
|
+
}
|
|
24
25
|
function isRoyaleFile(v) {
|
|
25
26
|
if (typeof v !== "object" || v === null)
|
|
26
27
|
return false;
|
|
@@ -31,11 +32,15 @@ function isRoyaleFile(v) {
|
|
|
31
32
|
typeof o.linkedAt === "number" &&
|
|
32
33
|
(o.serverUrl === undefined || typeof o.serverUrl === "string"));
|
|
33
34
|
}
|
|
34
|
-
export function
|
|
35
|
+
export function createWorldLink(opts) {
|
|
35
36
|
const filePath = path.join(opts.agentDir, "royale.json");
|
|
36
37
|
const env = opts.env ?? process.env;
|
|
37
38
|
const doFetch = opts.fetchImpl ?? fetch;
|
|
38
39
|
const now = opts.now ?? Date.now;
|
|
40
|
+
function base() {
|
|
41
|
+
const fromEnv = env.GG_WORLD_URL;
|
|
42
|
+
return stripSlashes(fromEnv && fromEnv.length > 0 ? fromEnv : DEFAULT_WORLD_URL);
|
|
43
|
+
}
|
|
39
44
|
async function read() {
|
|
40
45
|
try {
|
|
41
46
|
const parsed = JSON.parse(await fs.readFile(filePath, "utf8"));
|
|
@@ -45,47 +50,15 @@ export function createRoyale(opts) {
|
|
|
45
50
|
return null;
|
|
46
51
|
}
|
|
47
52
|
}
|
|
48
|
-
/** The
|
|
49
|
-
function target() {
|
|
50
|
-
const fromEnv = env.GG_ROYALE_URL;
|
|
51
|
-
return stripSlashes(fromEnv && fromEnv.length > 0 ? fromEnv : DEFAULT_ROYALE_URL);
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* The saved link, only if it was made with the server we're talking to. A
|
|
55
|
-
* link (and its device token) belongs to one server: it's never sent to
|
|
56
|
-
* another, and a link to a dev server doesn't stick once you're back on the
|
|
57
|
-
* live game. Links saved before serverUrl was always stored are live links.
|
|
58
|
-
*/
|
|
53
|
+
/** The saved link, only if it belongs to the server we're talking to. */
|
|
59
54
|
async function link() {
|
|
60
55
|
const file = await read();
|
|
61
|
-
|
|
62
|
-
return null;
|
|
63
|
-
return stripSlashes(file.serverUrl ?? DEFAULT_ROYALE_URL) === target() ? file : null;
|
|
64
|
-
}
|
|
65
|
-
async function register(base) {
|
|
66
|
-
const reg = await postJson(`${base}/api/device/register`, {
|
|
67
|
-
client: "gg-coder",
|
|
68
|
-
version: opts.version,
|
|
69
|
-
});
|
|
70
|
-
const r = reg;
|
|
71
|
-
if (typeof r?.playerId !== "string" ||
|
|
72
|
-
typeof r.deviceToken !== "string" ||
|
|
73
|
-
r.deviceToken.length === 0) {
|
|
74
|
-
throw new Error("The GG Royale server sent an unexpected sign-up response.");
|
|
75
|
-
}
|
|
76
|
-
const file = {
|
|
77
|
-
playerId: r.playerId,
|
|
78
|
-
deviceToken: r.deviceToken,
|
|
79
|
-
linkedAt: now(),
|
|
80
|
-
serverUrl: base,
|
|
81
|
-
};
|
|
82
|
-
await write(file);
|
|
83
|
-
return file;
|
|
56
|
+
return file && linkServer(file) === base() ? file : null;
|
|
84
57
|
}
|
|
85
58
|
async function write(file) {
|
|
86
59
|
await fs.mkdir(opts.agentDir, { recursive: true });
|
|
87
60
|
// The device token is private from its first byte: write a 0600 temp
|
|
88
|
-
// file and rename it into place
|
|
61
|
+
// file and rename it into place.
|
|
89
62
|
const tmp = `${filePath}.${process.pid}.${Date.now()}.tmp`;
|
|
90
63
|
try {
|
|
91
64
|
await fs.writeFile(tmp, JSON.stringify(file, null, 2), {
|
|
@@ -100,152 +73,77 @@ export function createRoyale(opts) {
|
|
|
100
73
|
}
|
|
101
74
|
await fs.chmod(filePath, 0o600).catch(() => { });
|
|
102
75
|
}
|
|
103
|
-
async function
|
|
104
|
-
|
|
105
|
-
try {
|
|
106
|
-
res = await doFetch(url, {
|
|
107
|
-
method: "POST",
|
|
108
|
-
headers: {
|
|
109
|
-
"content-type": "application/json",
|
|
110
|
-
...(token ? { authorization: `Bearer ${token}` } : {}),
|
|
111
|
-
},
|
|
112
|
-
body: body === undefined ? undefined : JSON.stringify(body),
|
|
113
|
-
signal: AbortSignal.timeout(OPEN_TIMEOUT_MS),
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
catch {
|
|
117
|
-
throw new Error("Couldn't reach the GG Royale server. Check your connection and try again.");
|
|
118
|
-
}
|
|
119
|
-
if (!res.ok) {
|
|
120
|
-
throw Object.assign(new Error(`The GG Royale server returned an error (HTTP ${res.status}).`), { status: res.status });
|
|
121
|
-
}
|
|
122
|
-
try {
|
|
123
|
-
return await res.json();
|
|
124
|
-
}
|
|
125
|
-
catch {
|
|
126
|
-
throw new Error("The GG Royale server sent a response the app couldn't read.");
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
async function status() {
|
|
130
|
-
const file = await link();
|
|
131
|
-
return { linked: file !== null, serverUrl: target() };
|
|
132
|
-
}
|
|
133
|
-
async function open() {
|
|
134
|
-
const base = target();
|
|
135
|
-
let file = (await link()) ?? (await register(base));
|
|
136
|
-
const code = async (f) => (await postJson(`${base}/api/device/login-code`, undefined, f.deviceToken));
|
|
137
|
-
let codeRes;
|
|
138
|
-
try {
|
|
139
|
-
codeRes = await code(file);
|
|
140
|
-
}
|
|
141
|
-
catch (err) {
|
|
142
|
-
// The server no longer knows this link (reset or removed): link again, once.
|
|
143
|
-
if (err.status !== 401)
|
|
144
|
-
throw err;
|
|
145
|
-
file = await register(base);
|
|
146
|
-
codeRes = await code(file);
|
|
147
|
-
}
|
|
148
|
-
if (typeof codeRes?.code !== "string" || codeRes.code.length === 0) {
|
|
149
|
-
throw new Error("The GG Royale server sent an unexpected sign-in response.");
|
|
150
|
-
}
|
|
151
|
-
return { url: `${base}/#code=${encodeURIComponent(codeRes.code)}` };
|
|
152
|
-
}
|
|
153
|
-
async function unlink() {
|
|
154
|
-
await fs.rm(filePath, { force: true });
|
|
155
|
-
}
|
|
156
|
-
function send(base, token, kind, count, bug) {
|
|
157
|
-
// Payload is deliberately ONLY kind/count/at (+ a whitelisted bug label).
|
|
158
|
-
const safeBug = bug && ROYALE_BUG_CATEGORIES.includes(bug) ? bug : null;
|
|
159
|
-
const body = JSON.stringify(safeBug ? { kind, count, at: now(), bug: safeBug } : { kind, count, at: now() });
|
|
160
|
-
void doFetch(`${base}/api/device/outcome`, {
|
|
76
|
+
async function register(server) {
|
|
77
|
+
const res = await doFetch(`${server}/api/world/device/register`, {
|
|
161
78
|
method: "POST",
|
|
162
|
-
headers: { "content-type": "application/json"
|
|
163
|
-
body,
|
|
164
|
-
signal: AbortSignal.timeout(
|
|
165
|
-
})
|
|
166
|
-
.then((res) => {
|
|
167
|
-
if (!res.ok)
|
|
168
|
-
log("DEBUG", "royale", "outcome rejected", { status: String(res.status) });
|
|
169
|
-
})
|
|
170
|
-
.catch((err) => {
|
|
171
|
-
log("DEBUG", "royale", "outcome failed", {
|
|
172
|
-
message: err instanceof Error ? err.message : String(err),
|
|
173
|
-
});
|
|
79
|
+
headers: { "content-type": "application/json" },
|
|
80
|
+
body: JSON.stringify({ client: "gg-coder", version: opts.version }),
|
|
81
|
+
signal: AbortSignal.timeout(REGISTER_TIMEOUT_MS),
|
|
174
82
|
});
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
const key = createHash("sha256").update(goalId).digest("hex").slice(0, 16);
|
|
183
|
-
const day = utcDay();
|
|
184
|
-
let seen = [];
|
|
185
|
-
try {
|
|
186
|
-
const parsed = JSON.parse(await fs.readFile(goalsFile, "utf8"));
|
|
187
|
-
if (parsed.day === day && Array.isArray(parsed.goals)) {
|
|
188
|
-
seen = parsed.goals.filter((g) => typeof g === "string");
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
catch {
|
|
192
|
-
// No file yet, or unreadable: a fresh day.
|
|
83
|
+
if (!res.ok)
|
|
84
|
+
throw new Error(`World sign-up failed (HTTP ${res.status}).`);
|
|
85
|
+
const r = (await res.json());
|
|
86
|
+
if (typeof r?.playerId !== "string" ||
|
|
87
|
+
typeof r.deviceToken !== "string" ||
|
|
88
|
+
r.deviceToken.length === 0) {
|
|
89
|
+
throw new Error("The World server sent an unexpected sign-up response.");
|
|
193
90
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
void link()
|
|
203
|
-
.then(async (file) => {
|
|
204
|
-
if (!file)
|
|
205
|
-
return;
|
|
206
|
-
const base = target();
|
|
207
|
-
send(base, file.deviceToken, "run", 1, bug);
|
|
208
|
-
const n = Number.isFinite(commits) ? Math.floor(commits) : 0;
|
|
209
|
-
if (n > 0)
|
|
210
|
-
send(base, file.deviceToken, "commit", n);
|
|
211
|
-
if (deployed)
|
|
212
|
-
send(base, file.deviceToken, "deploy", 1);
|
|
213
|
-
if (goalId && (n > 0 || workers) && (await firstGoalWorkToday(goalId))) {
|
|
214
|
-
send(base, file.deviceToken, "goal", 1);
|
|
215
|
-
}
|
|
216
|
-
})
|
|
217
|
-
.catch((err) => {
|
|
218
|
-
log("DEBUG", "royale", "report failed", {
|
|
219
|
-
message: err instanceof Error ? err.message : String(err),
|
|
220
|
-
});
|
|
221
|
-
});
|
|
91
|
+
const file = {
|
|
92
|
+
playerId: r.playerId,
|
|
93
|
+
deviceToken: r.deviceToken,
|
|
94
|
+
linkedAt: now(),
|
|
95
|
+
serverUrl: server,
|
|
96
|
+
};
|
|
97
|
+
await write(file);
|
|
98
|
+
return file;
|
|
222
99
|
}
|
|
223
|
-
async function
|
|
100
|
+
async function world(method, route, body) {
|
|
101
|
+
const server = base();
|
|
224
102
|
try {
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
103
|
+
const linked = await link();
|
|
104
|
+
// Nothing to delete without a link: don't sign up just to delete.
|
|
105
|
+
if (!linked && method === "DELETE")
|
|
106
|
+
return { status: 200, body: { deleted: true } };
|
|
107
|
+
const file = linked ?? (await register(server));
|
|
108
|
+
const res = await doFetch(`${server}${route}`, {
|
|
109
|
+
method,
|
|
110
|
+
headers: {
|
|
111
|
+
authorization: `Bearer ${file.deviceToken}`,
|
|
112
|
+
...(body === undefined ? {} : { "content-type": "application/json" }),
|
|
113
|
+
},
|
|
114
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
115
|
+
signal: AbortSignal.timeout(WORLD_TIMEOUT_MS),
|
|
231
116
|
});
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
117
|
+
let parsed = null;
|
|
118
|
+
try {
|
|
119
|
+
parsed = await res.json();
|
|
235
120
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
return { claimable: count(o.claimable), streak: count(o.streak), playing: count(o.playing) };
|
|
121
|
+
catch {
|
|
122
|
+
parsed = null;
|
|
123
|
+
}
|
|
124
|
+
return { status: res.status, body: parsed };
|
|
241
125
|
}
|
|
242
126
|
catch (err) {
|
|
243
|
-
log("DEBUG", "
|
|
127
|
+
log("DEBUG", "world", "world request failed", {
|
|
244
128
|
message: err instanceof Error ? err.message : String(err),
|
|
245
129
|
});
|
|
246
|
-
return
|
|
130
|
+
return { status: 0, body: { error: "Couldn't reach the server." } };
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
async function accountDelete() {
|
|
134
|
+
const result = await world("DELETE", "/api/world/account");
|
|
135
|
+
// 404: the server no longer knows this device, so the account is gone too.
|
|
136
|
+
if ((result.status >= 200 && result.status < 300) || result.status === 404) {
|
|
137
|
+
await fs.rm(filePath, { force: true }).catch(() => { });
|
|
247
138
|
}
|
|
139
|
+
return result;
|
|
248
140
|
}
|
|
249
|
-
return {
|
|
141
|
+
return {
|
|
142
|
+
worldGet: () => world("GET", "/api/world/profile"),
|
|
143
|
+
worldPut: (ver, patch) => world("PUT", "/api/world/profile", { ver, patch }),
|
|
144
|
+
worldDelete: () => world("DELETE", "/api/world/me"),
|
|
145
|
+
worldLive: () => world("POST", "/api/world/live", {}),
|
|
146
|
+
accountDelete,
|
|
147
|
+
};
|
|
250
148
|
}
|
|
251
149
|
//# sourceMappingURL=royale.js.map
|