arctiq-cli 0.2.0__tar.gz

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.
@@ -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 [yyyy] [name of copyright owner]
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.
@@ -0,0 +1,116 @@
1
+ Metadata-Version: 2.4
2
+ Name: arctiq-cli
3
+ Version: 0.2.0
4
+ Summary: The arctiq command: ARCTIQ from a terminal, for developers and their AI assistants.
5
+ Author: ARCTIQ
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://arctiq.xyz
8
+ Keywords: arctiq,cli,research,collaboration,github
9
+ Classifier: Environment :: Console
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3 :: Only
15
+ Requires-Python: >=3.10
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Provides-Extra: keyring
19
+ Requires-Dist: keyring>=24; extra == "keyring"
20
+ Provides-Extra: tui
21
+ Requires-Dist: textual<9,>=8.2; extra == "tui"
22
+ Provides-Extra: seal
23
+ Requires-Dist: cryptography>=47; extra == "seal"
24
+ Requires-Dist: cbor2>=5.4; extra == "seal"
25
+ Dynamic: license-file
26
+
27
+ # arctiq-cli
28
+
29
+ The `arctiq` command: ARCTIQ from a terminal, for developers and the AI assistants working with them.
30
+
31
+ ```bash
32
+ pipx install arctiq-cli # or: uv tool install arctiq-cli
33
+ arctiq login
34
+ ```
35
+
36
+ The first `login` asks for your ARCTIQ address (or pass `--server`) and remembers it. It prints an
37
+ address and a code: open the address, enter the code and approve. The token is
38
+ kept in your system's keyring (install `arctiq-cli[keyring]`) or in a file only you can read.
39
+
40
+ ## Artefacts and files
41
+
42
+ ```bash
43
+ arctiq artefacts --repo my-org/my-repo
44
+ arctiq new --repo my-org/my-repo --problem "…" --domain "…" --approach "…"
45
+ arctiq upload paper.pdf data.csv --repo my-org/my-repo # each file is scanned on arrival
46
+ arctiq files | download NAME | remove NAME | submit | open # with --repo, and --artefact when there are several
47
+ ```
48
+
49
+ Inside a clone of a GitHub repository linked to ARCTIQ, `arctiq link` writes `.arctiq.yml` and the
50
+ commands need no `--repo`. `arctiq status` shows the repository's artefacts, the proposals waiting
51
+ for you and the last pull-request check; `arctiq pin TAG` keeps a tagged release as evidence.
52
+
53
+ ## Resources and Try it
54
+
55
+ ```bash
56
+ arctiq resources # code, data and documents; then partners'
57
+ arctiq resources show "syndrome records" # one, with its columns and files
58
+ arctiq resources sample field-run-magnetometer-records --csv sample.csv # made-up rows
59
+ arctiq resources add ./syndrome_2026_q4.parquet --level 3 # to ARCTIQ storage, in parts
60
+ arctiq resources add-version "syndrome records" ./syndrome_2026_q1.parquet # its next version
61
+ arctiq ask field-run-magnetometer-records --mean b_field_nt --by site
62
+ arctiq ask field-run-magnetometer-records --count --where site=Svalbard --where "day>=2026-03-01"
63
+ ```
64
+
65
+ `resources` is the repository's Resources tab: `--json` for scripts. `add` sends each file in
66
+ parts, sealed with your organisation's key as each arrives, then scanned; with no file it adds a
67
+ resource described only. `ask` asks a dataset a partner shares with this repository, under its
68
+ space's rules: noise and the privacy budget when the agreement has one, every question in both
69
+ sides' logs, and a refusal names the rule that refused it. `show` on a partner's dataset gives
70
+ its summary, with noise; `sample` prints a synthetic sample drawn from it (no row is real), and
71
+ `--csv FILE` saves it.
72
+
73
+ `add-version` sends files as the next version of one of your datasets. Each space that holds it
74
+ then waits for you to check it there.
75
+
76
+ ## Datasets sealed for enclaves
77
+
78
+ ```bash
79
+ pipx install "arctiq-cli[seal]"
80
+ arctiq resources add-version "syndrome records" ./syndrome_2026_q1.parquet
81
+ ```
82
+
83
+ A dataset sealed for enclaves takes only files sealed on your side. Before anything is sealed,
84
+ `add-version` checks the attestation the enclave made with the dataset's key:
85
+ - its signature, and its chain to a root this tool trusts;
86
+ - that the image it names is one the owner allows;
87
+ - that the key it names is the key ARCTIQ gave.
88
+
89
+ Each file is then sealed here with a key made for it alone (AES-256), and that key is wrapped
90
+ to the dataset's, which is two keys at once: RSA-3072 and ML-KEM-768 (post-quantum, FIPS 203).
91
+ Opening it takes both, so it stays sealed if either holds. ARCTIQ stores the file and can't open
92
+ it. The list of allowed images comes from ARCTIQ, so the image's PCR0 is printed for you to
93
+ compare with the published build.
94
+
95
+ It checks an AWS enclave's attestation against AWS Nitro Enclaves' root, which it carries; the
96
+ root itself is checked against the fingerprint AWS publishes. Against a local enclave stand-in,
97
+ which runs in ARCTIQ's own process and protects nothing from ARCTIQ, it seals only with
98
+ `--local-stand-in`. The `seal` extra adds `cryptography` 47 or later (Apache-2.0 or BSD; the
99
+ first with ML-KEM) and `cbor2` (MIT).
100
+
101
+ ## The terminal app
102
+
103
+ ```bash
104
+ pipx install "arctiq-cli[tui]"
105
+ arctiq tui
106
+ ```
107
+
108
+ Your repositories and their checks, an artefact beside the folder it comes from (upload what
109
+ changed, with progress), and your partners: what moves each way, every use, and who can see a
110
+ dataset. Keys `1` to `4`, `ctrl+p` for everything else. The `tui` extra adds Textual (MIT).
111
+
112
+ The command calls ARCTIQ's `/api/v1` only, and says so (`ARCTIQ-Client`). When an assistant runs
113
+ it, set `ARCTIQ_AGENT` (Claude Code is recognised on its own), and its changes show as made by an
114
+ agent on your behalf. Standard library only (the `tui` extra adds Textual); Python 3.10 or newer.
115
+
116
+ Licensed under the Apache License 2.0.
@@ -0,0 +1,90 @@
1
+ # arctiq-cli
2
+
3
+ The `arctiq` command: ARCTIQ from a terminal, for developers and the AI assistants working with them.
4
+
5
+ ```bash
6
+ pipx install arctiq-cli # or: uv tool install arctiq-cli
7
+ arctiq login
8
+ ```
9
+
10
+ The first `login` asks for your ARCTIQ address (or pass `--server`) and remembers it. It prints an
11
+ address and a code: open the address, enter the code and approve. The token is
12
+ kept in your system's keyring (install `arctiq-cli[keyring]`) or in a file only you can read.
13
+
14
+ ## Artefacts and files
15
+
16
+ ```bash
17
+ arctiq artefacts --repo my-org/my-repo
18
+ arctiq new --repo my-org/my-repo --problem "…" --domain "…" --approach "…"
19
+ arctiq upload paper.pdf data.csv --repo my-org/my-repo # each file is scanned on arrival
20
+ arctiq files | download NAME | remove NAME | submit | open # with --repo, and --artefact when there are several
21
+ ```
22
+
23
+ Inside a clone of a GitHub repository linked to ARCTIQ, `arctiq link` writes `.arctiq.yml` and the
24
+ commands need no `--repo`. `arctiq status` shows the repository's artefacts, the proposals waiting
25
+ for you and the last pull-request check; `arctiq pin TAG` keeps a tagged release as evidence.
26
+
27
+ ## Resources and Try it
28
+
29
+ ```bash
30
+ arctiq resources # code, data and documents; then partners'
31
+ arctiq resources show "syndrome records" # one, with its columns and files
32
+ arctiq resources sample field-run-magnetometer-records --csv sample.csv # made-up rows
33
+ arctiq resources add ./syndrome_2026_q4.parquet --level 3 # to ARCTIQ storage, in parts
34
+ arctiq resources add-version "syndrome records" ./syndrome_2026_q1.parquet # its next version
35
+ arctiq ask field-run-magnetometer-records --mean b_field_nt --by site
36
+ arctiq ask field-run-magnetometer-records --count --where site=Svalbard --where "day>=2026-03-01"
37
+ ```
38
+
39
+ `resources` is the repository's Resources tab: `--json` for scripts. `add` sends each file in
40
+ parts, sealed with your organisation's key as each arrives, then scanned; with no file it adds a
41
+ resource described only. `ask` asks a dataset a partner shares with this repository, under its
42
+ space's rules: noise and the privacy budget when the agreement has one, every question in both
43
+ sides' logs, and a refusal names the rule that refused it. `show` on a partner's dataset gives
44
+ its summary, with noise; `sample` prints a synthetic sample drawn from it (no row is real), and
45
+ `--csv FILE` saves it.
46
+
47
+ `add-version` sends files as the next version of one of your datasets. Each space that holds it
48
+ then waits for you to check it there.
49
+
50
+ ## Datasets sealed for enclaves
51
+
52
+ ```bash
53
+ pipx install "arctiq-cli[seal]"
54
+ arctiq resources add-version "syndrome records" ./syndrome_2026_q1.parquet
55
+ ```
56
+
57
+ A dataset sealed for enclaves takes only files sealed on your side. Before anything is sealed,
58
+ `add-version` checks the attestation the enclave made with the dataset's key:
59
+ - its signature, and its chain to a root this tool trusts;
60
+ - that the image it names is one the owner allows;
61
+ - that the key it names is the key ARCTIQ gave.
62
+
63
+ Each file is then sealed here with a key made for it alone (AES-256), and that key is wrapped
64
+ to the dataset's, which is two keys at once: RSA-3072 and ML-KEM-768 (post-quantum, FIPS 203).
65
+ Opening it takes both, so it stays sealed if either holds. ARCTIQ stores the file and can't open
66
+ it. The list of allowed images comes from ARCTIQ, so the image's PCR0 is printed for you to
67
+ compare with the published build.
68
+
69
+ It checks an AWS enclave's attestation against AWS Nitro Enclaves' root, which it carries; the
70
+ root itself is checked against the fingerprint AWS publishes. Against a local enclave stand-in,
71
+ which runs in ARCTIQ's own process and protects nothing from ARCTIQ, it seals only with
72
+ `--local-stand-in`. The `seal` extra adds `cryptography` 47 or later (Apache-2.0 or BSD; the
73
+ first with ML-KEM) and `cbor2` (MIT).
74
+
75
+ ## The terminal app
76
+
77
+ ```bash
78
+ pipx install "arctiq-cli[tui]"
79
+ arctiq tui
80
+ ```
81
+
82
+ Your repositories and their checks, an artefact beside the folder it comes from (upload what
83
+ changed, with progress), and your partners: what moves each way, every use, and who can see a
84
+ dataset. Keys `1` to `4`, `ctrl+p` for everything else. The `tui` extra adds Textual (MIT).
85
+
86
+ The command calls ARCTIQ's `/api/v1` only, and says so (`ARCTIQ-Client`). When an assistant runs
87
+ it, set `ARCTIQ_AGENT` (Claude Code is recognised on its own), and its changes show as made by an
88
+ agent on your behalf. Standard library only (the `tui` extra adds Textual); Python 3.10 or newer.
89
+
90
+ Licensed under the Apache License 2.0.
@@ -0,0 +1,57 @@
1
+ # ======================================================================
2
+ # arctiq-cli -- the `arctiq` command, published on PyPI (ADR 0025).
3
+ # ----------------------------------------------------------------------
4
+ # Its own small package, separate from the platform: standard library only,
5
+ # Apache-2.0, built and published by .github/workflows/cli-release.yml when a
6
+ # `cli-v<version>` tag is pushed. The version lives in src/arctiq_cli/__init__.py.
7
+ # ======================================================================
8
+
9
+ [build-system]
10
+ requires = ["setuptools>=77", "wheel"]
11
+ build-backend = "setuptools.build_meta"
12
+
13
+ [project]
14
+ name = "arctiq-cli"
15
+ dynamic = ["version"]
16
+ description = "The arctiq command: ARCTIQ from a terminal, for developers and their AI assistants."
17
+ readme = "README.md"
18
+ license = "Apache-2.0"
19
+ license-files = ["LICENSE"]
20
+ requires-python = ">=3.10"
21
+ authors = [{ name = "ARCTIQ" }]
22
+ keywords = ["arctiq", "cli", "research", "collaboration", "github"]
23
+ classifiers = [
24
+ "Environment :: Console",
25
+ "Intended Audience :: Developers",
26
+ "Intended Audience :: Science/Research",
27
+ "Operating System :: OS Independent",
28
+ "Programming Language :: Python :: 3",
29
+ "Programming Language :: Python :: 3 :: Only",
30
+ ]
31
+ dependencies = []
32
+
33
+ [project.optional-dependencies]
34
+ # Keep the token in the system's keyring instead of a file only you can read.
35
+ keyring = ["keyring>=24"]
36
+ # The terminal app, `arctiq tui` (ADR 0027). Textual is MIT-licensed.
37
+ tui = ["textual>=8.2,<9"]
38
+ # Sealing files for a dataset sealed for enclaves, on your side (ADR 0031, phase 4): the
39
+ # enclave key's attestation is checked first; files' keys are wrapped with RSA and ML-KEM
40
+ # (cryptography 47 is the first with ML-KEM). cryptography (Apache-2.0/BSD), cbor2 (MIT).
41
+ seal = ["cryptography>=47", "cbor2>=5.4"]
42
+
43
+ [project.scripts]
44
+ arctiq = "arctiq_cli.main:main"
45
+
46
+ [project.urls]
47
+ Homepage = "https://arctiq.xyz"
48
+
49
+ [tool.setuptools.dynamic]
50
+ version = { attr = "arctiq_cli.__version__" }
51
+
52
+ [tool.setuptools.packages.find]
53
+ where = ["src"]
54
+
55
+ [tool.setuptools.package-data]
56
+ # AWS Nitro Enclaves' root, to check an enclave key's attestation (`arctiq resources add-version`).
57
+ arctiq_cli = ["*.pem"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,9 @@
1
+ """The `arctiq` command: ARCTIQ from a terminal, for developers and their assistants (ADR 0025).
2
+
3
+ Standard library only. It signs in with the terminal sign-in (the device flow), keeps its token
4
+ in the system keyring when `keyring` is installed, else in a file only you can read, and calls
5
+ `/api/v1` only, saying what it is (`ARCTIQ-Client`) and, when an assistant drives it, which
6
+ (`ARCTIQ-Agent`), so its changes show "API" and "Agent" on the pages.
7
+ """
8
+
9
+ __version__ = "0.2.0"
@@ -0,0 +1,3 @@
1
+ from arctiq_cli.main import main
2
+
3
+ raise SystemExit(main())
@@ -0,0 +1,14 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIICETCCAZagAwIBAgIRAPkxdWgbkK/hHUbMtOTn+FYwCgYIKoZIzj0EAwMwSTEL
3
+ MAkGA1UEBhMCVVMxDzANBgNVBAoMBkFtYXpvbjEMMAoGA1UECwwDQVdTMRswGQYD
4
+ VQQDDBJhd3Mubml0cm8tZW5jbGF2ZXMwHhcNMTkxMDI4MTMyODA1WhcNNDkxMDI4
5
+ MTQyODA1WjBJMQswCQYDVQQGEwJVUzEPMA0GA1UECgwGQW1hem9uMQwwCgYDVQQL
6
+ DANBV1MxGzAZBgNVBAMMEmF3cy5uaXRyby1lbmNsYXZlczB2MBAGByqGSM49AgEG
7
+ BSuBBAAiA2IABPwCVOumCMHzaHDimtqQvkY4MpJzbolL//Zy2YlES1BR5TSksfbb
8
+ 48C8WBoyt7F2Bw7eEtaaP+ohG2bnUs990d0JX28TcPQXCEPZ3BABIeTPYwEoCWZE
9
+ h8l5YoQwTcU/9KNCMEAwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUkCW1DdkF
10
+ R+eWw5b6cp3PmanfS5YwDgYDVR0PAQH/BAQDAgGGMAoGCCqGSM49BAMDA2kAMGYC
11
+ MQCjfy+Rocm9Xue4YnwWmNJVA44fA0P5W2OpYow9OYCVRaEevL8uO1XYru5xtMPW
12
+ rfMCMQCi85sWBbJwKKXdS6BptQFuZbT73o/gBh1qUxl/nNr12UO8Yfwr6wPLb+6N
13
+ IwLz3/Y=
14
+ -----END CERTIFICATE-----
@@ -0,0 +1,156 @@
1
+ """Calls to `/api/v1`. The transport is a function, so tests can answer without a network."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import io
6
+ import json
7
+ import os
8
+ import secrets
9
+ import urllib.error
10
+ import urllib.request
11
+ from collections.abc import Callable
12
+ from dataclasses import dataclass, field
13
+ from urllib.parse import quote
14
+
15
+ from arctiq_cli import __version__
16
+
17
+
18
+ class Reading:
19
+ """A request body sent in blocks, telling `progress` (bytes sent, of total) as it goes. What
20
+ lets the TUI draw an upload's progress; the plain CLI sends bytes."""
21
+
22
+ def __init__(self, data: bytes, progress: Callable[[int, int], None]) -> None:
23
+ self._data, self.progress, self.total, self.sent = io.BytesIO(data), progress, len(data), 0
24
+
25
+ def read(self, size: int = -1) -> bytes:
26
+ block = self._data.read(size if size and size > 0 else 64 * 1024)
27
+ self.sent += len(block)
28
+ self.progress(self.sent, self.total)
29
+ return block
30
+
31
+ def getvalue(self) -> bytes:
32
+ return self._data.getvalue()
33
+
34
+
35
+ #: (method, url, headers, body) -> (status, body)
36
+ Transport = Callable[[str, str, dict[str, str], "bytes | Reading | None"], tuple[int, bytes]]
37
+ TIMEOUT = 300 # pinning keeps a copy of a release, and uploads can be large: give them time
38
+
39
+
40
+ def urllib_transport(
41
+ method: str, url: str, headers: dict[str, str], body: bytes | Reading | None
42
+ ) -> tuple[int, bytes]:
43
+ if not url.startswith(("https://", "http://localhost", "http://127.0.0.1")):
44
+ raise ApiError(0, "The server must be https (or localhost).")
45
+ if isinstance(body, Reading): # sent in blocks; its length is known, so no chunking
46
+ headers = {**headers, "Content-Length": str(body.total)}
47
+ request = urllib.request.Request(url, data=body, headers=headers, method=method) # noqa: S310
48
+ try:
49
+ with urllib.request.urlopen(request, timeout=TIMEOUT) as answer: # noqa: S310
50
+ return answer.status, answer.read()
51
+ except urllib.error.HTTPError as exc:
52
+ return exc.code, exc.read()
53
+ except (urllib.error.URLError, TimeoutError) as exc:
54
+ raise ApiError(0, f"Could not reach {url.split('/api/')[0]}: {exc}") from None
55
+
56
+
57
+ def agent() -> str | None:
58
+ """The assistant driving this command, as it declares itself: `ARCTIQ_AGENT`, or Claude
59
+ Code's own marker. Recorded as declared, never as proof (ADR 0023)."""
60
+ named = os.environ.get("ARCTIQ_AGENT", "").strip()
61
+ if named:
62
+ return named[:100]
63
+ if os.environ.get("CLAUDECODE") == "1":
64
+ return "claude-code"
65
+ return None
66
+
67
+
68
+ class ApiError(Exception):
69
+ def __init__(self, status: int, detail: str, error: str | None = None) -> None:
70
+ super().__init__(detail)
71
+ self.status, self.detail, self.error = status, detail, error
72
+
73
+
74
+ @dataclass
75
+ class Api:
76
+ server: str
77
+ token: str | None = None
78
+ transport: Transport = field(default=urllib_transport)
79
+
80
+ def _headers(self, content_type: str | None) -> dict[str, str]:
81
+ headers = {"Accept": "application/json", "ARCTIQ-Client": f"arctiq-cli/{__version__}"}
82
+ if content_type:
83
+ headers["Content-Type"] = content_type
84
+ if self.token:
85
+ headers["Authorization"] = f"Bearer {self.token}"
86
+ if (who := agent()) is not None:
87
+ headers["ARCTIQ-Agent"] = who
88
+ return headers
89
+
90
+ def _send(
91
+ self, method: str, path: str, body: bytes | Reading | None, content_type: str | None
92
+ ) -> tuple[int, bytes]:
93
+ url = f"{self.server.rstrip('/')}/api/v1{path}"
94
+ status, raw = self.transport(method, url, self._headers(content_type), body)
95
+ if status >= 400:
96
+ try:
97
+ data = json.loads(raw) if raw else None
98
+ except ValueError:
99
+ data = None
100
+ detail = data.get("detail") if isinstance(data, dict) else None
101
+ error = data.get("error") if isinstance(data, dict) else None
102
+ if isinstance(detail, list): # FastAPI's validation errors
103
+ detail = "; ".join(str(d.get("msg", d)) for d in detail)
104
+ raise ApiError(status, str(detail or error or f"The server answered {status}."), error)
105
+ return status, raw
106
+
107
+ def call(self, method: str, path: str, payload: dict | None = None) -> object:
108
+ body = json.dumps(payload).encode() if payload is not None else None
109
+ _, raw = self._send(method, path, body, "application/json" if body is not None else None)
110
+ try:
111
+ return json.loads(raw) if raw else None
112
+ except ValueError:
113
+ return None
114
+
115
+ def upload(
116
+ self,
117
+ path: str,
118
+ filename: str,
119
+ data: bytes,
120
+ progress: Callable[[int, int], None] | None = None,
121
+ ) -> object:
122
+ """POST one file as `multipart/form-data`, field `file`. The server decides its type.
123
+ With `progress`, it is told (bytes sent, of total) as the body goes out."""
124
+ boundary = f"arctiq-{secrets.token_hex(16)}"
125
+ name = "".join("_" if ch in '"\\\r\n' else ch for ch in filename)
126
+ head = (
127
+ f"--{boundary}\r\n"
128
+ f'Content-Disposition: form-data; name="file"; filename="{name}"\r\n'
129
+ "Content-Type: application/octet-stream\r\n\r\n"
130
+ ).encode()
131
+ body = head + data + f"\r\n--{boundary}--\r\n".encode()
132
+ sent: bytes | Reading = body if progress is None else Reading(body, progress)
133
+ _, raw = self._send("POST", path, sent, f"multipart/form-data; boundary={boundary}")
134
+ return json.loads(raw) if raw else None
135
+
136
+ def download(self, path: str) -> bytes:
137
+ return self._send("GET", path, None, None)[1]
138
+
139
+ def get(self, path: str) -> object:
140
+ return self.call("GET", path)
141
+
142
+ def post(self, path: str, payload: dict) -> object:
143
+ return self.call("POST", path, payload)
144
+
145
+ def delete(self, path: str) -> object:
146
+ return self.call("DELETE", path)
147
+
148
+ def put_bytes(self, path: str, data: bytes) -> object:
149
+ """PUT raw bytes: one part of a file sent in parts."""
150
+ _, raw = self._send("PUT", path, data, "application/octet-stream")
151
+ return json.loads(raw) if raw else None
152
+
153
+
154
+ def part(value: str) -> str:
155
+ """One path segment, escaped."""
156
+ return quote(value, safe="")