gipity 1.1.11 → 1.1.12

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/dist/knowledge.js CHANGED
@@ -52,7 +52,7 @@ Prefer the cheapest option that works - CLI and sandbox are instant and free, ap
52
52
  3. App services - runtime HTTP endpoints your deployed app calls directly at \`https://a.gipity.ai/api/<PROJECT_GUID>/services/*\`. Available: LLM, TTS, image, sound, music, transcribe, video, file upload, realtime, location, push notifications (Gipity Notify - \`gipity add notify\`, send from a function with the injected \`notify()\`; see \`app-notify\`). Load the matching skill (\`app-llm\`, \`app-tts\`, etc.) before writing service code - they have the schemas, auth pattern, and common-mistake guards. For one-off generation during development, prefer \`gipity generate <image|video|speech|sound|music>\` or \`gipity chat\` - direct generation always bills you (the owner), regardless of any service \`billing_mode\` (that setting only governs the deployed app's runtime calls; never flip it just to create assets). \`gipity generate\` saves to a generic file in the current directory by default (e.g. \`./generated.png\`) - pass \`-o <path>\` to write it straight into your source tree so it deploys (e.g. \`gipity generate image "hero banner" -o src/assets/images/hero.png\`) instead of generating at cwd and moving it.
53
53
  4. Delegate to Gip (\`gipity chat "<task>"\`) - only when the work genuinely needs agent reasoning or a tool not in the CLI, sandbox, or app services. Required for: Twitter/X search, Gmail, calendar, push notifications, video understanding, audio source isolation, cross-model second opinions, multi-step orchestration. Don't use \`gipity chat\` for anything the sandbox can do - it's slower and burns tokens.
54
54
 
55
- You are the developer. Write files in this directory - Gipity's editor hooks (installed by \`gipity init\` into Claude Code, Grok, and Codex) auto-sync them to Gipity. Don't run \`npm install\`, \`npm start\`, \`node\`, or \`python\` locally; there is no local runtime. Code runs in the Gipity sandbox.
55
+ You are the developer. Write files in this directory - Gipity's editor hooks (installed by \`gipity init\` into Claude Code, Grok, Codex, and opencode) auto-sync them to Gipity. Don't run \`npm install\`, \`npm start\`, \`node\`, or \`python\` locally; there is no local runtime. Code runs in the Gipity sandbox.
56
56
 
57
57
  ## Use first-party services before reaching outside
58
58
 
@@ -144,7 +144,7 @@ Every tool call returns its full output with that call. There is no output buffe
144
144
 
145
145
  This directory is the app root - it holds \`.gipity.json\` (and \`gipity.yaml\` for backends) and is already your cwd, so run app commands here. Don't \`cd\` to a git root (\`git rev-parse --show-toplevel\`): when the app is nested in a larger repo that resolves outside the app.
146
146
 
147
- Write files locally - Gipity's editor hooks (installed into Claude Code, Grok, and Codex by \`gipity init\`) auto-push every save to Gipity and auto-pull remote changes (images, audio from \`gipity chat\`) before each turn. Use \`gipity sync\` if things get out of sync (or if the hooks aren't installed - \`gipity status --repair-hooks\` re-enables them). Deletes are safe - use \`rollback\` with a datetime to undo, or \`file_version_restore\` for individual files.
147
+ Write files locally - Gipity's editor hooks (installed into Claude Code, Grok, Codex, and opencode by \`gipity init\`) auto-push every save to Gipity and auto-pull remote changes (images, audio from \`gipity chat\`) before each turn. Use \`gipity sync\` if things get out of sync (or if the hooks aren't installed - \`gipity status --repair-hooks\` re-enables them). Deletes are safe - use \`rollback\` with a datetime to undo, or \`file_version_restore\` for individual files.
148
148
 
149
149
  To keep local-only material (research clones, scratch data, vendored references) in the project directory without syncing or deploying it, list it in a \`.gipityignore\` at the project root - gitignore-style, one pattern per line, \`#\` comments. Ignored paths are invisible to sync in both directions; anything that already synced before being ignored stays on the server until you delete it.
150
150
 
@@ -0,0 +1,171 @@
1
+ /**
2
+ * opencode install + integration helpers, shared by `gipity build --agent
3
+ * opencode` (auto-ensures opencode before launching) and the opencode
4
+ * adapter's setup surface.
5
+ *
6
+ * The integration has three legs, all idempotent and best-effort:
7
+ *
8
+ * 1. Skills: opencode reads the cross-agent ~/.agents/skills directory
9
+ * natively (same SKILL.md family Codex/OpenClaw use), so it shares the
10
+ * Codex skills install (setup.ts installSkillsAndHooks).
11
+ * 2. Plugin: the Gipity opencode plugin (auth + session capture + the
12
+ * "gipity" model provider) ships in the GipityAI/skills repo as
13
+ * hooks/scripts/opencode-plugin.mjs, is staged into ~/.gipity/agent-hooks
14
+ * by the skills install, and is copied from there into opencode's global
15
+ * plugin dir (~/.config/opencode/plugins/gipity.js).
16
+ * 3. Model token: a long-lived gip_at_* agent API token minted for the
17
+ * model slot, stored 0600 at ~/.gipity/opencode-token.json. The plugin
18
+ * reads it (env GIPITY_TOKEN wins, e.g. under a relay daemon) and feeds
19
+ * it to the "gipity" provider as the API key, so opencode's model picker
20
+ * can run the curated open models billed via the user's Gipity credits.
21
+ */
22
+ import { execSync } from 'child_process';
23
+ import { copyFileSync, existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync, chmodSync } from 'fs';
24
+ import { homedir, hostname } from 'os';
25
+ import { dirname, join } from 'path';
26
+ import { AGENT_HOOKS_DIR } from './setup.js';
27
+ import { post } from './api.js';
28
+ import { getAuth } from './auth.js';
29
+ import { resolveApiBase } from './config.js';
30
+ export const OPENCODE_PACKAGE = 'opencode-ai';
31
+ /** opencode's global config root (its own convention: $XDG_CONFIG_HOME or
32
+ * ~/.config, then /opencode). */
33
+ export function opencodeConfigDir() {
34
+ const base = process.env.XDG_CONFIG_HOME || join(homedir(), '.config');
35
+ return join(base, 'opencode');
36
+ }
37
+ /** Where the Gipity plugin lands inside opencode's global plugin dir. */
38
+ export function opencodePluginDest() {
39
+ return join(opencodeConfigDir(), 'plugins', 'gipity.js');
40
+ }
41
+ /** The staged plugin source (installed by setup.ts installSkillsAndHooks
42
+ * alongside capture.cjs and friends). */
43
+ export function stagedPluginPath() {
44
+ return join(AGENT_HOOKS_DIR, 'opencode-plugin.mjs');
45
+ }
46
+ /** The model-slot token file the plugin reads. Owner-only: it holds a
47
+ * long-lived agent API token. */
48
+ export const OPENCODE_TOKEN_FILE = join(process.env.GIPITY_DIR || join(homedir(), '.gipity'), 'opencode-token.json');
49
+ /** Model tokens self-expire so an orphaned file (user wipes ~/.gipity, we
50
+ * lose the guid to revoke with) doesn't live forever. Launch re-mints on
51
+ * expiry - see ensureOpencodeModelToken(). */
52
+ const MODEL_TOKEN_EXPIRY_DAYS = 90;
53
+ export function isOpencodeInstalled() {
54
+ const cmd = process.platform === 'win32' ? 'where opencode' : 'which opencode';
55
+ try {
56
+ execSync(cmd, { stdio: 'ignore', windowsHide: true });
57
+ return true;
58
+ }
59
+ catch {
60
+ return false;
61
+ }
62
+ }
63
+ /** Install opencode via npm if it isn't already on PATH. Idempotent, same
64
+ * shape as ensureClaudeInstalled(). Vanilla opencode - never a fork. */
65
+ export function ensureOpencodeInstalled(opts = {}) {
66
+ if (isOpencodeInstalled())
67
+ return true;
68
+ try {
69
+ execSync(`npm install -g ${OPENCODE_PACKAGE}`, {
70
+ stdio: opts.quiet ? 'ignore' : 'inherit',
71
+ windowsHide: true,
72
+ });
73
+ }
74
+ catch { /* fall through to the definitive re-check */ }
75
+ return isOpencodeInstalled();
76
+ }
77
+ /** Copy the staged Gipity plugin into opencode's global plugin dir. Returns
78
+ * true when the plugin is in place after the call. Content-compared so the
79
+ * steady-state cost is two file reads. */
80
+ export function ensureOpencodePluginInstalled() {
81
+ const src = stagedPluginPath();
82
+ if (!existsSync(src))
83
+ return existsSync(opencodePluginDest());
84
+ const dest = opencodePluginDest();
85
+ try {
86
+ if (existsSync(dest) && readFileSync(dest, 'utf-8') === readFileSync(src, 'utf-8'))
87
+ return true;
88
+ mkdirSync(join(opencodeConfigDir(), 'plugins'), { recursive: true });
89
+ copyFileSync(src, dest);
90
+ console.log('Installed the Gipity plugin for opencode (models + session capture).');
91
+ return true;
92
+ }
93
+ catch {
94
+ return existsSync(dest);
95
+ }
96
+ }
97
+ export function opencodePluginState() {
98
+ const src = stagedPluginPath();
99
+ const dest = opencodePluginDest();
100
+ try {
101
+ return { current: existsSync(dest) && (!existsSync(src) || readFileSync(dest, 'utf-8') === readFileSync(src, 'utf-8')) };
102
+ }
103
+ catch {
104
+ return { current: false };
105
+ }
106
+ }
107
+ export function removeOpencodePlugin() {
108
+ const dest = opencodePluginDest();
109
+ if (!existsSync(dest))
110
+ return false;
111
+ try {
112
+ unlinkSync(dest);
113
+ }
114
+ catch {
115
+ return false;
116
+ }
117
+ return true;
118
+ }
119
+ export function readOpencodeModelToken() {
120
+ try {
121
+ const parsed = JSON.parse(readFileSync(OPENCODE_TOKEN_FILE, 'utf-8'));
122
+ return typeof parsed?.token === 'string' && parsed.token ? parsed : null;
123
+ }
124
+ catch {
125
+ return null;
126
+ }
127
+ }
128
+ /**
129
+ * Ensure a valid model-slot token exists, minting one when absent or dead.
130
+ * Requires a logged-in session (minting uses normal session auth); silently
131
+ * no-ops when logged out or offline - the plugin then falls back to
132
+ * GIPITY_TOKEN env (the relay/devbox path) or reports auth missing.
133
+ */
134
+ export async function ensureOpencodeModelToken() {
135
+ const existing = readOpencodeModelToken();
136
+ if (existing) {
137
+ // Only a definitive 401 discards a stored token - a network blip must
138
+ // not trigger a re-mint storm (same rule as relay/agent-token.ts).
139
+ try {
140
+ const res = await fetch(`${resolveApiBase()}/users/me`, {
141
+ headers: { Authorization: `Bearer ${existing.token}` },
142
+ });
143
+ if (res.status !== 401)
144
+ return existing.token;
145
+ }
146
+ catch {
147
+ return existing.token;
148
+ }
149
+ }
150
+ if (!getAuth())
151
+ return null;
152
+ try {
153
+ const res = await post('/auth/agent-tokens', { name: `opencode models on ${hostname()}`, expiresInDays: MODEL_TOKEN_EXPIRY_DAYS });
154
+ const stored = {
155
+ token: res.data.token,
156
+ guid: res.data.shortGuid,
157
+ mintedAt: new Date().toISOString(),
158
+ };
159
+ mkdirSync(dirname(OPENCODE_TOKEN_FILE), { recursive: true, mode: 0o700 });
160
+ writeFileSync(OPENCODE_TOKEN_FILE, JSON.stringify(stored, null, 2), { mode: 0o600 });
161
+ try {
162
+ chmodSync(OPENCODE_TOKEN_FILE, 0o600);
163
+ }
164
+ catch { /* best-effort */ }
165
+ return stored.token;
166
+ }
167
+ catch {
168
+ return null;
169
+ }
170
+ }
171
+ //# sourceMappingURL=opencode-setup.js.map
@@ -5,7 +5,7 @@
5
5
  * Source: platform/server/src/config/constants/provider-docs.ts
6
6
  * Run `just sync-docs` to refresh from platform.
7
7
  */
8
- export const GEMINI_LLM_MODELS_DOC = `gemini-3.6-flash (Gemini 3.6 Flash, $1.5/$7.5 per 1M tok, 1049K ctx), gemini-3.5-flash (Gemini 3.5 Flash, $1.5/$9 per 1M tok, 1049K ctx), gemini-3.1-pro-preview (Gemini 3.1 Pro, $2/$12 per 1M tok, 1049K ctx), gemini-3.1-flash-lite (Gemini 3.1 Flash-Lite, $0.25/$1.5 per 1M tok, 1049K ctx), gemini-3-flash-preview (Gemini 3 Flash, $0.5/$3 per 1M tok, 1049K ctx), gemini-2.5-pro (Gemini 2.5 Pro, $1.25/$10 per 1M tok, 1049K ctx), gemini-2.5-flash (Gemini 2.5 Flash, $0.3/$2.5 per 1M tok, 1049K ctx), gemini-2.5-flash-lite (Gemini 2.5 Flash-Lite, $0.1/$0.4 per 1M tok, 1049K ctx)`;
8
+ export const GEMINI_LLM_MODELS_DOC = `gemini-3.6-flash (Gemini 3.6 Flash, $1.5/$7.5 per 1M tok, 1049K ctx), gemini-3.5-flash (Gemini 3.5 Flash, $1.5/$9 per 1M tok, 1049K ctx), gemini-3.1-pro-preview (Gemini 3.1 Pro, $2/$12 per 1M tok, 1049K ctx), gemini-3.1-flash-lite (Gemini 3.1 Flash-Lite, $0.25/$1.5 per 1M tok, 1049K ctx), gemini-3-flash-preview (Gemini 3 Flash, $0.5/$3 per 1M tok, 1049K ctx), gemini-2.5-flash (Gemini 2.5 Flash, $0.3/$2.5 per 1M tok, 1049K ctx)`;
9
9
  export const GEMINI_TTS_VOICES = [
10
10
  'Zephyr',
11
11
  'Puck',
@@ -91,8 +91,8 @@ export const IMAGE_TIER_ALIAS_IDS = [
91
91
  'high',
92
92
  'ultra',
93
93
  ];
94
- export const LLM_DEFAULT_MODELS_DOC = `OpenAI: gpt-5.4-nano (cheapest), gpt-5.4-mini (cheap reasoning). Anthropic: claude-haiku-4-5 (cheapest). Gemini: gemini-2.5-flash-lite (cheapest, 1M context)`;
95
- export const LLM_PROVIDERS_LIST = `anthropic, openai, gemini`;
94
+ export const LLM_DEFAULT_MODELS_DOC = `OpenAI: gpt-5.4-nano (cheapest), gpt-5.4-mini (cheap reasoning). Anthropic: claude-haiku-4-5 (cheapest). Gemini: gemini-3.1-flash-lite (cheapest, 1M context)`;
95
+ export const LLM_PROVIDERS_LIST = `anthropic, openai, gemini, openrouter`;
96
96
  export const OPENAI_TTS_VOICES_DOC = `alloy, ash, ballad, coral, echo, fable, nova, onyx, sage, shimmer, verse`;
97
97
  export const TRANSCRIBE_PROVIDERS_DOC = `elevenlabs (default, Scribe v2), openai (GPT-4o Transcribe), gemini (Gemini 2.5 Flash - cheapest, multilingual)`;
98
98
  export const TTS_PROVIDERS_LIST = `elevenlabs, openai, gemini`;
@@ -112,17 +112,15 @@ export const VIDEO_ASPECT_RATIO_IDS = [
112
112
  '9:16',
113
113
  '1:1',
114
114
  ];
115
- export const VIDEO_MODELS_DOC = `veo-3.1-generate-preview (best quality, up to 4K, ~$0.40/sec), veo-3.1-fast-generate-preview (faster, ~$0.10/sec), veo-3.1-lite-generate-preview (budget, ~$0.05/sec), gemini-omni-flash-preview (3-10s @ 720p, conversational editing, ~$0.10/sec)`;
116
- export const VIDEO_MODELS_LIST = `veo-3.1-generate-preview, veo-3.1-fast-generate-preview, veo-3.1-lite-generate-preview, gemini-omni-flash-preview`;
115
+ export const VIDEO_MODELS_DOC = `veo-3.1-generate-preview (best quality, up to 4K, ~$0.40/sec), veo-3.1-fast-generate-preview (faster, ~$0.10/sec), veo-3.1-lite-generate-preview (budget, ~$0.05/sec)`;
116
+ export const VIDEO_MODELS_LIST = `veo-3.1-generate-preview, veo-3.1-fast-generate-preview, veo-3.1-lite-generate-preview`;
117
117
  export const VIDEO_MODELS_TABLE = ` veo-3.1-generate-preview best quality, up to 4K, ~$0.40/sec
