@kenkaiiii/ggcoder 5.84.3 → 5.86.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.
Files changed (173) hide show
  1. package/assets/skills/bulletproof/SKILL.md +69 -130
  2. package/assets/skills/bulletproof/references/agent-surface.md +22 -1
  3. package/assets/skills/bulletproof/references/audit-protocol.md +23 -6
  4. package/assets/skills/bulletproof/references/platform-playbooks.md +12 -0
  5. package/assets/skills/bulletproof/references/provenance.md +19 -2
  6. package/assets/skills/bulletproof/references/secure-defaults.md +13 -1
  7. package/assets/skills/bulletproof/references/supply-chain.md +8 -5
  8. package/assets/skills/bulletproof/references/threat-landscape.md +46 -57
  9. package/assets/skills/clarify/SKILL.md +2 -2
  10. package/assets/skills/code-review/SKILL.md +5 -11
  11. package/assets/skills/compliance-guard/SKILL.md +59 -212
  12. package/assets/skills/compliance-guard/references/artifacts.md +14 -1
  13. package/assets/skills/compliance-guard/references/eu-uk.md +17 -7
  14. package/assets/skills/compliance-guard/references/exposure-triage.md +16 -0
  15. package/assets/skills/compliance-guard/references/full-review.md +155 -0
  16. package/assets/skills/compliance-guard/references/lawsuit-vectors.md +14 -2
  17. package/assets/skills/compliance-guard/references/provenance.md +33 -2
  18. package/assets/skills/compliance-guard/references/sector-gates.md +15 -1
  19. package/assets/skills/compliance-guard/references/security-baseline.md +21 -34
  20. package/assets/skills/compliance-guard/references/trigger-map.md +15 -1
  21. package/assets/skills/compliance-guard/references/us.md +32 -8
  22. package/assets/skills/durable/SKILL.md +22 -29
  23. package/assets/skills/durable/references/agent-db-safety.md +2 -2
  24. package/assets/skills/durable/references/backups-and-runtime.md +6 -6
  25. package/assets/skills/durable/references/migrations-and-schema.md +5 -4
  26. package/assets/skills/evidence-led-ui/LICENSES.md +3 -4
  27. package/assets/skills/evidence-led-ui/SKILL.md +9 -14
  28. package/assets/skills/evidence-led-ui/references/archetypes.md +1 -1
  29. package/assets/skills/evidence-led-ui/references/direction.md +4 -12
  30. package/assets/skills/evidence-led-ui/references/methodology.md +3 -11
  31. package/assets/skills/evidence-led-ui/references/observed-patterns.md +1 -1
  32. package/assets/skills/evidence-led-ui/references/production-contract.md +2 -2
  33. package/assets/skills/evidence-led-ui/references/provenance.md +14 -14
  34. package/assets/skills/lean/SKILL.md +34 -50
  35. package/assets/skills/lean/references/playbooks.md +9 -7
  36. package/assets/skills/refactoring/SKILL.md +35 -50
  37. package/assets/skills/root-cause/SKILL.md +2 -2
  38. package/assets/skills/shared-language/SKILL.md +3 -3
  39. package/dist/app-sidecar/auth-routes.js +2 -0
  40. package/dist/app-sidecar/auth-routes.js.map +1 -1
  41. package/dist/app-sidecar/goal-routes.js +1 -0
  42. package/dist/app-sidecar/goal-routes.js.map +1 -1
  43. package/dist/app-sidecar/integration-routes.js +4 -0
  44. package/dist/app-sidecar/integration-routes.js.map +1 -1
  45. package/dist/app-sidecar/mcp-routes.js +1 -0
  46. package/dist/app-sidecar/mcp-routes.js.map +1 -1
  47. package/dist/app-sidecar/progress-manager.d.ts +20 -2
  48. package/dist/app-sidecar/progress-manager.js +15 -2
  49. package/dist/app-sidecar/progress-manager.js.map +1 -1
  50. package/dist/app-sidecar/prompt-routes.js +67 -1
  51. package/dist/app-sidecar/prompt-routes.js.map +1 -1
  52. package/dist/app-sidecar/route-context.d.ts +2 -0
  53. package/dist/app-sidecar/royale-bug.d.ts +19 -0
  54. package/dist/app-sidecar/royale-bug.js +112 -0
  55. package/dist/app-sidecar/royale-bug.js.map +1 -0
  56. package/dist/app-sidecar/royale-deploy.d.ts +5 -0
  57. package/dist/app-sidecar/royale-deploy.js +76 -0
  58. package/dist/app-sidecar/royale-deploy.js.map +1 -0
  59. package/dist/app-sidecar/royale.d.ts +38 -0
  60. package/dist/app-sidecar/royale.js +251 -0
  61. package/dist/app-sidecar/royale.js.map +1 -0
  62. package/dist/app-sidecar/run-control-routes.js +12 -0
  63. package/dist/app-sidecar/run-control-routes.js.map +1 -1
  64. package/dist/app-sidecar/task-routes.js +2 -0
  65. package/dist/app-sidecar/task-routes.js.map +1 -1
  66. package/dist/app-sidecar/trophy-manager.d.ts +15 -0
  67. package/dist/app-sidecar/trophy-manager.js +71 -0
  68. package/dist/app-sidecar/trophy-manager.js.map +1 -0
  69. package/dist/app-sidecar/workspace-routes.js +1 -0
  70. package/dist/app-sidecar/workspace-routes.js.map +1 -1
  71. package/dist/app-sidecar.js +107 -6
  72. package/dist/app-sidecar.js.map +1 -1
  73. package/dist/core/bundled-agents.js +2 -2
  74. package/dist/core/trophies/catalog-more.d.ts +2 -0
  75. package/dist/core/trophies/catalog-more.js +857 -0
  76. package/dist/core/trophies/catalog-more.js.map +1 -0
  77. package/dist/core/trophies/catalog.d.ts +4 -0
  78. package/dist/core/trophies/catalog.js +649 -0
  79. package/dist/core/trophies/catalog.js.map +1 -0
  80. package/dist/core/trophies/engine.d.ts +70 -0
  81. package/dist/core/trophies/engine.js +351 -0
  82. package/dist/core/trophies/engine.js.map +1 -0
  83. package/dist/core/trophies/store.d.ts +17 -0
  84. package/dist/core/trophies/store.js +113 -0
  85. package/dist/core/trophies/store.js.map +1 -0
  86. package/dist/core/trophies/types.d.ts +119 -0
  87. package/dist/core/trophies/types.js +78 -0
  88. package/dist/core/trophies/types.js.map +1 -0
  89. package/dist/system-prompt.js +1 -1
  90. package/dist/system-prompt.js.map +1 -1
  91. package/dist/tools/bash.js +4 -1
  92. package/dist/tools/bash.js.map +1 -1
  93. package/dist/tools/skill.d.ts +2 -0
  94. package/dist/tools/skill.js +18 -1
  95. package/dist/tools/skill.js.map +1 -1
  96. package/package.json +4 -4
  97. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/LICENSE +0 -21
  98. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/airbnb/DESIGN.md +0 -545
  99. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/airtable/DESIGN.md +0 -554
  100. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/apple/DESIGN.md +0 -562
  101. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/binance/DESIGN.md +0 -634
  102. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/bmw/DESIGN.md +0 -544
  103. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/bmw-m/DESIGN.md +0 -503
  104. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/bugatti/DESIGN.md +0 -454
  105. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/cal/DESIGN.md +0 -542
  106. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/claude/DESIGN.md +0 -589
  107. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/clay/DESIGN.md +0 -541
  108. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/clickhouse/DESIGN.md +0 -544
  109. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/cohere/DESIGN.md +0 -451
  110. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/coinbase/DESIGN.md +0 -570
  111. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/composio/DESIGN.md +0 -506
  112. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/cursor/DESIGN.md +0 -537
  113. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/dell-1996/DESIGN.md +0 -632
  114. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/elevenlabs/DESIGN.md +0 -504
  115. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/expo/DESIGN.md +0 -526
  116. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/ferrari/DESIGN.md +0 -531
  117. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/figma/DESIGN.md +0 -578
  118. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/framer/DESIGN.md +0 -544
  119. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/hashicorp/DESIGN.md +0 -575
  120. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/hp/DESIGN.md +0 -670
  121. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/ibm/DESIGN.md +0 -550
  122. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/intercom/DESIGN.md +0 -546
  123. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/kraken/DESIGN.md +0 -125
  124. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/lamborghini/DESIGN.md +0 -288
  125. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/linear.app/DESIGN.md +0 -548
  126. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/lovable/DESIGN.md +0 -298
  127. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/mastercard/DESIGN.md +0 -365
  128. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/meta/DESIGN.md +0 -683
  129. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/minimax/DESIGN.md +0 -746
  130. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/mintlify/DESIGN.md +0 -852
  131. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/miro/DESIGN.md +0 -825
  132. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/mistral.ai/DESIGN.md +0 -773
  133. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/mongodb/DESIGN.md +0 -767
  134. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/nike/DESIGN.md +0 -575
  135. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/nintendo-2001/DESIGN.md +0 -649
  136. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/notion/DESIGN.md +0 -821
  137. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/nvidia/DESIGN.md +0 -640
  138. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/ollama/DESIGN.md +0 -539
  139. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/opencode.ai/DESIGN.md +0 -521
  140. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/pinterest/DESIGN.md +0 -597
  141. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/playstation/DESIGN.md +0 -661
  142. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/posthog/DESIGN.md +0 -690
  143. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/raycast/DESIGN.md +0 -669
  144. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/renault/DESIGN.md +0 -589
  145. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/replicate/DESIGN.md +0 -616
  146. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/resend/DESIGN.md +0 -585
  147. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/revolut/DESIGN.md +0 -636
  148. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/runwayml/DESIGN.md +0 -244
  149. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/sanity/DESIGN.md +0 -357
  150. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/sentry/DESIGN.md +0 -551
  151. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/shopify/DESIGN.md +0 -516
  152. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/slack/DESIGN.md +0 -482
  153. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/spacex/DESIGN.md +0 -363
  154. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/spotify/DESIGN.md +0 -246
  155. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/starbucks/DESIGN.md +0 -580
  156. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/stripe/DESIGN.md +0 -487
  157. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/supabase/DESIGN.md +0 -462
  158. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/superhuman/DESIGN.md +0 -448
  159. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/tesla/DESIGN.md +0 -286
  160. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/theverge/DESIGN.md +0 -339
  161. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/together.ai/DESIGN.md +0 -633
  162. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/uber/DESIGN.md +0 -636
  163. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/vercel/DESIGN.md +0 -736
  164. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/vodafone/DESIGN.md +0 -538
  165. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/voltagent/DESIGN.md +0 -521
  166. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/warp/DESIGN.md +0 -526
  167. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/webflow/DESIGN.md +0 -588
  168. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/wired/DESIGN.md +0 -497
  169. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/wise/DESIGN.md +0 -544
  170. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/x.ai/DESIGN.md +0 -465
  171. package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/zapier/DESIGN.md +0 -537
  172. package/assets/skills/evidence-led-ui/data/corpus-manifest.json +0 -768
  173. package/assets/skills/evidence-led-ui/data/observations.json +0 -47053
