agnify 0.1.0__py3-none-any.whl
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.
- agnify-0.1.0.dist-info/METADATA +90 -0
- agnify-0.1.0.dist-info/RECORD +24 -0
- agnify-0.1.0.dist-info/WHEEL +4 -0
- agnify-0.1.0.dist-info/entry_points.txt +2 -0
- agnify-0.1.0.dist-info/licenses/LICENSE +202 -0
- agnify_cli/__init__.py +67 -0
- agnify_cli/_auth.py +207 -0
- agnify_cli/_client.py +212 -0
- agnify_cli/_config.py +82 -0
- agnify_cli/_models.py +22 -0
- agnify_cli/_output.py +99 -0
- agnify_cli/_v1_menu.py +40 -0
- agnify_cli/_validation.py +195 -0
- agnify_cli/auth.py +159 -0
- agnify_cli/camera.py +595 -0
- agnify_cli/events.py +144 -0
- agnify_cli/file.py +103 -0
- agnify_cli/ingest.py +186 -0
- agnify_cli/nodes.py +72 -0
- agnify_cli/org.py +69 -0
- agnify_cli/pipeline.py +151 -0
- agnify_cli/py.typed +0 -0
- agnify_cli/run.py +357 -0
- agnify_cli/templates.py +73 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agnify
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Command-line client for Agnify — drive video-analysis pipelines, uploads, executions, cameras, and events from your terminal.
|
|
5
|
+
Project-URL: Homepage, https://app.agnify.ai
|
|
6
|
+
Project-URL: Documentation, https://app.agnify.ai/docs/cli
|
|
7
|
+
Project-URL: Repository, https://github.com/agnifyai/agnify
|
|
8
|
+
Project-URL: Issues, https://github.com/agnifyai/agnify/issues
|
|
9
|
+
Author-email: Agnify <support@agnify.ai>
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: agnify,cli,computer-vision,inference,pipeline,video
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Environment :: Console
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Multimedia :: Video
|
|
22
|
+
Classifier: Topic :: Utilities
|
|
23
|
+
Requires-Python: >=3.11
|
|
24
|
+
Requires-Dist: httpx>=0.26.0
|
|
25
|
+
Requires-Dist: pydantic>=2.5.0
|
|
26
|
+
Requires-Dist: pyjwt>=2.8.0
|
|
27
|
+
Requires-Dist: rich>=13.0.0
|
|
28
|
+
Requires-Dist: typer>=0.12.0
|
|
29
|
+
Provides-Extra: keyring
|
|
30
|
+
Requires-Dist: keyring>=24.0.0; extra == 'keyring'
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
# Agnify CLI
|
|
34
|
+
|
|
35
|
+
`agnify` is the command-line client for [Agnify](https://app.agnify.ai), a
|
|
36
|
+
video-analysis platform. Drive pipelines, upload media, run executions, manage
|
|
37
|
+
cameras, and query events — all from your terminal.
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
One line (installs [uv](https://docs.astral.sh/uv/) if needed, then the CLI):
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
curl -LsSf https://app.agnify.ai/install.sh | sh
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Or, if you already have a Python toolchain:
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
uv tool install 'agnify[keyring]' # recommended — OS keychain for tokens
|
|
51
|
+
# or
|
|
52
|
+
pipx install 'agnify[keyring]'
|
|
53
|
+
# or
|
|
54
|
+
pip install 'agnify[keyring]'
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The `[keyring]` extra stores your refresh token in the OS keychain (macOS
|
|
58
|
+
Keychain, Secret Service, Windows Credential Manager). Plain `agnify` also
|
|
59
|
+
works — it falls back to a `0600` file under `~/.config/agnify/`.
|
|
60
|
+
|
|
61
|
+
## Authenticate
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
agnify login # device-code flow in your browser
|
|
65
|
+
agnify whoami # confirm the active user + org
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
For CI / cron / integrations, skip `login` and set an org-scoped API key:
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
export AGNIFY_API_KEY=ak_… # minted in the Agnify dashboard
|
|
72
|
+
export AGNIFY_API_BASE=https://app.agnify.ai
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Self-hosted? Point the CLI at your backend with `AGNIFY_API_BASE`.
|
|
76
|
+
|
|
77
|
+
## Use
|
|
78
|
+
|
|
79
|
+
```sh
|
|
80
|
+
agnify nodes list # the pipeline node menu
|
|
81
|
+
agnify ingest file ./clip.mp4 --wait # upload + run + wait for results
|
|
82
|
+
agnify run ls # list executions
|
|
83
|
+
agnify events tail # stream live pipeline events
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Full command reference: <https://app.agnify.ai/docs/cli>
|
|
87
|
+
|
|
88
|
+
## License
|
|
89
|
+
|
|
90
|
+
[Apache-2.0](./LICENSE) © 2026 Fewbits Inc. (Agnify).
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
agnify_cli/__init__.py,sha256=yTiCGWIN-_dkDYCRcbMLMzXu7PeNk94NMzaEwFztZNE,2602
|
|
2
|
+
agnify_cli/_auth.py,sha256=WuGAUPlmOXHcOhuers6UgpjvQqT3nwu3KTyePbZKn38,6617
|
|
3
|
+
agnify_cli/_client.py,sha256=nmxKfmWAXs_FXpe8vu6hKnIFMQrlnJKSUUBxprB9Qeo,7955
|
|
4
|
+
agnify_cli/_config.py,sha256=SnTLtw7I8UZctWsNlrRt52qNpD9ZwD7u13UkAxqIVh4,2405
|
|
5
|
+
agnify_cli/_models.py,sha256=hewAepXdNMyPi15gxN24hCft3TkUJVJ-tWvdW-8CFe4,813
|
|
6
|
+
agnify_cli/_output.py,sha256=k4HonwaZZAGdtuUY7s4xzNeHzjGiRsVJMhAayyuxw18,3103
|
|
7
|
+
agnify_cli/_v1_menu.py,sha256=c5ZBoT96Zz2kIx8qFsgkIkolkZ0Pz2Hh2gFCr32_d7s,1477
|
|
8
|
+
agnify_cli/_validation.py,sha256=U4FpVXAfNT9sTYOuf_RA7zKB7evyBajORhq9oKTqU14,6906
|
|
9
|
+
agnify_cli/auth.py,sha256=13dUqoGlD571A0VeWv6u6SlDmlBag5JW7tCcnj29o0E,5625
|
|
10
|
+
agnify_cli/camera.py,sha256=ccNhws80xq_GIu370VtY4uwsgJLjDjAizElMOPDRt8Y,19839
|
|
11
|
+
agnify_cli/events.py,sha256=oQkQg_09UnoeG6_7Q2ShGc1EoS2rhcmuOby09B9gucI,5111
|
|
12
|
+
agnify_cli/file.py,sha256=8dk7yDbecpbz31UPF-mCT13WRXRobx7LgBeDksvK8_8,3340
|
|
13
|
+
agnify_cli/ingest.py,sha256=kxuEGUE5RKdWmQmcqSO98bVs6FEOQQI113C9thgdXDQ,5752
|
|
14
|
+
agnify_cli/nodes.py,sha256=22rzyxuFSdNHbUA2xOvFFMKs1fW_IM6YbSnc3nHxS6o,2297
|
|
15
|
+
agnify_cli/org.py,sha256=MJDx-SaU1Z48dleCJv3WgKQH9YUvJ3LO_jJoDekK-Y4,2088
|
|
16
|
+
agnify_cli/pipeline.py,sha256=Uo2_rEX7HO6jFXB6xji2C44kX0GQPjnlaRuPltxVTMg,4768
|
|
17
|
+
agnify_cli/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
|
+
agnify_cli/run.py,sha256=ZpyRp-83ixWqoR6Z8__zaw0s2TdB6MWcPnT-n2FoRYs,11592
|
|
19
|
+
agnify_cli/templates.py,sha256=CTGcEZr-E2WVUtgqQAhXeaB5Cf1ZX8LtznOtQ8xalaE,2238
|
|
20
|
+
agnify-0.1.0.dist-info/METADATA,sha256=ZNkCIbZeFA8GMff1aiikiGr1egUB90H_rljWl-Xz0jg,2897
|
|
21
|
+
agnify-0.1.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
22
|
+
agnify-0.1.0.dist-info/entry_points.txt,sha256=bh7ydom1lV_jFXFruhuNHVPncXAJuE63rAnczAX7qM8,43
|
|
23
|
+
agnify-0.1.0.dist-info/licenses/LICENSE,sha256=Unz2ZaN0DTsSPVs3Kutz3JN45cpE1q8C6DqD07XmOMs,11343
|
|
24
|
+
agnify-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Fewbits Inc.
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
agnify_cli/__init__.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""``agnify`` CLI — narrow tool surface for the Agent MVP harness.
|
|
2
|
+
|
|
3
|
+
The agent (Claude Code headless) reaches the backend through this CLI rather
|
|
4
|
+
than calling HTTP directly. Every command:
|
|
5
|
+
|
|
6
|
+
- reads ``AGNIFY_API_BASE`` / ``AGNIFY_API_KEY`` / ``AGNIFY_ORG_ID`` (and
|
|
7
|
+
where relevant ``AGNIFY_DRAFT_EXECUTION_ID``) from the environment;
|
|
8
|
+
- emits a single JSON object to stdout on success, exit 0;
|
|
9
|
+
- emits a single JSON ``{"error": ..., "detail": ...}`` to stderr on failure,
|
|
10
|
+
non-zero exit.
|
|
11
|
+
|
|
12
|
+
See ``docs/specs/agent.md`` for the full surface.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import typer
|
|
18
|
+
|
|
19
|
+
from agnify_cli import _output
|
|
20
|
+
from agnify_cli import auth as auth_cmd
|
|
21
|
+
from agnify_cli import camera as camera_cmd
|
|
22
|
+
from agnify_cli import events as events_cmd
|
|
23
|
+
from agnify_cli import file as file_cmd
|
|
24
|
+
from agnify_cli import ingest as ingest_cmd
|
|
25
|
+
from agnify_cli import nodes as nodes_cmd
|
|
26
|
+
from agnify_cli import org as org_cmd
|
|
27
|
+
from agnify_cli import pipeline as pipeline_cmd
|
|
28
|
+
from agnify_cli import run as run_cmd
|
|
29
|
+
from agnify_cli import templates as templates_cmd
|
|
30
|
+
|
|
31
|
+
app = typer.Typer(
|
|
32
|
+
name="agnify",
|
|
33
|
+
help="Agent-facing CLI: narrow wrappers around the Agnify backend API.",
|
|
34
|
+
no_args_is_help=True,
|
|
35
|
+
add_completion=False,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@app.callback()
|
|
40
|
+
def _root(
|
|
41
|
+
output: str = typer.Option(
|
|
42
|
+
"auto",
|
|
43
|
+
"--output", "-o",
|
|
44
|
+
help="Output format: 'auto' (table on TTY, JSON elsewhere), 'json', or 'table'.",
|
|
45
|
+
),
|
|
46
|
+
) -> None:
|
|
47
|
+
"""Configure global flags before any subcommand runs."""
|
|
48
|
+
_output.set_mode(output)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
app.command("login", help="Authenticate this machine via the device-code flow.")(auth_cmd.login)
|
|
52
|
+
app.command("logout", help="Forget this machine's refresh token + active org.")(auth_cmd.logout)
|
|
53
|
+
app.command("whoami", help="Show the currently-authenticated user + active org.")(auth_cmd.whoami)
|
|
54
|
+
|
|
55
|
+
app.add_typer(nodes_cmd.app, name="nodes", help="Inspect the node menu.")
|
|
56
|
+
app.add_typer(templates_cmd.app, name="templates", help="List pipeline templates.")
|
|
57
|
+
app.add_typer(pipeline_cmd.app, name="pipeline", help="Inspect / mutate the draft pipeline.")
|
|
58
|
+
app.add_typer(file_cmd.app, name="file", help="Read uploaded-file artifacts.")
|
|
59
|
+
app.add_typer(org_cmd.app, name="org", help="Active-organization management.")
|
|
60
|
+
app.add_typer(run_cmd.app, name="run", help="Execution lifecycle commands.")
|
|
61
|
+
app.add_typer(events_cmd.app, name="events", help="Query metrics-channel events.")
|
|
62
|
+
app.add_typer(ingest_cmd.app, name="ingest", help="Upload-and-run convenience flows.")
|
|
63
|
+
app.add_typer(camera_cmd.app, name="camera", help="Camera management + segment streaming.")
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def main() -> None:
|
|
67
|
+
app()
|
agnify_cli/_auth.py
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"""Keychain-backed credential resolution for the human CLI path.
|
|
2
|
+
|
|
3
|
+
The agent + CI path doesn't touch any of this — env vars short-circuit
|
|
4
|
+
in :func:`agnify_cli._client.get_client` before this module is imported.
|
|
5
|
+
|
|
6
|
+
For human users:
|
|
7
|
+
|
|
8
|
+
* The **refresh token** prefers the OS keychain (macOS Keychain, Secret
|
|
9
|
+
Service on Linux, Windows Credential Manager — whatever ``keyring``
|
|
10
|
+
resolves to). When the keychain refuses to interact (locked, headless,
|
|
11
|
+
-25308 ``errSecInteractionNotAllowed`` from a non-Aqua context), the
|
|
12
|
+
token falls back to a 0600 file at ``~/.config/agnify/refresh_token``.
|
|
13
|
+
Matches ``gh`` / ``gcloud`` / ``aws`` behavior. Both stores are
|
|
14
|
+
consulted on read; logout wipes both.
|
|
15
|
+
* The **access token** is short-lived (1 hour) and cached in process
|
|
16
|
+
memory only. JWTs are self-describing, so we decode-without-verify to
|
|
17
|
+
read ``exp`` and refresh proactively when fewer than 60s remain.
|
|
18
|
+
|
|
19
|
+
Errors surface as ``CliError`` with exit code 2 so the calling command
|
|
20
|
+
prints a clean "run agnify login" hint and exits non-zero.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
from __future__ import annotations
|
|
24
|
+
|
|
25
|
+
import sys
|
|
26
|
+
import time
|
|
27
|
+
from dataclasses import dataclass
|
|
28
|
+
from pathlib import Path
|
|
29
|
+
|
|
30
|
+
import httpx
|
|
31
|
+
import jwt as pyjwt
|
|
32
|
+
|
|
33
|
+
from agnify_cli._client import CLI_TOKEN_PREFIX, CliError
|
|
34
|
+
from agnify_cli._config import (
|
|
35
|
+
KEYRING_SERVICE,
|
|
36
|
+
KEYRING_USERNAME,
|
|
37
|
+
config_dir,
|
|
38
|
+
get_active_org_id,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
_REFRESH_THRESHOLD_S = 60
|
|
42
|
+
_REFRESH_ENDPOINT = "/api/v1/cli/token/refresh"
|
|
43
|
+
_FILE_FALLBACK_NAME = "refresh_token"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _keyring():
|
|
47
|
+
"""Import lazily so the agent path stays keyring-free.
|
|
48
|
+
|
|
49
|
+
Importing ``keyring`` triggers a backend resolution that can pop a
|
|
50
|
+
macOS Keychain auth dialog the first time. Deferring it to first
|
|
51
|
+
human-mode use keeps non-interactive (agent + CI) invocations silent.
|
|
52
|
+
"""
|
|
53
|
+
import keyring # noqa: PLC0415 — see module docstring
|
|
54
|
+
return keyring
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _fallback_path() -> Path:
|
|
58
|
+
return config_dir() / _FILE_FALLBACK_NAME
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _file_store(wire: str) -> None:
|
|
62
|
+
path = _fallback_path()
|
|
63
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
64
|
+
path.write_text(wire, encoding="utf-8")
|
|
65
|
+
path.chmod(0o600)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _file_read() -> str | None:
|
|
69
|
+
path = _fallback_path()
|
|
70
|
+
if not path.exists():
|
|
71
|
+
return None
|
|
72
|
+
return path.read_text(encoding="utf-8").strip() or None
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _file_delete() -> None:
|
|
76
|
+
path = _fallback_path()
|
|
77
|
+
if path.exists():
|
|
78
|
+
path.unlink()
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def store_refresh_token(wire: str) -> None:
|
|
82
|
+
"""Write the refresh token, preferring the OS keychain.
|
|
83
|
+
|
|
84
|
+
Falls back to a 0600 file at ``~/.config/agnify/refresh_token`` when
|
|
85
|
+
the keychain refuses (locked, headless, no GUI session, etc.). The
|
|
86
|
+
fallback notice fires only when the file didn't exist before this
|
|
87
|
+
write — subsequent token rotations stay silent so commands don't
|
|
88
|
+
repeat the warning on every invocation.
|
|
89
|
+
"""
|
|
90
|
+
try:
|
|
91
|
+
_keyring().set_password(KEYRING_SERVICE, KEYRING_USERNAME, wire)
|
|
92
|
+
# Clear any stale fallback file from a prior keychain-less run so
|
|
93
|
+
# we don't end up with two conflicting tokens on disk.
|
|
94
|
+
_file_delete()
|
|
95
|
+
return
|
|
96
|
+
except Exception as exc:
|
|
97
|
+
first_time = not _fallback_path().exists()
|
|
98
|
+
_file_store(wire)
|
|
99
|
+
if first_time:
|
|
100
|
+
sys.stderr.write(
|
|
101
|
+
f"note: OS keychain unavailable ({exc.__class__.__name__}); "
|
|
102
|
+
f"refresh token saved to {_fallback_path()} (0600).\n",
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def read_refresh_token() -> str | None:
|
|
107
|
+
try:
|
|
108
|
+
val = _keyring().get_password(KEYRING_SERVICE, KEYRING_USERNAME)
|
|
109
|
+
if val:
|
|
110
|
+
return val
|
|
111
|
+
except Exception:
|
|
112
|
+
pass
|
|
113
|
+
return _file_read()
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def delete_refresh_token() -> None:
|
|
117
|
+
try:
|
|
118
|
+
_keyring().delete_password(KEYRING_SERVICE, KEYRING_USERNAME)
|
|
119
|
+
except Exception:
|
|
120
|
+
# Already absent / keychain unavailable is a no-op — ``logout`` is best-effort.
|
|
121
|
+
pass
|
|
122
|
+
_file_delete()
|
|
123
|
+
_reset_cache()
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
@dataclass
|
|
127
|
+
class _AccessCache:
|
|
128
|
+
token: str
|
|
129
|
+
exp: int # unix seconds
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
_cache: _AccessCache | None = None
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _reset_cache() -> None:
|
|
136
|
+
"""Test seam — drop the in-process access-token cache."""
|
|
137
|
+
global _cache
|
|
138
|
+
_cache = None
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def _read_jwt_exp(token: str) -> int:
|
|
142
|
+
"""Decode-without-verify to extract the JWT's ``exp`` claim."""
|
|
143
|
+
encoded = token.removeprefix(CLI_TOKEN_PREFIX)
|
|
144
|
+
try:
|
|
145
|
+
claims = pyjwt.decode(encoded, options={"verify_signature": False})
|
|
146
|
+
except pyjwt.InvalidTokenError as exc:
|
|
147
|
+
raise CliError(
|
|
148
|
+
"could not decode access token", detail={"reason": str(exc)}, exit_code=2,
|
|
149
|
+
)
|
|
150
|
+
return int(claims.get("exp", 0))
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def refresh_if_needed(api_base: str) -> str:
|
|
154
|
+
"""Return a valid access token, refreshing from the keychain if needed."""
|
|
155
|
+
global _cache
|
|
156
|
+
now = int(time.time())
|
|
157
|
+
if _cache and _cache.exp - now > _REFRESH_THRESHOLD_S:
|
|
158
|
+
return _cache.token
|
|
159
|
+
refresh = read_refresh_token()
|
|
160
|
+
if not refresh:
|
|
161
|
+
raise CliError(
|
|
162
|
+
"not logged in; run `agnify login`",
|
|
163
|
+
detail={"hint": "no refresh token in keychain"},
|
|
164
|
+
exit_code=2,
|
|
165
|
+
)
|
|
166
|
+
try:
|
|
167
|
+
resp = httpx.post(
|
|
168
|
+
f"{api_base.rstrip('/')}{_REFRESH_ENDPOINT}",
|
|
169
|
+
json={"refresh_token": refresh},
|
|
170
|
+
timeout=15.0,
|
|
171
|
+
)
|
|
172
|
+
resp.raise_for_status()
|
|
173
|
+
except httpx.HTTPStatusError as exc:
|
|
174
|
+
# Surface a hint to re-login on a hard 400 (rotated, expired, replayed).
|
|
175
|
+
if exc.response.status_code == 400:
|
|
176
|
+
delete_refresh_token()
|
|
177
|
+
raise CliError(
|
|
178
|
+
"refresh token rejected; run `agnify login` again",
|
|
179
|
+
detail={"status": 400},
|
|
180
|
+
exit_code=2,
|
|
181
|
+
)
|
|
182
|
+
raise CliError(
|
|
183
|
+
"refresh failed",
|
|
184
|
+
detail={"status": exc.response.status_code, "body": exc.response.text},
|
|
185
|
+
exit_code=3,
|
|
186
|
+
)
|
|
187
|
+
except httpx.HTTPError as exc:
|
|
188
|
+
raise CliError(
|
|
189
|
+
"network error during token refresh",
|
|
190
|
+
detail={"type": type(exc).__name__, "message": str(exc)},
|
|
191
|
+
exit_code=3,
|
|
192
|
+
)
|
|
193
|
+
body = resp.json()
|
|
194
|
+
access_token = body["access_token"]
|
|
195
|
+
new_refresh = body["refresh_token"]
|
|
196
|
+
store_refresh_token(new_refresh)
|
|
197
|
+
_cache = _AccessCache(token=access_token, exp=_read_jwt_exp(access_token))
|
|
198
|
+
return access_token
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def resolve_credentials(api_base: str) -> tuple[str, str | None]:
|
|
202
|
+
"""Return ``(access_token, active_org_id)`` for the human-CLI path.
|
|
203
|
+
|
|
204
|
+
Raises :class:`CliError` (exit 2) if the user hasn't logged in.
|
|
205
|
+
"""
|
|
206
|
+
access_token = refresh_if_needed(api_base)
|
|
207
|
+
return access_token, get_active_org_id()
|