118
118
  veo-3.1-fast-generate-preview faster, ~$0.10/sec
119
- veo-3.1-lite-generate-preview budget, ~$0.05/sec
120
- gemini-omni-flash-preview 3-10s @ 720p, conversational editing, ~$0.10/sec`;
119
+ veo-3.1-lite-generate-preview budget, ~$0.05/sec`;
121
120
  export const VIDEO_MODEL_IDS = [
122
121
  'veo-3.1-generate-preview',
123
122
  'veo-3.1-fast-generate-preview',
124
123
  'veo-3.1-lite-generate-preview',
125
- 'gemini-omni-flash-preview',
126
124
  ];
127
125
  export const VIDEO_RESOLUTIONS = `720p, 1080p, 4k`;
128
126
  export const VIDEO_RESOLUTION_IDS = [
@@ -91,7 +91,16 @@ export async function pairDevice(opts = {}) {
91
91
  throw new Error('Device name must be 1–100 non-whitespace characters.');
92
92
  }
93
93
  const plat = mapPlatform(osPlatform());
94
- const res = await post('/remote-devices', { name, platform: plat, machine_id: getMachineId() });
94
+ // Platform-provisioned devboxes declare what they run and where they live
95
+ // (the relay-host entrypoint sets these); a normal local pairing sends
96
+ // neither and the server defaults to local/claude_code.
97
+ const deviceKind = process.env.GIPITY_DEVICE_KIND;
98
+ const agentKind = process.env.GIPITY_AGENT_KIND;
99
+ const res = await post('/remote-devices', {
100
+ name, platform: plat, machine_id: getMachineId(),
101
+ ...(deviceKind ? { device_kind: deviceKind } : {}),
102
+ ...(agentKind ? { agent_kind: agentKind } : {}),
103
+ });
95
104
  state.setDevice({
96
105
  guid: res.data.short_guid,
97
106
  name,
package/dist/setup.js CHANGED
@@ -7,6 +7,7 @@ import { existsSync, mkdirSync, writeFileSync, readFileSync, mkdtempSync, rmSync
7
7
  import { resolveCommand, spawnSyncCommand } from './platform.js';
8
8
  import { SKILLS_CONTENT, BUILD_VS_NON_BUILD_RULE, DEFINITION_OF_DONE } from './knowledge.js';
9
9
  import { DEFAULT_API_BASE, resolveApiBase } from './config.js';
10
+ import { ensureOpencodePluginInstalled } from './opencode-setup.js';
10
11
  export { SKILLS_CONTENT };
11
12
  /** Canonical list of workstation artifacts that are NOT part of the project.
12
13
  * Used as the single source of truth for three separate decisions:
@@ -33,6 +34,7 @@ export const PRIMER_FILES = {
33
34
  codex: 'AGENTS.md',
34
35
  grok: 'AGENTS.md', // Grok Build reads the AGENTS.md family (and CLAUDE.md) natively
35
36
  agy: 'AGENTS.md', // Antigravity reads the same AGENTS.md/GEMINI.md rules family natively
37
+ opencode: 'AGENTS.md', // opencode reads AGENTS.md (and CLAUDE.md) natively
36
38
  aider: 'AGENTS.md', // shares the Codex primer; aider is pointed at it via .aider.conf.yml
37
39
  gemini: 'GEMINI.md',
38
40
  copilot: '.github/copilot-instructions.md',
@@ -638,6 +640,34 @@ export function setupCodexIntegration() {
638
640
  ensureAgentSkillsInstalled();
639
641
  setupCodexHooks();
640
642
  }
643
+ // --- opencode ----------------------------------------------------------------
644
+ // opencode reads the same cross-agent ~/.agents/skills directory Codex does
645
+ // (it walks .agents/skills natively), so its skills install shares the Codex
646
+ // dir + manifest. Its deeper integration - the Gipity plugin providing the
647
+ // model slot and session capture - lives in opencode-setup.ts; the plugin file
648
+ // itself ships in the GipityAI/skills repo (hooks/scripts/opencode-plugin.mjs)
649
+ // and is staged into ~/.gipity/agent-hooks by installSkillsAndHooks like every
650
+ // other hook script.
651
+ /** Materialize the Gipity skills for opencode. Shares AGENTS_SKILLS_DIR (and
652
+ * the manifest) with Codex - both read the same cross-agent directory - but
653
+ * gates on the opencode binary so either tool being present is enough. */
654
+ export function ensureOpencodeSkillsInstalled() {
655
+ if (agentSkillsState().current)
656
+ return;
657
+ if (!binaryOnPath('opencode'))
658
+ return;
659
+ installSkillsAndHooks(AGENTS_SKILLS_DIR, AGENT_SKILLS_MANIFEST, 'opencode');
660
+ }
661
+ /** Full opencode integration: user-scope skills + the Gipity opencode plugin
662
+ * (model provider + session capture). Gated on the opencode binary. The
663
+ * import cycle with opencode-setup.ts (it reads AGENT_HOOKS_DIR from here)
664
+ * is safe: neither module calls into the other at module-eval time. */
665
+ export function setupOpencodeIntegration() {
666
+ if (!binaryOnPath('opencode'))
667
+ return;
668
+ ensureOpencodeSkillsInstalled();
669
+ ensureOpencodePluginInstalled();
670
+ }
641
671
  // --- Google Antigravity (agy) --------------------------------------------
642
672
  // agy's hook system is a real departure from the Claude-format hooks Codex
643
673
  // and Grok reuse: project hooks live in `.agents/hooks.json` as a NAMED-block
@@ -1009,6 +1039,7 @@ export const SUPPORTED_TOOLS = [
1009
1039
  { key: 'codex', label: 'OpenAI Codex (AGENTS.md + skills + sync hooks)', setup: setupAgentsMd, integrate: setupCodexIntegration },
1010
1040
  { key: 'grok', label: 'Grok Build (AGENTS.md + Gipity plugin)', setup: setupAgentsMd, integrate: ensureGrokPluginInstalled },
1011
1041
  { key: 'agy', label: 'Antigravity (AGENTS.md + skills + sync hooks)', setup: setupAgentsMd, integrate: setupAgyIntegration },
1042
+ { key: 'opencode', label: 'opencode (AGENTS.md + skills + Gipity plugin)', setup: setupAgentsMd, integrate: setupOpencodeIntegration },
1012
1043
  { key: 'aider', label: 'Aider (AGENTS.md + .aider.conf.yml)', setup: setupAiderMd, optIn: true },
1013
1044
  { key: 'gemini', label: 'Gemini CLI (GEMINI.md)', setup: setupGeminiMd },
1014
1045
  { key: 'copilot', label: 'GitHub Copilot (.github/copilot-instructions.md)', setup: setupCopilotMd },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gipity",
3
- "version": "1.1.11",
3
+ "version": "1.1.12",
4
4
  "description": "The full-stack platform tuned for AI agents. Database, storage, auth, functions, deploy, and drop-in kits - all agent-tuned. Pair with Claude Code or use standalone.",
5
5
  "bin": {
6
6
  "gipity": "dist/updater/shim.js",