@@ -0,0 +1,112 @@
1
+ // ── GG Royale "bug fixed" classifier ────────────────────────────────────
2
+ // Pure: given one run's transcript slice, decide whether a check-like shell
3
+ // command (tests/build/typecheck/lint) failed and a later run of the SAME
4
+ // command passed, and label the FAILED output with one coarse category.
5
+ // Only the category label ever leaves the machine — never the command,
6
+ // output, or paths.
7
+ export const ROYALE_BUG_CATEGORIES = [
8
+ "type",
9
+ "null",
10
+ "test",
11
+ "build",
12
+ "lint",
13
+ "syntax",
14
+ "timeout",
15
+ "crash",
16
+ ];
17
+ const SHELL_TOOLS = new Set(["bash", "shell"]);
18
+ const CHECK_RE = /\b(test|tests|vitest|jest|pytest|mocha|tsc|typecheck|build|lint|eslint|biome|ruff|clippy|mypy|pyright|check)\b/i;
19
+ /** Ordered: first match wins (more specific before generic "test"/"build"). */
20
+ const RULES = [
21
+ ["timeout", /\btim(e|ed)[ -]?out\b|\btimeout\b/i],
22
+ [
23
+ "crash",
24
+ /\bpanic(ked)?\b|segfault|segmentation fault|core dumped|\bcrash(ed)?\b|uncaught exception/i,
25
+ ],
26
+ ["syntax", /SyntaxError|unexpected token|parse error|parsing error/i],
27
+ [
28
+ "null",
29
+ /Cannot read propert(y|ies) of (undefined|null)|\bis (undefined|null)\b|NoneType|nil pointer|NullPointerException|null pointer/i,
30
+ ],
31
+ ["type", /TypeError|type error|error TS\d{4}|\bTS2\d{3}\b|is not assignable to type/i],
32
+ ["lint", /\blint\b|eslint|ruff|clippy|biome/i],
33
+ ["test", /AssertionError|assert(ion)?|\bexpected\b|tests? failed|\bFAIL\b|failing/i],
34
+ [
35
+ "build",
36
+ /build failed|compil(e|ation|er) (error|failed)|failed to compile|bundl|\berror\[E\d+\]/i,
37
+ ],
38
+ ];
39
+ function textOf(content) {
40
+ if (typeof content === "string")
41
+ return content;
42
+ if (!Array.isArray(content))
43
+ return "";
44
+ return content
45
+ .map((c) => typeof c === "object" && c !== null && typeof c.text === "string"
46
+ ? c.text
47
+ : "")
48
+ .join("\n");
49
+ }
50
+ /** Bash results begin "Exit code: N" (or TIMEOUT…). Unknown → null. */
51
+ function exitOk(result, isError) {
52
+ const m = /^Exit code: (\S+)/.exec(result);
53
+ if (m)
54
+ return m[1] === "0";
55
+ return isError === true ? false : null;
56
+ }
57
+ function normalize(cmd) {
58
+ return cmd.trim().replace(/\s+/g, " ");
59
+ }
60
+ export function categorizeFailure(output, command) {
61
+ for (const [cat, re] of RULES)
62
+ if (re.test(output))
63
+ return cat;
64
+ // Fall back to what kind of check it was.
65
+ if (/\b(tsc|typecheck|mypy|pyright)\b/i.test(command))
66
+ return "type";
67
+ if (/\b(lint|eslint|ruff|clippy|biome)\b/i.test(command))
68
+ return "lint";
69
+ if (/\bbuild\b/i.test(command))
70
+ return "build";
71
+ return "test";
72
+ }
73
+ /** Category of the first check that failed then later passed, or null. */
74
+ export function classifyFixedCheck(messages) {
75
+ const commands = new Map();
76
+ const runs = [];
77
+ for (const m of messages) {
78
+ if (typeof m.content === "string")
79
+ continue;
80
+ for (const part of m.content) {
81
+ if (m.role === "assistant" && part.type === "tool_call" && part.id && part.name) {
82
+ const cmd = part.args?.command;
83
+ if (SHELL_TOOLS.has(part.name) && typeof cmd === "string" && CHECK_RE.test(cmd)) {
84
+ commands.set(part.id, normalize(cmd));
85
+ }
86
+ }
87
+ else if (m.role === "tool" && part.type === "tool_result" && part.toolCallId) {
88
+ const command = commands.get(part.toolCallId);
89
+ if (command === undefined)
90
+ continue;
91
+ const output = textOf(part.content);
92
+ const ok = exitOk(output, part.isError);
93
+ if (ok !== null)
94
+ runs.push({ command, ok, output });
95
+ }
96
+ }
97
+ }
98
+ const failed = new Map();
99
+ for (const r of runs) {
100
+ if (!r.ok) {
101
+ if (!failed.has(r.command))
102
+ failed.set(r.command, r.output);
103
+ }
104
+ else {
105
+ const out = failed.get(r.command);
106
+ if (out !== undefined)
107
+ return categorizeFailure(out, r.command);
108
+ }
109
+ }
110
+ return null;
111
+ }
112
+ //# sourceMappingURL=royale-bug.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"royale-bug.js","sourceRoot":"","sources":["../../src/app-sidecar/royale-bug.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,4EAA4E;AAC5E,0EAA0E;AAC1E,wEAAwE;AACxE,uEAAuE;AACvE,oBAAoB;AAEpB,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,MAAM;IACN,QAAQ;IAC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AI,CAAC;AACd,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { MessageLike } from "./royale-bug.js";
2
+ /** Whether a shell command (one tool call's text) deploys or publishes. */
3
+ export declare function isDeployCommand(command: string): boolean;
4
+ /** True when the run's shell ran a deploy (or publish) that exited 0. */
5
+ export declare function detectDeploy(messages: ReadonlyArray<MessageLike>): boolean;
@@ -0,0 +1,76 @@
1
+ // ── GG Royale "shipped it" detector ─────────────────────────────────────
2
+ // Pure: given one run's transcript slice, decide whether a deploy (or a
3
+ // package publish) command ran in the shell and succeeded. Only "a deploy
4
+ // happened" ever leaves the machine: never the command, its output, the
5
+ // site, or any path.
6
+ const SHELL_TOOLS = new Set(["bash", "shell"]);
7
+ /**
8
+ * Commands that put something live. Each is matched within one command of a
9
+ * pipeline or chain (no `;`, `|` or `&` in between), so "vercel env ls; echo
10
+ * deploy" doesn't count.
11
+ */
12
+ const DEPLOY_RES = [
13
+ /\bvercel\b[^;&|\n]*(\bdeploy\b|--prod\b)/i,
14
+ /\bnetlify\b[^;&|\n]*\bdeploy\b/i,
15
+ /\bwrangler\b[^;&|\n]*\b(deploy|publish)\b/i,
16
+ /\bfly(ctl)?\b[^;&|\n]*\bdeploy\b/i,
17
+ /\bfirebase\b[^;&|\n]*\bdeploy\b/i,
18
+ /\brailway\b[^;&|\n]*\b(up|deploy)\b/i,
19
+ /\bgcloud\b[^;&|\n]*\b(app|run|functions)\b[^;&|\n]*\bdeploy\b/i,
20
+ /\b(sls|serverless|cdk|amplify)\b[^;&|\n]*\b(deploy|publish)\b/i,
21
+ /\bgit\s+push\s+(heroku|dokku)\b/i,
22
+ /\bsurge\b(\s|$)/i,
23
+ // A project's own deploy script, and publishing a package.
24
+ /\b(npm|pnpm|yarn|bun)\s+(run\s+)?deploy\b/i,
25
+ /\b(npm|pnpm|yarn|bun)\s+publish\b/i,
26
+ ];
27
+ /** Rehearsals that don't ship anything. */
28
+ const DRY_RE = /--dry-run\b|--dryrun\b|\bdry-run\b/i;
29
+ /** Whether a shell command (one tool call's text) deploys or publishes. */
30
+ export function isDeployCommand(command) {
31
+ if (DRY_RE.test(command))
32
+ return false;
33
+ return DEPLOY_RES.some((re) => re.test(command));
34
+ }
35
+ /** Bash results begin "Exit code: N" (or TIMEOUT…). Unknown → null. */
36
+ function exitOk(result, isError) {
37
+ const m = /^Exit code: (\S+)/.exec(result);
38
+ if (m)
39
+ return m[1] === "0";
40
+ return isError === true ? false : null;
41
+ }
42
+ function textOf(content) {
43
+ if (typeof content === "string")
44
+ return content;
45
+ if (!Array.isArray(content))
46
+ return "";
47
+ return content
48
+ .map((c) => typeof c === "object" && c !== null && typeof c.text === "string"
49
+ ? c.text
50
+ : "")
51
+ .join("\n");
52
+ }
53
+ /** True when the run's shell ran a deploy (or publish) that exited 0. */
54
+ export function detectDeploy(messages) {
55
+ const deploys = new Set();
56
+ for (const m of messages) {
57
+ if (typeof m.content === "string")
58
+ continue;
59
+ for (const part of m.content) {
60
+ if (m.role === "assistant" && part.type === "tool_call" && part.id && part.name) {
61
+ const cmd = part.args?.command;
62
+ if (SHELL_TOOLS.has(part.name) && typeof cmd === "string" && isDeployCommand(cmd)) {
63
+ deploys.add(part.id);
64
+ }
65
+ }
66
+ else if (m.role === "tool" && part.type === "tool_result" && part.toolCallId) {
67
+ if (!deploys.has(part.toolCallId))
68
+ continue;
69
+ if (exitOk(textOf(part.content), part.isError) === true)
70
+ return true;
71
+ }
72
+ }
73
+ }
74
+ return false;
75
+ }
76
+ //# sourceMappingURL=royale-deploy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"royale-deploy.js","sourceRoot":"","sources":["../../src/app-sidecar/royale-deploy.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,wEAAwE;AACxE,0EAA0E;AAC1E,wEAAwE;AACxE,qBAAqB;AAIrB,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAE/C;;;;GAIG;AACH,MAAM,UAA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IAAI,CAAC,CAAC;AAChB,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,YAAY,CAAC,QAAoC;IAC/D,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAClC,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;QACzB,IAAI,OAAO,CAAC,CAAC,OAAO,KAAK,QAAQ;YAAE,SAAS;QAC5C,KAAK,MAAM,IAAI,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;YAC7B,IAAI,CAAC,CAAC,IAAI,KAAK,WAAW,IAAI,IAAI,CAAC,IAAI,KAAK,WAAW,IAAI,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;gBAChF,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC;gBAC/B,IAAI,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC;oBAClF,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBACvB,CAAC;YACH,CAAC;iBAAM,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;gBAC/E,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC;oBAAE,SAAS;gBAC5C,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI;oBAAE,OAAO,IAAI,CAAC;YACvE,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { RunOutcome } from "./progress-manager.js";
2
+ /** The ONE place the default GG Royale server URL lives. Overridden by
3
+ * GG_ROYALE_URL or royale.json `serverUrl`. */
4
+ export declare const DEFAULT_ROYALE_URL = "https://gg-royale.buzzbeamaustralia.workers.dev";
5
+ export interface RoyaleFile {
6
+ serverUrl?: string;
7
+ playerId: string;
8
+ deviceToken: string;
9
+ linkedAt: number;
10
+ }
11
+ export interface RoyaleStatus {
12
+ linked: boolean;
13
+ serverUrl: string;
14
+ }
15
+ export interface RoyaleSummary {
16
+ claimable: number;
17
+ streak: number;
18
+ playing: number;
19
+ }
20
+ export interface RoyaleOptions {
21
+ agentDir: string;
22
+ version: string;
23
+ env?: NodeJS.ProcessEnv;
24
+ fetchImpl?: typeof fetch;
25
+ now?: () => number;
26
+ }
27
+ export interface Royale {
28
+ status: () => Promise<RoyaleStatus>;
29
+ open: () => Promise<{
30
+ url: string;
31
+ }>;
32
+ unlink: () => Promise<void>;
33
+ /** Fire-and-forget; never throws, never awaits the network for the caller. */
34
+ reportRun: (input: RunOutcome) => void;
35
+ /** Badge counts; null when unlinked or on any error. Never throws. */
36
+ summary: () => Promise<RoyaleSummary | null>;
37
+ }
38
+ export declare function createRoyale(opts: RoyaleOptions): Royale;
@@ -0,0 +1,251 @@
1
+ import { createHash } from "node:crypto";
2
+ import fs from "node:fs/promises";
3
+ import path from "node:path";
4
+ import { log } from "../core/logger.js";
5
+ import { ROYALE_BUG_CATEGORIES } from "./royale-bug.js";
6
+ // ── GG Royale (public hook only) ────────────────────────────────────────
7
+ // GG Royale is a private, web-hosted game mode. This module only links the
8
+ // device, mints a login code for the hosted page, and reports "a run finished
9
+ // / N commits / a goal made progress today / a deploy happened". The outcome
10
+ // payload is ONLY {kind, count, at} plus, on a run that fixed a failing check,
11
+ // a fixed-vocabulary `bug` label: never paths, repo names, goal names,
12
+ // prompts, commands or code.
13
+ /** The ONE place the default GG Royale server URL lives. Overridden by
14
+ * GG_ROYALE_URL or royale.json `serverUrl`. */
15
+ export const DEFAULT_ROYALE_URL = "https://gg-royale.buzzbeamaustralia.workers.dev";
16
+ const REPORT_TIMEOUT_MS = 5_000;
17
+ const OPEN_TIMEOUT_MS = 10_000;
18
+ function count(v) {
19
+ return typeof v === "number" && Number.isSafeInteger(v) && v >= 0 ? v : 0;
20
+ }
21
+ function stripSlashes(url) {
22
+ return url.replace(/\/+$/, "");
23
+ }
24
+ function isRoyaleFile(v) {
25
+ if (typeof v !== "object" || v === null)
26
+ return false;
27
+ const o = v;
28
+ return (typeof o.playerId === "string" &&
29
+ typeof o.deviceToken === "string" &&
30
+ o.deviceToken.length > 0 &&
31
+ typeof o.linkedAt === "number" &&
32
+ (o.serverUrl === undefined || typeof o.serverUrl === "string"));
33
+ }
34
+ export function createRoyale(opts) {
35
+ const filePath = path.join(opts.agentDir, "royale.json");
36
+ const env = opts.env ?? process.env;
37
+ const doFetch = opts.fetchImpl ?? fetch;
38
+ const now = opts.now ?? Date.now;
39
+ async function read() {
40
+ try {
41
+ const parsed = JSON.parse(await fs.readFile(filePath, "utf8"));
42
+ return isRoyaleFile(parsed) ? parsed : null;
43
+ }
44
+ catch {
45
+ return null;
46
+ }
47
+ }
48
+ /** The server this app talks to: GG_ROYALE_URL when set, else the live game. */
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
+ */
59
+ async function link() {
60
+ const file = await read();
61
+ if (!file)
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;
84
+ }
85
+ async function write(file) {
86
+ await fs.mkdir(opts.agentDir, { recursive: true });
87
+ // The device token is private from its first byte: write a 0600 temp
88
+ // file and rename it into place (no moment where others can read it).
89
+ const tmp = `${filePath}.${process.pid}.${Date.now()}.tmp`;
90
+ try {
91
+ await fs.writeFile(tmp, JSON.stringify(file, null, 2), {
92
+ encoding: "utf8",
93
+ flag: "wx",
94
+ mode: 0o600,
95
+ });
96
+ await fs.rename(tmp, filePath);
97
+ }
98
+ finally {
99
+ await fs.rm(tmp, { force: true }).catch(() => { });
100
+ }
101
+ await fs.chmod(filePath, 0o600).catch(() => { });
102
+ }
103
+ async function postJson(url, body, token) {
104
+ let res;
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`, {
161
+ method: "POST",
162
+ headers: { "content-type": "application/json", authorization: `Bearer ${token}` },
163
+ body,
164
+ signal: AbortSignal.timeout(REPORT_TIMEOUT_MS),
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
+ });
174
+ });
175
+ }
176
+ // A goal counts once a day: the first of its runs that does real work
177
+ // (commits, or work handed to workers). Remembered across restarts in a
178
+ // tiny file holding only hashed goal ids for the current UTC day.
179
+ const goalsFile = path.join(opts.agentDir, "royale-goals.json");
180
+ const utcDay = () => new Date(now()).toISOString().slice(0, 10);
181
+ async function firstGoalWorkToday(goalId) {
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.
193
+ }
194
+ if (seen.includes(key))
195
+ return false;
196
+ const tmp = `${goalsFile}.${process.pid}.tmp`;
197
+ await fs.writeFile(tmp, JSON.stringify({ day, goals: [...seen, key] }));
198
+ await fs.rename(tmp, goalsFile);
199
+ return true;
200
+ }
201
+ function reportRun({ commits, bug, goalId, workers, deployed }) {
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
+ });
222
+ }
223
+ async function summary() {
224
+ try {
225
+ const file = await link();
226
+ if (!file)
227
+ return null;
228
+ const res = await doFetch(`${target()}/api/device/summary`, {
229
+ headers: { authorization: `Bearer ${file.deviceToken}` },
230
+ signal: AbortSignal.timeout(REPORT_TIMEOUT_MS),
231
+ });
232
+ if (!res.ok) {
233
+ log("DEBUG", "royale", "summary rejected", { status: String(res.status) });
234
+ return null;
235
+ }
236
+ const body = await res.json();
237
+ if (typeof body !== "object" || body === null)
238
+ return null;
239
+ const o = body;
240
+ return { claimable: count(o.claimable), streak: count(o.streak), playing: count(o.playing) };
241
+ }
242
+ catch (err) {
243
+ log("DEBUG", "royale", "summary failed", {
244
+ message: err instanceof Error ? err.message : String(err),
245
+ });
246
+ return null;
247
+ }
248
+ }
249
+ return { status, open, unlink, reportRun, summary };
250
+ }
251
+ //# sourceMappingURL=royale.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"royale.js","sourceRoot":"","sources":["../../src/app-sidecar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AO,EAAE,QAAQ,EAAE,gBAAgB,EAAE;gBACvC,OAAO,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;aAC1D,CAAC,CAAC;YACH,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;AACtD,CAAC"}
@@ -162,6 +162,7 @@ export function handleRunControlRoutes(ctx, req, res, url, method) {
162
162
  // the footer's context meter rescales immediately.
163
163
  ctx.broadcast("extras", ctx.footerExtras());
164
164
  json(res, 200, { provider: target.provider, model: target.id, ...payload });
165
+ void ctx.trophies.count("modelSwitches", ctx.sessionId);
165
166
  });
166
167
  return true;
167
168
  }
@@ -224,6 +225,7 @@ export function handleRunControlRoutes(ctx, req, res, url, method) {
224
225
  provider: target.provider,
225
226
  model: target.id,
226
227
  });
228
+ void ctx.trophies.count("kenPins", ctx.sessionId);
227
229
  }
228
230
  const payload = ctx.kenStatePayload();
229
231
  ctx.broadcast("ken_model_change", payload);
@@ -264,6 +266,8 @@ export function handleRunControlRoutes(ctx, req, res, url, method) {
264
266
  ...(cancelled ? { cancelledId: id } : {}),
265
267
  });
266
268
  json(res, 200, { cancelled, queued });
269
+ if (cancelled)
270
+ void ctx.trophies.count("queueCancels", ctx.sessionId);
267
271
  });
268
272
  return true;
269
273
  }
@@ -287,6 +291,7 @@ export function handleRunControlRoutes(ctx, req, res, url, method) {
287
291
  // Push the updated task list right away rather than waiting for the poll.
288
292
  ctx.broadcast("tasks", { tasks: ctx.session.listBackgroundProcesses() });
289
293
  json(res, 200, { message });
294
+ void ctx.trophies.count("processKills", ctx.sessionId);
290
295
  });
291
296
  return true;
292
297
  }
@@ -314,6 +319,8 @@ export function handleRunControlRoutes(ctx, req, res, url, method) {
314
319
  ...(body.cwd ? { cwd: body.cwd } : {}),
315
320
  });
316
321
  json(res, result.ok ? 200 : 400, result);
322
+ if (result.ok)
323
+ void ctx.trophies.count("transcriptImports", ctx.sessionId);
317
324
  });
318
325
  return true;
319
326
  }
@@ -351,6 +358,7 @@ export function handleRunControlRoutes(ctx, req, res, url, method) {
351
358
  };
352
359
  ctx.broadcast("thinking_change", payload);
353
360
  json(res, 200, payload);
361
+ void ctx.trophies.count("thinkingChanges", ctx.sessionId);
354
362
  });
355
363
  return true;
356
364
  }
@@ -403,6 +411,8 @@ export function handleRunControlRoutes(ctx, req, res, url, method) {
403
411
  runState: ctx.runLifecycle.state,
404
412
  drained,
405
413
  });
414
+ if (result.status === "cancelled")
415
+ void ctx.trophies.count("cancels", ctx.sessionId);
406
416
  })().catch((error) => {
407
417
  ctx.broadcast("cancel_failed", { error: "cancel_failed", runState: ctx.runLifecycle.state });
408
418
  json(res, 500, {
@@ -430,6 +440,7 @@ export function handleRunControlRoutes(ctx, req, res, url, method) {
430
440
  ctx.broadcast("session_reset", {});
431
441
  // The new conversation's file, so a daemon restart reopens it.
432
442
  json(res, 200, { ok: true, sessionPath: ctx.session.getState().sessionPath ?? null });
443
+ void ctx.trophies.count("newSessions", ctx.sessionId);
433
444
  })
434
445
  .catch((err) => {
435
446
  json(res, 500, { error: err instanceof Error ? err.message : String(err) });
@@ -486,6 +497,7 @@ export function handleRunControlRoutes(ctx, req, res, url, method) {
486
497
  ctx.broadcast("session_reset", { planTotal });
487
498
  ctx.broadcast("plan_progress", ctx.planProgressPayload());
488
499
  json(res, 200, { ok: true, planTotal });
500
+ void ctx.trophies.count("plansApproved", ctx.sessionId);
489
501
  }
490
502
  catch (err) {
491
503
  json(res, 500, { error: err instanceof Error ? err.message : String(err) });