arctiq-cli 0.2.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.
- arctiq_cli/__init__.py +9 -0
- arctiq_cli/__main__.py +3 -0
- arctiq_cli/aws_nitro_root_g1.pem +14 -0
- arctiq_cli/client.py +156 -0
- arctiq_cli/credentials.py +109 -0
- arctiq_cli/main.py +1068 -0
- arctiq_cli/project.py +100 -0
- arctiq_cli/seal.py +217 -0
- arctiq_cli/tui/__init__.py +19 -0
- arctiq_cli/tui/app.py +1208 -0
- arctiq_cli/tui/draw.py +307 -0
- arctiq_cli/tui/folder.py +148 -0
- arctiq_cli/tui/source.py +98 -0
- arctiq_cli-0.2.0.dist-info/METADATA +116 -0
- arctiq_cli-0.2.0.dist-info/RECORD +19 -0
- arctiq_cli-0.2.0.dist-info/WHEEL +5 -0
- arctiq_cli-0.2.0.dist-info/entry_points.txt +2 -0
- arctiq_cli-0.2.0.dist-info/licenses/LICENSE +202 -0
- arctiq_cli-0.2.0.dist-info/top_level.txt +1 -0
arctiq_cli/tui/draw.py
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
"""The TUI's drawings, as Rich text: bars, the level ladder, the partners' flow, a partnership's
|
|
2
|
+
timeline (docs/ui-mockups/tui). Pure functions over the API's JSON, so they are tested without a
|
|
3
|
+
terminal."""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import datetime as dt
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
from rich.text import Text
|
|
11
|
+
|
|
12
|
+
INK, INK2, MUTE, LINE = "#e6e6e3", "#a3a39f", "#6e6e6a", "#3a3a38"
|
|
13
|
+
ACC, RED, OK, AMBER = "#6b9bff", "#ff6b6b", "#4cc46a", "#e0a536"
|
|
14
|
+
LEVEL = {1: "See it exists", 2: "See its shape", 3: "Try it", 4: "Use it", 5: "Build on it"}
|
|
15
|
+
#: The ladder's top step: no data is ever downloaded, so nothing above it (ADR 0031).
|
|
16
|
+
TOP = max(LEVEL)
|
|
17
|
+
SHORT = {2: "Shape", 3: "Try it", 4: "Use it"}
|
|
18
|
+
#: Line weight in the flow, and bar height in the timeline, by step.
|
|
19
|
+
GLYPH = {2: "─", 3: "━", 4: "█"}
|
|
20
|
+
HEIGHT = {2: "▄", 3: "▆", 4: "█"}
|
|
21
|
+
LIVE = ("active", "ending")
|
|
22
|
+
SIGNING = ("agreeing", "your_signature", "their_signature")
|
|
23
|
+
MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def T(*parts: str | tuple[str, str] | Text) -> Text:
|
|
27
|
+
out = Text()
|
|
28
|
+
for p in parts:
|
|
29
|
+
if isinstance(p, Text):
|
|
30
|
+
out.append(p)
|
|
31
|
+
elif isinstance(p, tuple):
|
|
32
|
+
out.append(p[0], style=p[1])
|
|
33
|
+
else:
|
|
34
|
+
out.append(p)
|
|
35
|
+
return out
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def clip(text: str, most: int) -> str:
|
|
39
|
+
"""`text`, cut to `most` characters with an ellipsis when it is longer."""
|
|
40
|
+
return text if len(text) <= most else text[: most - 1].rstrip() + "…"
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def lines(*rows: Text | str) -> Text:
|
|
44
|
+
out = Text()
|
|
45
|
+
for i, r in enumerate(rows):
|
|
46
|
+
if i:
|
|
47
|
+
out.append("\n")
|
|
48
|
+
out.append(r if isinstance(r, Text) else Text(r))
|
|
49
|
+
return out
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def when(value: str | None) -> dt.datetime | None:
|
|
53
|
+
"""An API timestamp (`…Z` or with an offset) as an aware datetime."""
|
|
54
|
+
if not value:
|
|
55
|
+
return None
|
|
56
|
+
return dt.datetime.fromisoformat(value.replace("Z", "+00:00"))
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def day(value: str | None) -> dt.date | None:
|
|
60
|
+
if not value:
|
|
61
|
+
return None
|
|
62
|
+
return dt.date.fromisoformat(value[:10])
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def short(d: dt.date | dt.datetime | None, year: bool = False) -> str:
|
|
66
|
+
if d is None:
|
|
67
|
+
return ""
|
|
68
|
+
return f"{d.day} {MONTHS[d.month - 1]}" + (f" {d.year}" if year else "")
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def size(n: int | None) -> str:
|
|
72
|
+
if n is None:
|
|
73
|
+
return ""
|
|
74
|
+
for unit in ("bytes", "KB", "MB", "GB"):
|
|
75
|
+
if n < 1024 or unit == "GB":
|
|
76
|
+
return f"{n} {unit}" if unit == "bytes" else f"{n:.1f} {unit}"
|
|
77
|
+
n = n / 1024 # type: ignore[assignment]
|
|
78
|
+
return ""
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
# ---------------------------------------------------------------------- small pieces
|
|
82
|
+
def bar(n: int, width: int = 24) -> Text:
|
|
83
|
+
full = max(0, min(width, round(n / 100 * width)))
|
|
84
|
+
return T(("━" * full, INK), ("━" * (width - full), LINE), (f" {n:>3}", f"bold {INK}"))
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def ladder(step: int, offered: int = TOP, wide: bool = True) -> Text:
|
|
88
|
+
"""A segment per step, the first `step` lit, but never past `offered`: squares (`wide`) or
|
|
89
|
+
thin lines. Unlit segments up to `offered` are grey; past it, darker."""
|
|
90
|
+
out = Text()
|
|
91
|
+
for i in range(1, TOP + 1):
|
|
92
|
+
lit = i <= min(step, offered)
|
|
93
|
+
if wide:
|
|
94
|
+
out.append(" ", style=f"on {INK if lit else (LINE if i <= offered else '#222221')}")
|
|
95
|
+
else:
|
|
96
|
+
out.append("━━", style=f"bold {INK}" if lit else (LINE if i <= offered else "#222221"))
|
|
97
|
+
out.append(" " if i < 6 else "")
|
|
98
|
+
return out
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def level(step: int | None) -> str:
|
|
102
|
+
return f"{step} · {LEVEL[step]}" if step in LEVEL else "–"
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
# ---------------------------------------------------------------------- the partners' flow
|
|
106
|
+
def _arrow_in(step: int, colour: str, dashed: bool) -> Text:
|
|
107
|
+
return T((" ", ""), (("┅" if dashed else GLYPH.get(step, "─")) * 7, colour), ("▶ ", colour))
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _arrow_out(step: int, colour: str, dashed: bool) -> Text:
|
|
111
|
+
return T((" ◀", colour), (("┅" if dashed else GLYPH.get(step, "─")) * 7, colour), (" ", ""))
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def flow(parts: list[dict[str, Any]]) -> Text:
|
|
115
|
+
"""Each agreement as a box: what you share flows in from the left, theirs from the right.
|
|
116
|
+
Line weight is the level; dashed while not signed by both; red when ending soon. Ended ones,
|
|
117
|
+
and ones nothing is shared on, are listed under."""
|
|
118
|
+
w_name, w_lv, w_box = 26, 19, 32
|
|
119
|
+
out = T((f"{'YOU SHARE':<{w_name + w_lv + 10}}", f"bold {INK2}"),
|
|
120
|
+
(f"{'PARTNER':<{w_box + 10}}", f"bold {INK2}"), ("THEY SHARE", f"bold {INK2}")) # fmt: skip
|
|
121
|
+
out.append("\n\n")
|
|
122
|
+
drawn = [p for p in parts if p["state"] in LIVE + SIGNING]
|
|
123
|
+
for p in drawn:
|
|
124
|
+
live = p["state"] in LIVE
|
|
125
|
+
red = p["state"] == "ending"
|
|
126
|
+
dashed = not live
|
|
127
|
+
colour = RED if red else (INK if live else INK2)
|
|
128
|
+
mine = [r for r in p["you_share"] if r["live"] or not live]
|
|
129
|
+
theirs = [r for r in p["they_share"] if r["live"] or not live]
|
|
130
|
+
h, v = ("┄", "┆") if dashed else ("─", "│")
|
|
131
|
+
if red and p.get("days_left") is not None:
|
|
132
|
+
sub = f"ends {short(day(p['ends_on']))} · {p['days_left']} days"
|
|
133
|
+
elif live:
|
|
134
|
+
sub = f"until {short(day(p['ends_on']), True)}" if p.get("ends_on") else "no end date"
|
|
135
|
+
else:
|
|
136
|
+
sub = p["label"].lower()
|
|
137
|
+
name = p["partner"][: w_box - 4]
|
|
138
|
+
box = [
|
|
139
|
+
T(("┌" + h * (w_box - 2) + "┐", colour)),
|
|
140
|
+
T((v + " ", colour), (f"{name:<{w_box - 4}}", f"bold {INK}"), (" " + v, colour)),
|
|
141
|
+
T(
|
|
142
|
+
(v + " ", colour),
|
|
143
|
+
(f"{sub[: w_box - 4]:<{w_box - 4}}", RED if red else INK2),
|
|
144
|
+
(" " + v, colour),
|
|
145
|
+
), # fmt: skip
|
|
146
|
+
T(("└" + h * (w_box - 2) + "┘", colour)),
|
|
147
|
+
]
|
|
148
|
+
rows = max(4, 2 + max(len(mine), len(theirs)))
|
|
149
|
+
for i in range(rows):
|
|
150
|
+
row = Text()
|
|
151
|
+
k = i - 1
|
|
152
|
+
if 0 <= k < len(mine):
|
|
153
|
+
r = mine[k]
|
|
154
|
+
row.append(T((f"{clip(r['name'], w_name - 2):<{w_name}}", INK),
|
|
155
|
+
(f"{r['step']} · {LEVEL[r['step']]:<{w_lv - 4}}", INK2))) # fmt: skip
|
|
156
|
+
row.append(_arrow_in(r["step"], colour, dashed))
|
|
157
|
+
elif k == 0 and not mine:
|
|
158
|
+
row.append(T((f"{'nothing of yours':<{w_name + w_lv}}", MUTE), (" " * 10, "")))
|
|
159
|
+
else:
|
|
160
|
+
row.append(" " * (w_name + w_lv + 10))
|
|
161
|
+
row.append(box[i] if i < 4 else Text(" " * w_box))
|
|
162
|
+
if 0 <= k < len(theirs):
|
|
163
|
+
r = theirs[k]
|
|
164
|
+
row.append(_arrow_out(r["step"], colour, dashed))
|
|
165
|
+
row.append(
|
|
166
|
+
T((f"{r['step']} · {LEVEL[r['step']]:<{w_lv - 4}}", INK2), (r["name"], INK))
|
|
167
|
+
)
|
|
168
|
+
out.append(row)
|
|
169
|
+
out.append("\n")
|
|
170
|
+
out.append("\n")
|
|
171
|
+
pad = " " * (w_name + w_lv + 10)
|
|
172
|
+
for p in parts:
|
|
173
|
+
if p["state"] == "ended":
|
|
174
|
+
out.append(T((pad, ""), ("· ", MUTE), (p["partner"] + " ", INK2),
|
|
175
|
+
(f"ended {short(day(p.get('ended_on')), True)} · {p['title']}", MUTE))) # fmt: skip
|
|
176
|
+
out.append("\n")
|
|
177
|
+
if not parts:
|
|
178
|
+
out.append(T(("No agreements yet. Find someone to work with in Discover.", MUTE)))
|
|
179
|
+
out.append("\n")
|
|
180
|
+
out.append("\n")
|
|
181
|
+
out.append(T(("Line weight is the level: ", MUTE), ("── 2 See its shape ", INK2),
|
|
182
|
+
("━━ 3 Try it ", INK2), ("██ 4 Use it ", INK2), ("┅┅ not signed by both ", INK2),
|
|
183
|
+
("red", RED), (" ends within 60 days", INK2))) # fmt: skip
|
|
184
|
+
return out
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
# ---------------------------------------------------------------------- a partnership's timeline
|
|
188
|
+
def _months_between(first: dt.date, last: dt.date) -> int:
|
|
189
|
+
return (last.year - first.year) * 12 + last.month - first.month
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def gantt(p: dict[str, Any], today: dt.date, label_w: int = 40, cpm: int = 5) -> Text:
|
|
193
|
+
"""One bar per shared resource from the day it started to the agreement's end, grouped by
|
|
194
|
+
side. Bar height is the level; dim after today; ◆ marks the first and the latest question."""
|
|
195
|
+
resources = [("YOU SHARE", p["you_share"]), (f"{p['partner'].upper()} SHARES", p["they_share"])]
|
|
196
|
+
if not p["you_share"] and not p["they_share"]:
|
|
197
|
+
return T(("Nothing is shared either way in this agreement.", MUTE))
|
|
198
|
+
begin = (
|
|
199
|
+
when(p.get("proposed_at")) or when(p.get("signed_at")) or dt.datetime.now(dt.UTC)
|
|
200
|
+
).date()
|
|
201
|
+
ends = [day(r.get("ends_on")) for _, rs in resources for r in rs] + [day(p.get("ends_on"))]
|
|
202
|
+
finish = max([d for d in ends if d] + [today + dt.timedelta(days=30)])
|
|
203
|
+
first = dt.date(min(begin, today).year, min(begin, today).month, 1)
|
|
204
|
+
months = _months_between(first, finish) + 1
|
|
205
|
+
width = months * cpm
|
|
206
|
+
|
|
207
|
+
def col(d: dt.date | None) -> int | None:
|
|
208
|
+
if d is None:
|
|
209
|
+
return None
|
|
210
|
+
return max(
|
|
211
|
+
0, min(width - 1, _months_between(first, d) * cpm + round((d.day - 1) / 31 * cpm))
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
today_c = col(today)
|
|
215
|
+
end_c = col(day(p.get("ends_on"))) if p["state"] != "ended" else None
|
|
216
|
+
out = Text()
|
|
217
|
+
words = []
|
|
218
|
+
if p.get("proposed_at"):
|
|
219
|
+
words.append(f"proposed {short(when(p['proposed_at']))}")
|
|
220
|
+
if p.get("signed_at"):
|
|
221
|
+
words.append(f"signed {short(when(p['signed_at']), True)}")
|
|
222
|
+
if p["state"] == "ended" and p.get("ended_on"):
|
|
223
|
+
words.append(f"ended {short(day(p['ended_on']), True)}")
|
|
224
|
+
out.append(T((" " * label_w, ""), ("● " + " · ".join(words) if words else "", INK)))
|
|
225
|
+
out.append("\n")
|
|
226
|
+
# "▼ today" starts at today; "ends ┐" stops at the end. When they would meet (an end within
|
|
227
|
+
# a month or so), the second goes on a line of its own.
|
|
228
|
+
rows_of_marks: list[list[str]] = []
|
|
229
|
+
for c, text in ((today_c, "▼ today"), (end_c, "ends ┐")):
|
|
230
|
+
if c is None:
|
|
231
|
+
continue
|
|
232
|
+
start = c if text.startswith("▼") else max(0, c - len(text) + 1)
|
|
233
|
+
span = range(start, min(width, start + len(text) + 1))
|
|
234
|
+
row = next((r for r in rows_of_marks if all(r[i] == " " for i in span)), None)
|
|
235
|
+
if row is None:
|
|
236
|
+
row = [" "] * width
|
|
237
|
+
rows_of_marks.append(row)
|
|
238
|
+
for i, ch in enumerate(text):
|
|
239
|
+
if start + i < width:
|
|
240
|
+
row[start + i] = ch
|
|
241
|
+
for row in rows_of_marks:
|
|
242
|
+
out.append(T((" " * label_w, ""), ("".join(row), ACC)))
|
|
243
|
+
out.append("\n")
|
|
244
|
+
for head, rs in resources:
|
|
245
|
+
if not rs:
|
|
246
|
+
continue
|
|
247
|
+
out.append(T((f"{head[:label_w]:<{label_w}}", f"bold {INK2}")))
|
|
248
|
+
out.append("\n")
|
|
249
|
+
for r in rs:
|
|
250
|
+
step = r["step"]
|
|
251
|
+
out.append(T((f" {clip(r['name'], label_w - 12):<{label_w - 10}}", INK),
|
|
252
|
+
(f"{step} ", f"bold {INK}"), (f"{SHORT.get(step, ''):<7}", INK2))) # fmt: skip
|
|
253
|
+
s = col(day(r.get("starts_on")) or begin) or 0
|
|
254
|
+
e = col(day(r.get("ends_on"))) or (width - 1)
|
|
255
|
+
if p["state"] == "ended" and p.get("ended_on"):
|
|
256
|
+
e = min(e, col(day(p["ended_on"])) or e)
|
|
257
|
+
marks = {}
|
|
258
|
+
for key in ("first_asked", "last_asked"):
|
|
259
|
+
at = when(r.get(key))
|
|
260
|
+
if at is not None:
|
|
261
|
+
marks[col(at.date())] = INK
|
|
262
|
+
line = Text()
|
|
263
|
+
for c in range(width):
|
|
264
|
+
glyph = HEIGHT.get(step, "▄")
|
|
265
|
+
if c in marks:
|
|
266
|
+
line.append("◆", style=f"bold {marks[c]}")
|
|
267
|
+
elif c == end_c:
|
|
268
|
+
line.append("┆", style=INK)
|
|
269
|
+
elif c < s or c > e:
|
|
270
|
+
line.append("│" if c == today_c else " ", style=ACC)
|
|
271
|
+
elif today_c is not None and c < today_c and (r["live"] or p["state"] == "ended"):
|
|
272
|
+
line.append(glyph, style=INK)
|
|
273
|
+
elif c == today_c:
|
|
274
|
+
line.append(glyph, style=ACC)
|
|
275
|
+
else:
|
|
276
|
+
line.append(glyph, style=LINE)
|
|
277
|
+
out.append(line)
|
|
278
|
+
out.append("\n")
|
|
279
|
+
axis = Text(" " * label_w)
|
|
280
|
+
years = Text(" " * label_w)
|
|
281
|
+
for i in range(months):
|
|
282
|
+
m = (first.month - 1 + i) % 12
|
|
283
|
+
axis.append(f"{MONTHS[m]:<{cpm}}", style=INK2)
|
|
284
|
+
yr = first.year + (first.month - 1 + i) // 12
|
|
285
|
+
years.append(f"{yr:<{cpm}}" if (i == 0 or m == 0) else " " * cpm, style=MUTE)
|
|
286
|
+
out.append(axis)
|
|
287
|
+
out.append("\n")
|
|
288
|
+
out.append(years)
|
|
289
|
+
out.append("\n\n")
|
|
290
|
+
out.append(T(("bar height is the level ▄ 2 ▆ 3 █ 4 · ", MUTE), ("◆", INK),
|
|
291
|
+
(" first and latest question · dim: still ahead", MUTE))) # fmt: skip
|
|
292
|
+
return out
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def per_day(uses: list[dict[str, Any]], today: dt.date, days: int = 30) -> list[int]:
|
|
296
|
+
"""Questions asked each day, the last `days` days, oldest first."""
|
|
297
|
+
counts = [0] * days
|
|
298
|
+
for u in uses:
|
|
299
|
+
if not str(u.get("did", "")).startswith("Asked"):
|
|
300
|
+
continue
|
|
301
|
+
at = when(u.get("at"))
|
|
302
|
+
if at is None:
|
|
303
|
+
continue
|
|
304
|
+
back = (today - at.date()).days
|
|
305
|
+
if 0 <= back < days:
|
|
306
|
+
counts[days - 1 - back] += 1
|
|
307
|
+
return counts
|
arctiq_cli/tui/folder.py
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"""The linked folder beside an artefact: which of its files the artefact holds, and whether each
|
|
2
|
+
is the same or changed (ADR 0027).
|
|
3
|
+
|
|
4
|
+
An artefact's files are kept by name, not path (`arctiq upload` sends a file's name), so a local
|
|
5
|
+
file belongs to the artefact when its name is one of the artefact's file names; same or changed is
|
|
6
|
+
decided by SHA-256. Two local files with one name are a clash: which one the artefact holds can't
|
|
7
|
+
be told, so neither is uploaded. Other files are listed, not marked: nothing new is added unless
|
|
8
|
+
the person picks it.
|
|
9
|
+
|
|
10
|
+
Which files: `git ls-files` (tracked, and untracked ones git doesn't ignore) in a git folder,
|
|
11
|
+
else a walk that skips the usual tool folders; then `.arctiqignore` (one glob per line, matched
|
|
12
|
+
against the path and against the name).
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import fnmatch
|
|
18
|
+
import hashlib
|
|
19
|
+
import subprocess
|
|
20
|
+
from dataclasses import dataclass
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
from typing import Any
|
|
23
|
+
|
|
24
|
+
SKIPPED = {
|
|
25
|
+
".git", ".hg", ".svn", "__pycache__", "node_modules", ".venv", "venv", ".mypy_cache",
|
|
26
|
+
".pytest_cache", ".ruff_cache", ".tox", ".idea", ".vscode", "dist", "build",
|
|
27
|
+
} # fmt: skip
|
|
28
|
+
MOST = 5000
|
|
29
|
+
IGNORE_FILE = ".arctiqignore"
|
|
30
|
+
|
|
31
|
+
SAME, CHANGED, NEW, CLASH, MISSING, OTHER = "same", "changed", "new", "clash", "missing", "other"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclass(frozen=True)
|
|
35
|
+
class Entry:
|
|
36
|
+
#: The path in the folder (posix), or for a file only the artefact has, its name.
|
|
37
|
+
path: str
|
|
38
|
+
state: str
|
|
39
|
+
size: int | None = None
|
|
40
|
+
stored: dict[str, Any] | None = None
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
def name(self) -> str:
|
|
44
|
+
return self.path.rsplit("/", 1)[-1]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _ignored(folder: Path) -> list[str]:
|
|
48
|
+
try:
|
|
49
|
+
text = (folder / IGNORE_FILE).read_text(encoding="utf-8")
|
|
50
|
+
except OSError:
|
|
51
|
+
return []
|
|
52
|
+
return [line.strip() for line in text.splitlines() if line.strip() and not line.startswith("#")]
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _git(folder: Path) -> list[str] | None:
|
|
56
|
+
try:
|
|
57
|
+
done = subprocess.run( # noqa: S603 - fixed arguments, no shell
|
|
58
|
+
["git", "ls-files", "-z", "--cached", "--others", "--exclude-standard"], # noqa: S607
|
|
59
|
+
cwd=folder, capture_output=True, timeout=20, check=False,
|
|
60
|
+
) # fmt: skip
|
|
61
|
+
except (OSError, subprocess.SubprocessError):
|
|
62
|
+
return None
|
|
63
|
+
if done.returncode != 0:
|
|
64
|
+
return None
|
|
65
|
+
return [p for p in done.stdout.decode("utf-8", "replace").split("\0") if p]
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _walk(folder: Path) -> list[str]:
|
|
69
|
+
out: list[str] = []
|
|
70
|
+
for path in sorted(folder.rglob("*")):
|
|
71
|
+
rel = path.relative_to(folder)
|
|
72
|
+
if any(part in SKIPPED or part.startswith(".") for part in rel.parts[:-1]):
|
|
73
|
+
continue
|
|
74
|
+
if path.is_file():
|
|
75
|
+
out.append(rel.as_posix())
|
|
76
|
+
if len(out) >= MOST:
|
|
77
|
+
break
|
|
78
|
+
return out
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def local_files(folder: Path) -> list[str]:
|
|
82
|
+
"""The folder's files, as posix paths relative to it, at most `MOST`."""
|
|
83
|
+
found = _git(folder)
|
|
84
|
+
paths = found if found is not None else _walk(folder)
|
|
85
|
+
patterns = _ignored(folder)
|
|
86
|
+
kept = [
|
|
87
|
+
p
|
|
88
|
+
for p in paths
|
|
89
|
+
if not any(
|
|
90
|
+
fnmatch.fnmatch(p, g) or fnmatch.fnmatch(p.rsplit("/", 1)[-1], g) for g in patterns
|
|
91
|
+
)
|
|
92
|
+
and p != IGNORE_FILE
|
|
93
|
+
]
|
|
94
|
+
return sorted(kept)[:MOST]
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def sha256_of(path: Path) -> str:
|
|
98
|
+
digest = hashlib.sha256()
|
|
99
|
+
with path.open("rb") as handle:
|
|
100
|
+
for block in iter(lambda: handle.read(1024 * 1024), b""):
|
|
101
|
+
digest.update(block)
|
|
102
|
+
return digest.hexdigest()
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def compare(
|
|
106
|
+
folder: Path, stored: list[dict[str, Any]], chosen: set[str] | None = None
|
|
107
|
+
) -> list[Entry]:
|
|
108
|
+
"""Every local file with its state, then the artefact's files missing from the folder.
|
|
109
|
+
|
|
110
|
+
`chosen` are local paths the person picked to add: they are `new` unless the artefact already
|
|
111
|
+
has a file of that name."""
|
|
112
|
+
chosen = chosen or set()
|
|
113
|
+
by_name = {f["filename"]: f for f in stored}
|
|
114
|
+
paths = local_files(folder)
|
|
115
|
+
counts: dict[str, int] = {}
|
|
116
|
+
for p in paths:
|
|
117
|
+
name = p.rsplit("/", 1)[-1]
|
|
118
|
+
counts[name] = counts.get(name, 0) + 1
|
|
119
|
+
out: list[Entry] = []
|
|
120
|
+
seen: set[str] = set()
|
|
121
|
+
for p in paths:
|
|
122
|
+
name = p.rsplit("/", 1)[-1]
|
|
123
|
+
full = folder / p
|
|
124
|
+
try:
|
|
125
|
+
size = full.stat().st_size
|
|
126
|
+
except OSError:
|
|
127
|
+
continue
|
|
128
|
+
held = by_name.get(name)
|
|
129
|
+
if held is not None:
|
|
130
|
+
seen.add(name)
|
|
131
|
+
if counts[name] > 1:
|
|
132
|
+
out.append(Entry(p, CLASH, size, held))
|
|
133
|
+
else:
|
|
134
|
+
same = sha256_of(full) == held.get("sha256")
|
|
135
|
+
out.append(Entry(p, SAME if same else CHANGED, size, held))
|
|
136
|
+
elif p in chosen and counts[name] == 1:
|
|
137
|
+
out.append(Entry(p, NEW, size))
|
|
138
|
+
else:
|
|
139
|
+
out.append(Entry(p, OTHER, size))
|
|
140
|
+
for name, held in sorted(by_name.items()):
|
|
141
|
+
if name not in seen:
|
|
142
|
+
out.append(Entry(name, MISSING, held.get("size_bytes"), held))
|
|
143
|
+
return out
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def to_send(entries: list[Entry]) -> list[Entry]:
|
|
147
|
+
"""What "upload" sends: changed files and the ones picked to add."""
|
|
148
|
+
return [e for e in entries if e.state in (CHANGED, NEW)]
|
arctiq_cli/tui/source.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"""What the TUI reads and does: `/api/v1` only, with the person's token (ADR 0027).
|
|
2
|
+
|
|
3
|
+
One method per address, returning the API's JSON as it comes, so the screens show exactly what
|
|
4
|
+
the pages show the same person. Nothing here reads a database or keeps anything.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from collections.abc import Callable
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
from arctiq_cli.client import Api, part
|
|
13
|
+
|
|
14
|
+
JSON = dict[str, Any]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Source:
|
|
18
|
+
def __init__(self, api: Api, org: str) -> None:
|
|
19
|
+
self.api, self.org = api, org
|
|
20
|
+
|
|
21
|
+
# ------------------------------------------------------------------ addresses
|
|
22
|
+
def _o(self, path: str) -> str:
|
|
23
|
+
return f"/orgs/{part(self.org)}{path}"
|
|
24
|
+
|
|
25
|
+
def _repo(self, slug: str, path: str = "") -> str:
|
|
26
|
+
return self._o(f"/repos/{part(slug)}{path}")
|
|
27
|
+
|
|
28
|
+
def _list(self, path: str) -> list[JSON]:
|
|
29
|
+
found = self.api.get(path)
|
|
30
|
+
return found if isinstance(found, list) else []
|
|
31
|
+
|
|
32
|
+
def _one(self, path: str) -> JSON:
|
|
33
|
+
found = self.api.get(path)
|
|
34
|
+
return found if isinstance(found, dict) else {}
|
|
35
|
+
|
|
36
|
+
def web(self, path: str = "") -> str:
|
|
37
|
+
"""The page for `path` in this organisation, on the server signed in to."""
|
|
38
|
+
return f"{self.api.server.rstrip('/')}/o/{part(self.org)}/ui/{path.lstrip('/')}"
|
|
39
|
+
|
|
40
|
+
# ------------------------------------------------------------------ who and where
|
|
41
|
+
def me(self) -> JSON:
|
|
42
|
+
return self._one("/me")
|
|
43
|
+
|
|
44
|
+
def organisations(self) -> list[JSON]:
|
|
45
|
+
return self._list("/orgs")
|
|
46
|
+
|
|
47
|
+
def repositories(self) -> list[JSON]:
|
|
48
|
+
return self._list(self._o("/repos"))
|
|
49
|
+
|
|
50
|
+
def status(self, slug: str) -> JSON:
|
|
51
|
+
return self._one(self._repo(slug, "/status"))
|
|
52
|
+
|
|
53
|
+
# ------------------------------------------------------------------ artefacts and files
|
|
54
|
+
def artefacts(self, slug: str) -> list[JSON]:
|
|
55
|
+
return self._list(self._repo(slug, "/artefacts?limit=200"))
|
|
56
|
+
|
|
57
|
+
def files(self, slug: str, artefact: str) -> list[JSON]:
|
|
58
|
+
return self._list(self._repo(slug, f"/artefacts/{part(artefact)}/files"))
|
|
59
|
+
|
|
60
|
+
def summary(self, slug: str, artefact: str) -> JSON:
|
|
61
|
+
return self._one(self._repo(slug, f"/artefacts/{part(artefact)}/summary"))
|
|
62
|
+
|
|
63
|
+
def upload(
|
|
64
|
+
self,
|
|
65
|
+
slug: str,
|
|
66
|
+
artefact: str,
|
|
67
|
+
filename: str,
|
|
68
|
+
data: bytes,
|
|
69
|
+
progress: Callable[[int, int], None] | None = None,
|
|
70
|
+
) -> JSON:
|
|
71
|
+
stored = self.api.upload(
|
|
72
|
+
self._repo(slug, f"/artefacts/{part(artefact)}/files"), filename, data, progress
|
|
73
|
+
)
|
|
74
|
+
return stored if isinstance(stored, dict) else {}
|
|
75
|
+
|
|
76
|
+
def remove(self, slug: str, artefact: str, file_id: str) -> None:
|
|
77
|
+
"""Take a file off a draft. The platform keeps it in the file history, so it can be
|
|
78
|
+
brought back (ADR 0020)."""
|
|
79
|
+
self.api.delete(self._repo(slug, f"/artefacts/{part(artefact)}/files/{part(file_id)}"))
|
|
80
|
+
|
|
81
|
+
# ------------------------------------------------------------------ at a glance
|
|
82
|
+
def activity(self, limit: int = 50) -> list[JSON]:
|
|
83
|
+
return self._list(self._o(f"/activity?limit={int(limit)}"))
|
|
84
|
+
|
|
85
|
+
def checks(self) -> list[JSON]:
|
|
86
|
+
return self._list(self._o("/checks"))
|
|
87
|
+
|
|
88
|
+
def check(self, check_id: str) -> JSON:
|
|
89
|
+
return self._one(self._o(f"/checks/{part(check_id)}"))
|
|
90
|
+
|
|
91
|
+
def partners(self) -> JSON:
|
|
92
|
+
return self._one(self._o("/partners"))
|
|
93
|
+
|
|
94
|
+
def partnership(self, agreement: str, limit: int = 200) -> JSON:
|
|
95
|
+
return self._one(self._o(f"/partners/{part(agreement)}?limit={int(limit)}"))
|
|
96
|
+
|
|
97
|
+
def access(self, slug: str, dataset: str) -> JSON:
|
|
98
|
+
return self._one(self._repo(slug, f"/datasets/{part(dataset)}/access"))
|
|
@@ -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.
|