gemini-headless-cli 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +18 -2
- package/bin/gemini-headless-cli.js +4 -0
- package/bin/gemini-headless.js +4 -0
- package/lib/launcher.js +55 -0
- package/lib/platform.js +56 -0
- package/package.json +37 -4
- package/skills/gemini-headless-cli/SKILL.md +112 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
-
#
|
|
1
|
+
# gemini-headless-cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Unofficial fork of google-gemini/gemini-api-cli for headless use. Not affiliated with Google.
|
|
4
|
+
|
|
5
|
+
The `gemini-headless` command is the fork's CLI. It is installed side by side with the official `gemini-api` command and does not replace it.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npx gemini-headless-cli --version
|
|
11
|
+
pnpm dlx gemini-headless-cli --version
|
|
12
|
+
npm install -g gemini-headless-cli && gemini-headless --version
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
This package has no install scripts. The native binary for your OS and CPU comes from one of the `@yasuguin/gemini-headless-cli-<os>-<arch>` packages listed in `optionalDependencies`.
|
|
16
|
+
|
|
17
|
+
Supported: darwin-arm64, darwin-x64, linux-arm64, linux-x64, win32-arm64, win32-x64.
|
|
18
|
+
|
|
19
|
+
Source and issues: https://github.com/yasuguin/gemini-headless-cli
|
package/lib/launcher.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// 本体パッケージの bin から呼ばれる。OS 別パッケージの実行ファイルを子プロセスで起動し、
|
|
4
|
+
// 終了コードとシグナルを呼び出し元へ伝える。
|
|
5
|
+
// postinstall を使わないのは pnpm v10 が依存の lifecycle script を既定で止めるため。
|
|
6
|
+
const { spawn } = require('node:child_process');
|
|
7
|
+
const { resolveBinary } = require('./platform');
|
|
8
|
+
|
|
9
|
+
// 親が受けたシグナルは子へ転送する。子の終了を待って、親も同じシグナルで終わらせる。
|
|
10
|
+
const FORWARDED_SIGNALS = ['SIGINT', 'SIGTERM', 'SIGHUP'];
|
|
11
|
+
|
|
12
|
+
function run(argv, deps = {}) {
|
|
13
|
+
const platform = deps.platform || process.platform;
|
|
14
|
+
const arch = deps.arch || process.arch;
|
|
15
|
+
const resolve = deps.resolve || require.resolve;
|
|
16
|
+
const spawnFn = deps.spawn || spawn;
|
|
17
|
+
const stderr = deps.stderr || process.stderr;
|
|
18
|
+
const exit = deps.exit || ((code) => process.exit(code));
|
|
19
|
+
const kill = deps.kill || ((sig) => process.kill(process.pid, sig));
|
|
20
|
+
|
|
21
|
+
const found = resolveBinary(platform, arch, resolve);
|
|
22
|
+
if (found.error) {
|
|
23
|
+
stderr.write(`${found.error}\n`);
|
|
24
|
+
exit(1);
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const child = spawnFn(found.path, argv, { stdio: 'inherit' });
|
|
29
|
+
const forwarders = FORWARDED_SIGNALS.map((sig) => {
|
|
30
|
+
const fn = () => child.kill(sig);
|
|
31
|
+
process.on(sig, fn);
|
|
32
|
+
return [sig, fn];
|
|
33
|
+
});
|
|
34
|
+
const cleanup = () => {
|
|
35
|
+
for (const [sig, fn] of forwarders) process.removeListener(sig, fn);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
child.on('error', (err) => {
|
|
39
|
+
cleanup();
|
|
40
|
+
stderr.write(`gemini-headless: 起動できない: ${err.message}\n`);
|
|
41
|
+
exit(1);
|
|
42
|
+
});
|
|
43
|
+
child.on('exit', (code, signal) => {
|
|
44
|
+
cleanup();
|
|
45
|
+
if (signal) {
|
|
46
|
+
// 子がシグナルで終わったときは同じシグナルで親も終わらせ、終了の理由を呼び出し元に残す。
|
|
47
|
+
kill(signal);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
exit(code === null ? 1 : code);
|
|
51
|
+
});
|
|
52
|
+
return child;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
module.exports = { run, FORWARDED_SIGNALS };
|
package/lib/platform.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// OS 別パッケージの対応表。goreleaser の 6 種(linux・windows・darwin × amd64・arm64)と一致させる。
|
|
4
|
+
// 表の順に並べる(エラーメッセージの対応表の並びになる)。
|
|
5
|
+
const SUPPORTED = [
|
|
6
|
+
{ platform: 'darwin', arch: 'arm64', pkg: 'darwin-arm64' },
|
|
7
|
+
{ platform: 'darwin', arch: 'x64', pkg: 'darwin-x64' },
|
|
8
|
+
{ platform: 'linux', arch: 'arm64', pkg: 'linux-arm64' },
|
|
9
|
+
{ platform: 'linux', arch: 'x64', pkg: 'linux-x64' },
|
|
10
|
+
{ platform: 'win32', arch: 'arm64', pkg: 'win32-arm64' },
|
|
11
|
+
{ platform: 'win32', arch: 'x64', pkg: 'win32-x64' },
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
const SCOPE = '@yasuguin/gemini-headless-cli';
|
|
15
|
+
|
|
16
|
+
function packageName(platform, arch) {
|
|
17
|
+
const entry = SUPPORTED.find((e) => e.platform === platform && e.arch === arch);
|
|
18
|
+
return entry ? `${SCOPE}-${entry.pkg}` : null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function binaryFileName(platform) {
|
|
22
|
+
return platform === 'win32' ? 'gemini-headless.exe' : 'gemini-headless';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Node の require.resolve で OS 別パッケージの場所を探す。入っていなければ null を返す。
|
|
26
|
+
function resolveBinary(platform, arch, resolve = require.resolve) {
|
|
27
|
+
const name = packageName(platform, arch);
|
|
28
|
+
if (name === null) {
|
|
29
|
+
return { error: unsupportedMessage(platform, arch) };
|
|
30
|
+
}
|
|
31
|
+
const file = binaryFileName(platform);
|
|
32
|
+
try {
|
|
33
|
+
return { path: resolve(`${name}/${file}`) };
|
|
34
|
+
} catch (err) {
|
|
35
|
+
if (err && err.code === 'MODULE_NOT_FOUND') {
|
|
36
|
+
return {
|
|
37
|
+
error:
|
|
38
|
+
`gemini-headless: ${name} が入っていない。` +
|
|
39
|
+
' optionalDependencies の取得が止められていないか(--no-optional など)確かめ、' +
|
|
40
|
+
'npm・pnpm・yarn で入れ直す。',
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
throw err;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function unsupportedMessage(platform, arch) {
|
|
48
|
+
const lines = SUPPORTED.map((e) => ` ${e.platform}-${e.arch}`);
|
|
49
|
+
return [
|
|
50
|
+
`gemini-headless: ${platform}-${arch} は対応していない。対応表:`,
|
|
51
|
+
...lines,
|
|
52
|
+
'ほかの環境では、GitHub Releases の tar.gz・zip か PyPI 版(gemini-headless-cli)を使う。',
|
|
53
|
+
].join('\n');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
module.exports = { SUPPORTED, packageName, binaryFileName, resolveBinary, unsupportedMessage };
|
package/package.json
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gemini-headless-cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Unofficial fork of google-gemini/gemini-api-cli for headless use. Not affiliated with Google.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"homepage": "https://github.com/yasuguin/gemini-headless-cli",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/yasuguin/gemini-headless-cli.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/yasuguin/gemini-headless-cli/issues"
|
|
13
|
+
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"gemini-headless": "bin/gemini-headless.js",
|
|
16
|
+
"gemini-headless-cli": "bin/gemini-headless-cli.js"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"bin",
|
|
20
|
+
"lib",
|
|
21
|
+
"skills",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=18"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"optionalDependencies": {
|
|
32
|
+
"@yasuguin/gemini-headless-cli-darwin-arm64": "0.1.0",
|
|
33
|
+
"@yasuguin/gemini-headless-cli-darwin-x64": "0.1.0",
|
|
34
|
+
"@yasuguin/gemini-headless-cli-linux-arm64": "0.1.0",
|
|
35
|
+
"@yasuguin/gemini-headless-cli-linux-x64": "0.1.0",
|
|
36
|
+
"@yasuguin/gemini-headless-cli-win32-arm64": "0.1.0",
|
|
37
|
+
"@yasuguin/gemini-headless-cli-win32-x64": "0.1.0"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: gemini-headless-cli
|
|
3
|
+
description: Call Gemini API or Agent Platform (Vertex AI) headlessly from agents, scripts, and CI with the gemini-headless CLI (generate, analyze, transcribe, image, TTS).
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# gemini-headless
|
|
7
|
+
|
|
8
|
+
`gemini-headless` is an unofficial fork of the upstream `gemini-api` CLI. It sends the same commands to either:
|
|
9
|
+
|
|
10
|
+
- the Gemini API (default, authenticated with an API key), or
|
|
11
|
+
- Agent Platform (formerly Vertex AI), authenticated with Application Default Credentials (ADC), so IAM, audit logs, and VPC Service Controls apply.
|
|
12
|
+
|
|
13
|
+
Run `gemini-headless --help` and `gemini-headless <command> --help` for the full flag list. This skill covers what an agent needs to choose the backend, recover from auth errors, and avoid commands that Agent Platform does not serve.
|
|
14
|
+
|
|
15
|
+
## 1. Choose and check the backend first
|
|
16
|
+
|
|
17
|
+
Run this before any real call:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
gemini-headless whoami
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
It prints the resolved `backend`, `project`, and `location`, and where each value came from (flag, env, config, or default). Check that the project is the one you expect before a call that costs money.
|
|
24
|
+
|
|
25
|
+
Backend resolution order (first match wins):
|
|
26
|
+
|
|
27
|
+
1. `--backend vertex|gemini`
|
|
28
|
+
2. `GOOGLE_GENAI_USE_VERTEXAI=true|false`
|
|
29
|
+
3. `backend:` in `~/.config/gemini-headless/config.yaml`
|
|
30
|
+
4. default `gemini`
|
|
31
|
+
|
|
32
|
+
Project and location use the same order: flag, env (`GOOGLE_CLOUD_PROJECT`, `GOOGLE_CLOUD_LOCATION`), config (`project:`, `location:`). Location defaults to `global`.
|
|
33
|
+
|
|
34
|
+
To use Agent Platform for one call:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
gemini-headless generate "Hello" --backend vertex --project my-project
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## 2. Authentication
|
|
41
|
+
|
|
42
|
+
- Gemini API: set `GEMINI_API_KEY`, or run `gemini-headless configure` (the user must create the key; do not create one for them).
|
|
43
|
+
- Agent Platform: ADC, in this order: `--access-token` (highest priority), then `GOOGLE_APPLICATION_CREDENTIALS`, the gcloud ADC file, then the metadata server (on Cloud Run, GCE, and Workload Identity). The token is refreshed per request.
|
|
44
|
+
|
|
45
|
+
When Agent Platform auth fails, the error names the fix. Typical fixes:
|
|
46
|
+
|
|
47
|
+
- No ADC found: `gcloud auth application-default login`, or set `GOOGLE_APPLICATION_CREDENTIALS`.
|
|
48
|
+
- Token could not be refreshed: run `gcloud auth application-default login` again.
|
|
49
|
+
- No project: pass `--project`, set `GOOGLE_CLOUD_PROJECT`, or add `project:` to the config file.
|
|
50
|
+
|
|
51
|
+
Do not switch to an API key to get past an Agent Platform error. The CLI does not send an API key to Agent Platform.
|
|
52
|
+
|
|
53
|
+
## 3. Model names
|
|
54
|
+
|
|
55
|
+
- Use the same model names on both backends.
|
|
56
|
+
- If you do not pass `--model`, and the default is not served on Agent Platform, the CLI uses a replacement and prints a notice (`Using <replacement>: <default> is not available on Agent Platform`) to stderr, except with `-o json` or `--agent-mode`. Example: `transcribe` uses `gemini-3.8-flash` on Agent Platform instead of `gemini-3.5-transcribe`.
|
|
57
|
+
- If you pass `--model` explicitly and Agent Platform does not serve it, the CLI stops with a list of alternatives. It does not switch models silently. Pick one of the listed names and pass it again.
|
|
58
|
+
- `gemini-headless models` prints the offline catalog with the Agent Platform status of each model. `gemini-headless models list` and `models get` query the live API.
|
|
59
|
+
|
|
60
|
+
Models verified on Agent Platform (2026-11-26): `gemini-4-hydrogen` (default), `gemini-4-argon`, `gemini-4-carbon`, `gemini-4-neon`, `gemini-3.8-flash`, `gemini-3.7-flash`, `gemini-3.5-flash`. Not served: `gemini-2.5-flash`, `gemini-2.5-pro`, `gemini-flash-latest`, `gemini-pro-latest`, `gemma-4-31b-it`.
|
|
61
|
+
|
|
62
|
+
## 4. Commands on Agent Platform
|
|
63
|
+
|
|
64
|
+
Works:
|
|
65
|
+
|
|
66
|
+
- `generate`, `analyze`, `agent run`, `agent status`, `agent list`
|
|
67
|
+
- `transcribe` (default model is replaced as above)
|
|
68
|
+
- `image`: writes an image file; `--aspect-ratio`, `--image-size`, `--output-mime-type`, and an input image for edits work
|
|
69
|
+
- `tts`: writes a WAV file; `--voice`, `--style`, and `--multi-speaker` (up to 2 speakers) work
|
|
70
|
+
- `models list`, `models get`, `whoami`, `models`
|
|
71
|
+
|
|
72
|
+
Refused before any request, with exit code 2:
|
|
73
|
+
|
|
74
|
+
- `files` (including `files upload`). Put the file in Cloud Storage and pass its `gs://` URI with `--input`.
|
|
75
|
+
- `environments`, `triggers`, `webhooks`, `voices`, `credentials`
|
|
76
|
+
|
|
77
|
+
Not verified on Agent Platform: `music`, `video`, `gs://` input (the smoke run skipped it), and `agent` subcommands other than run, status, and list. Treat these as untested and check the output carefully.
|
|
78
|
+
|
|
79
|
+
Not supported: `tts --voice-prompt` (custom voices). Use a built-in voice name.
|
|
80
|
+
|
|
81
|
+
## 5. Command examples
|
|
82
|
+
|
|
83
|
+
These run against the default backend unless you pass `--backend vertex`.
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
gemini-headless generate "Explain concurrency in one sentence"
|
|
87
|
+
gemini-headless generate "Write a haiku" --stream=false -o json
|
|
88
|
+
gemini-headless analyze -i photo.jpg "What is in this picture?"
|
|
89
|
+
gemini-headless analyze -i gs://my-bucket/talk.mp4 "Summarize the talk"
|
|
90
|
+
gemini-headless transcribe -i interview.mp3 --format srt --out interview.srt
|
|
91
|
+
gemini-headless image "a lighthouse at sunset" --aspect-ratio 16:9 --out lighthouse.png
|
|
92
|
+
gemini-headless tts "Welcome to the show" --voice Puck --out welcome.wav
|
|
93
|
+
gemini-headless tts "Alice: hi. Bob: hello." --multi-speaker "Alice=Kore,Bob=Puck" --out dialog.wav
|
|
94
|
+
gemini-headless models list -o json
|
|
95
|
+
gemini-headless agent run --help
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Use `--help` on the subcommand before you guess a flag. Do not invent flags.
|
|
99
|
+
|
|
100
|
+
## 6. Flags for agents
|
|
101
|
+
|
|
102
|
+
- `--dry-run`: builds the request and prints it without sending. Use it to check the URL, the backend, and the body before a paid call. Credentials are masked.
|
|
103
|
+
- `--agent-mode`: structured errors with the fix in each error. Use it when you parse failures.
|
|
104
|
+
- `-o json` or `--jq '<expr>'`: machine-readable output. Use `--jq` to pick a field.
|
|
105
|
+
- `--usage`: prints the command schema in KDL, for discovering flags.
|
|
106
|
+
|
|
107
|
+
Exit codes: 0 ok, 1 runtime error, 2 usage error (including a command Agent Platform does not serve), 3 authentication or authorization error.
|
|
108
|
+
|
|
109
|
+
## 7. Things not to do
|
|
110
|
+
|
|
111
|
+
- Do not run `configure` or create an API key on the user's behalf.
|
|
112
|
+
- Do not pass a local file larger than about 14 MB to `analyze` or `transcribe`. Upload it to Cloud Storage and pass the `gs://` URI on Agent Platform, or use `files upload` on the Gemini API.
|