@cloop/runner 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,177 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ readState
4
+ } from "./chunk-UYTSOW2C.js";
5
+ import {
6
+ sanitizeLabel
7
+ } from "./chunk-4LFQXBWP.js";
8
+ import {
9
+ VERSION
10
+ } from "./chunk-7K5W6ELQ.js";
11
+ import {
12
+ getToken
13
+ } from "./chunk-SQJ7ZO4G.js";
14
+
15
+ // src/commands/statusline.ts
16
+ var FRESH_MS = 2 * 60 * 1e3;
17
+ var STALE_MS = 10 * 60 * 1e3;
18
+ var OFFLINE_MS = 90 * 1e3;
19
+ var WORKING_MS = 5 * 60 * 1e3;
20
+ var MAX_CHIPS = 4;
21
+ var dim = (s) => `\x1B[2m${s}\x1B[22m`;
22
+ var green = (s) => `\x1B[32m${s}\x1B[39m`;
23
+ var yellow = (s) => `\x1B[33m${s}\x1B[39m`;
24
+ var red = (s) => `\x1B[31m${s}\x1B[39m`;
25
+ var blue = (s) => `\x1B[34m${s}\x1B[39m`;
26
+ var orange = (s) => `\x1B[38;5;208m${s}\x1B[39m`;
27
+ var magenta = (s) => `\x1B[35m${s}\x1B[39m`;
28
+ function link(url, text) {
29
+ return `\x1B]8;;${url}\x07${text}\x1B]8;;\x07`;
30
+ }
31
+ function versionSuffix() {
32
+ const dotIdx = VERSION.indexOf(".");
33
+ return dotIdx >= 0 ? VERSION.slice(dotIdx) : `.${VERSION}`;
34
+ }
35
+ function mark(state, now) {
36
+ let o0;
37
+ switch (state) {
38
+ case "online": {
39
+ const frame = Math.floor(now / 1e3) % 3;
40
+ if (frame === 0) o0 = `${blue("o")}${green("0")}`;
41
+ else if (frame === 1) o0 = `${green("o")}${blue("0")}`;
42
+ else o0 = `${green("o")}${green("0")}`;
43
+ break;
44
+ }
45
+ case "connecting":
46
+ o0 = `${orange("o")}${orange("0")}`;
47
+ break;
48
+ case "stale":
49
+ o0 = `${red("o")}${red("0")}`;
50
+ break;
51
+ default:
52
+ o0 = dim("o0");
53
+ break;
54
+ }
55
+ return `${link("https://mycloop.com", o0)}${dim(versionSuffix())}`;
56
+ }
57
+ var PLATFORM_LABELS = {
58
+ claude: "CC",
59
+ codex: "CX",
60
+ cowork: "CW"
61
+ };
62
+ function platformLabel(platform) {
63
+ return PLATFORM_LABELS[platform] ?? (platform || "??").slice(0, 2).toUpperCase();
64
+ }
65
+ function lastSegment(value) {
66
+ const idx = value.lastIndexOf("/");
67
+ return idx >= 0 ? value.slice(idx + 1) : value;
68
+ }
69
+ function surfaceLabel(surface) {
70
+ if (!surface) return "";
71
+ const repo = surface.repo ? sanitizeLabel(lastSegment(surface.repo), 20) : "";
72
+ const branch = surface.branch ? sanitizeLabel(lastSegment(surface.branch), 24) : "";
73
+ if (repo && branch) return `${repo}\xB7${branch}`;
74
+ if (repo) return repo;
75
+ if (surface.doc) return sanitizeLabel(lastSegment(surface.doc), 24);
76
+ return "";
77
+ }
78
+ function ageMs(iso, now) {
79
+ const then = new Date(iso).getTime();
80
+ return Number.isNaN(then) ? Number.POSITIVE_INFINITY : now - then;
81
+ }
82
+ function shortAge(iso, now) {
83
+ const ms = ageMs(iso, now);
84
+ if (!Number.isFinite(ms)) return "";
85
+ const secs = Math.max(0, Math.floor(ms / 1e3));
86
+ if (secs < 60) return `${secs}s`;
87
+ const mins = Math.floor(secs / 60);
88
+ if (mins < 60) return `${mins}m`;
89
+ const hours = Math.floor(mins / 60);
90
+ if (hours < 24) return `${hours}h`;
91
+ return `${Math.floor(hours / 24)}d`;
92
+ }
93
+ function isOffline(s, now) {
94
+ if (s.status === "ended") return true;
95
+ return ageMs(s.last_seen_at, now) > OFFLINE_MS;
96
+ }
97
+ function activityAt(s) {
98
+ return s.event_at ?? s.last_seen_at;
99
+ }
100
+ function isWorking(s, now) {
101
+ return s.status === "active" && ageMs(activityAt(s), now) < WORKING_MS;
102
+ }
103
+ var SPINNER = ["\u28FE", "\u28FD", "\u28FB", "\u28BF", "\u287F", "\u28DF", "\u28EF", "\u28F7"];
104
+ function chip(s, now, localMachine, count) {
105
+ const working = isWorking(s, now);
106
+ const dot = working ? green("\u25CF") : yellow("\u25CB");
107
+ const plat = platformLabel(s.platform);
108
+ const machine = sanitizeLabel(s.machine, 20);
109
+ const machineTag = machine && machine !== localMachine ? ` ${dim(machine)}` : "";
110
+ const surface = surfaceLabel(s.surface);
111
+ const surfaceTag = surface ? ` ${dim(surface)}` : "";
112
+ const multi = count > 1 ? dim(`\xD7${count}`) : "";
113
+ const event = s.event ? sanitizeLabel(s.event, 20) : working ? "working" : "awaiting";
114
+ const spin = working ? `${SPINNER[Math.floor(now / 1e3) % SPINNER.length]} ` : "";
115
+ const age = shortAge(activityAt(s), now);
116
+ const activity = dim(`${spin}${event}${age ? ` ${age}` : ""}`);
117
+ return `${dot} ${plat}${machineTag}${surfaceTag}${multi ? ` ${multi}` : ""} ${activity}`;
118
+ }
119
+ function collapse(sessions, now) {
120
+ const groups = /* @__PURE__ */ new Map();
121
+ for (const s of sessions) {
122
+ const key = `${s.machine}|${s.surface?.repo ?? ""}|${s.surface?.branch ?? ""}`;
123
+ const existing = groups.get(key);
124
+ if (!existing) {
125
+ groups.set(key, { session: s, count: 1 });
126
+ continue;
127
+ }
128
+ existing.count++;
129
+ const better = (isWorking(s, now) ? 1 : 0) - (isWorking(existing.session, now) ? 1 : 0) || ageMs(activityAt(existing.session), now) - ageMs(activityAt(s), now);
130
+ if (better > 0) existing.session = s;
131
+ }
132
+ return [...groups.values()].sort(
133
+ (a, b) => (isWorking(b.session, now) ? 1 : 0) - (isWorking(a.session, now) ? 1 : 0) || ageMs(activityAt(a.session), now) - ageMs(activityAt(b.session), now)
134
+ );
135
+ }
136
+ function renderStatusline({ state, loggedIn, now = Date.now() }) {
137
+ if (!loggedIn) return `${mark("offline", now)} ${dim("offline")}`;
138
+ if (!state) return `${mark("connecting", now)} ${dim("connecting\u2026")}`;
139
+ const snapshotAge = ageMs(state.updatedAt, now);
140
+ if (snapshotAge > STALE_MS) return `${mark("stale", now)} ${dim("stale")}`;
141
+ const markState = snapshotAge > FRESH_MS ? "cold" : "online";
142
+ let working = 0;
143
+ let awaiting = 0;
144
+ let offline = 0;
145
+ const live = [];
146
+ for (const s of state.sessions) {
147
+ if (isOffline(s, now)) {
148
+ offline++;
149
+ continue;
150
+ }
151
+ if (isWorking(s, now)) working++;
152
+ else awaiting++;
153
+ live.push(s);
154
+ }
155
+ const parts = [
156
+ mark(markState, now),
157
+ `${green("\u25CF")} ${working}`,
158
+ `${yellow("\u25CB")} ${awaiting}`,
159
+ `${dim("\u25CC")} ${offline}`
160
+ ];
161
+ if (state.inboxPending && state.inboxPending > 0) parts.push(magenta(`\u2709 ${state.inboxPending}`));
162
+ const nodes = collapse(live, now);
163
+ const localMachine = state.machine ? sanitizeLabel(state.machine, 20) : void 0;
164
+ for (const { session, count } of nodes.slice(0, MAX_CHIPS)) {
165
+ parts.push(chip(session, now, localMachine, count));
166
+ }
167
+ if (nodes.length > MAX_CHIPS) parts.push(dim(`+${nodes.length - MAX_CHIPS}`));
168
+ return parts.join(" ");
169
+ }
170
+ function statuslineCommand() {
171
+ const out = renderStatusline({ state: readState(), loggedIn: Boolean(getToken()) });
172
+ process.stdout.write(out);
173
+ }
174
+ export {
175
+ renderStatusline,
176
+ statuslineCommand
177
+ };
package/package.json CHANGED
@@ -1,6 +1,58 @@
1
1
  {
2
- "name": "@cloop/runner",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@cloop/runner",
3
+ "version": "0.2.0",
4
+ "private": false,
5
+ "license": "MIT",
6
+ "description": "Make your machine and your agents Cloop runners: device login, the runner daemon, the Cloop MCP server, and Claude Code hooks.",
7
+ "homepage": "https://mycloop.com",
8
+ "bugs": {
9
+ "url": "https://github.com/ClosedLoopTechnologies/clo0p/issues"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/ClosedLoopTechnologies/clo0p.git",
14
+ "directory": "clo0p-mcp"
15
+ },
16
+ "keywords": [
17
+ "cloop",
18
+ "mcp",
19
+ "claude-code",
20
+ "cowork",
21
+ "codex",
22
+ "agent-presence"
23
+ ],
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "engines": {
28
+ "node": ">=20"
29
+ },
30
+ "files": [
31
+ "dist"
32
+ ],
33
+ "type": "module",
34
+ "bin": {
35
+ "cloop": "dist/index.js"
36
+ },
37
+ "scripts": {
38
+ "build": "tsup && chmod 644 dist/*.js && chmod 755 dist/index.js",
39
+ "typecheck": "tsc --noEmit",
40
+ "dev": "tsup --watch",
41
+ "lint": "biome check src",
42
+ "format": "biome format --write src",
43
+ "test": "vitest run"
44
+ },
45
+ "dependencies": {
46
+ "@modelcontextprotocol/server": "^2.0.0",
47
+ "ws": "^8.18.0"
48
+ },
49
+ "devDependencies": {
50
+ "@biomejs/biome": "^1.9.0",
51
+ "@modelcontextprotocol/client": "^2.0.0",
52
+ "@types/node": "^22.0.0",
53
+ "@types/ws": "^8.5.0",
54
+ "tsup": "^8.5.1",
55
+ "typescript": "^5.6.0",
56
+ "vitest": "^3.0.0"
57
+ }
58
+ }