shadok-ai 0.17.63 → 0.17.65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -1
- package/context/connect-done.html +43 -0
- package/context/social-skill/SKILL.md +68 -0
- package/context/social-skill/scripts/social.mjs +86 -0
- package/context/social-skill/test/social.test.mjs +137 -0
- package/dist/account-expiry.d.ts +51 -0
- package/dist/account-expiry.js +116 -0
- package/dist/account-expiry.js.map +1 -0
- package/dist/channels.d.ts +14 -5
- package/dist/channels.js +19 -3
- package/dist/channels.js.map +1 -1
- package/dist/connect-crypto.d.ts +29 -0
- package/dist/connect-crypto.js +86 -0
- package/dist/connect-crypto.js.map +1 -0
- package/dist/connect-routes.d.ts +81 -0
- package/dist/connect-routes.js +129 -0
- package/dist/connect-routes.js.map +1 -0
- package/dist/connected-accounts.d.ts +109 -0
- package/dist/connected-accounts.js +228 -0
- package/dist/connected-accounts.js.map +1 -0
- package/dist/extract.d.ts +3 -1
- package/dist/extract.js.map +1 -1
- package/dist/groups.d.ts +15 -0
- package/dist/groups.js +36 -0
- package/dist/groups.js.map +1 -1
- package/dist/linkedin.d.ts +37 -0
- package/dist/linkedin.js +140 -0
- package/dist/linkedin.js.map +1 -0
- package/dist/secrets.d.ts +16 -1
- package/dist/secrets.js +50 -16
- package/dist/secrets.js.map +1 -1
- package/dist/server.js +660 -17
- package/dist/server.js.map +1 -1
- package/dist/social-drafts.d.ts +276 -0
- package/dist/social-drafts.js +478 -0
- package/dist/social-drafts.js.map +1 -0
- package/dist/telegram.d.ts +2 -0
- package/dist/telegram.js +13 -0
- package/dist/telegram.js.map +1 -1
- package/package.json +1 -1
- package/public/group-nav.js +25 -0
- package/public/index.html +540 -15
- package/public/secrets-panel.js +27 -13
- package/public/social-card.js +234 -0
package/README.md
CHANGED
|
@@ -158,7 +158,9 @@ Enter to skip; you can add it later from the web UI).
|
|
|
158
158
|
- **Secret vault** — stored under `~/.shadok-ai`, never in your repo, injected
|
|
159
159
|
as env vars into the agents that need them. Add or **update** a secret from the
|
|
160
160
|
panel, tick the **profiles** it should feed right there, and reload the running
|
|
161
|
-
agents on those profiles in one click so a rotated value takes effect now.
|
|
161
|
+
agents on those profiles in one click so a rotated value takes effect now. On
|
|
162
|
+
an instance with groups, **Any profile** feeds a secret to every agent that can
|
|
163
|
+
read it, whatever its profile (only a person can pick it, not an agent). An
|
|
162
164
|
agent that **obtains** a credential (a CLI login, a key it just provisioned)
|
|
163
165
|
can add it to the vault itself so the next agent doesn't start from nothing —
|
|
164
166
|
write-only, the value piped in rather than typed as an argument, and never
|
|
@@ -452,6 +454,51 @@ Enter to skip; you can add it later from the web UI).
|
|
|
452
454
|
you what it is?") rather than guessing a stack. It is an **offer, not a
|
|
453
455
|
first-run screen**: ignore it entirely and the cockpit works exactly the same.
|
|
454
456
|
`SHADOK_GREETING=0` turns it off.
|
|
457
|
+
- **Connected accounts (LinkedIn)** — connect a LinkedIn account once, then ask
|
|
458
|
+
an agent to post ("write a post about the release and publish it on our
|
|
459
|
+
LinkedIn"). In *Secrets → Connected accounts* a person clicks **Connect
|
|
460
|
+
LinkedIn**, consents on LinkedIn, and the account appears. The agent uses the
|
|
461
|
+
seeded `shadok-social` skill (`social.mjs accounts` / `post --account <id>
|
|
462
|
+
--stdin`) and **never sees the token**: it names an account, the server holds
|
|
463
|
+
the credential. By default the post is a **draft**: an approval card shows
|
|
464
|
+
the account, the exact text and the image in the agent's chat, and nothing
|
|
465
|
+
goes out until a person clicks *Publish* (or *Discard*). The image published
|
|
466
|
+
is the one on the card: the server keeps its own copy from the moment the
|
|
467
|
+
agent drafts, so changing the file afterwards changes nothing. Each account has an
|
|
468
|
+
**owner**, a **share** setting — any combination of the owner's *Personal*
|
|
469
|
+
group (the default), chosen restricted groups and *Public* (Main and every public group, one commons),
|
|
470
|
+
optionally narrowed to agents running given **profiles** — and a **policy** (`approve`, the default, or `autonomous`,
|
|
471
|
+
which publishes at once — only the account's **owner** can switch it to
|
|
472
|
+
`autonomous`). Every attempt — published, refused, expired,
|
|
473
|
+
failed — is written to a **publication log** (who triggered it, who approved
|
|
474
|
+
it, the text, the post URL or LinkedIn's error), readable by anyone who can
|
|
475
|
+
use the account through the row's **Log** button (the last 50 entries). A pending draft counts as "waiting for an answer" like a
|
|
476
|
+
dialog (favicon badge, tab blink), and an unapproved draft expires after 7
|
|
477
|
+
days. LinkedIn tokens last about 60 days: seven days before expiry the owner
|
|
478
|
+
gets a dismissible banner at the top of the cockpit (and again once it has
|
|
479
|
+
expired) and, when they are the Telegram DM owner, a DM; an expired
|
|
480
|
+
account refuses to publish with a sentence the agent can relay. Posts to
|
|
481
|
+
Company Pages need a second LinkedIn app and are planned for v1.1.
|
|
482
|
+
On a mono-tenant instance (a laptop, any macOS cockpit) agents run as your own
|
|
483
|
+
OS user, so this is a **soft layer**: it stops accidents and prompt injection
|
|
484
|
+
(an agent posting because a web page told it to), not an agent determined to
|
|
485
|
+
read `~/.shadok-ai/connected-accounts/`. It also means **every agent on a
|
|
486
|
+
mono-tenant instance can use every connected account**: there is no wall
|
|
487
|
+
between agents to scope by, so the share setting decides which *people* see
|
|
488
|
+
an account (and, on a multi-tenant instance, which groups' agents may use it).
|
|
489
|
+
The profile filter applies on both kinds of instance.
|
|
490
|
+
Multi-tenant instances, where agents run as other OS users, make it a real
|
|
491
|
+
boundary.
|
|
492
|
+
**Operator setup** (once, for whoever runs the broker): a small stateless
|
|
493
|
+
Cloudflare Worker (`broker/`) holds the LinkedIn client secret so instances
|
|
494
|
+
never do; see [`broker/README.md`](broker/README.md). It needs two LinkedIn
|
|
495
|
+
apps — **A**: Sign in with LinkedIn (OIDC) + *Share on LinkedIn*, for member
|
|
496
|
+
posts; **B**: the Community Management API *alone* (LinkedIn requires that
|
|
497
|
+
product to stand by itself), for Pages, v1.1 — with the redirect URL
|
|
498
|
+
`https://connect.shadok.ai/linkedin/callback`. Instances reach the broker at
|
|
499
|
+
`SHADOK_CONNECT_BROKER` (default `https://connect.shadok.ai`). LinkedIn
|
|
500
|
+
sunsets API versions, so `LINKEDIN_VERSION` in `src/linkedin.ts` must be
|
|
501
|
+
bumped about once a year, or posting stops working.
|
|
455
502
|
- **Self-update** — polls npm and can update and reload itself in place.
|
|
456
503
|
|
|
457
504
|
### Telegram (optional)
|
|
@@ -1228,6 +1275,7 @@ client, or immediately on an explicit `stop` (which ends it for everyone).
|
|
|
1228
1275
|
| `{type:"stream-text", text, at?}` | a complete assistant text block, from the transcript. `at` is when it was **written**, not when we read it |
|
|
1229
1276
|
| `{type:"stream-tool", id, name, summary}` / `{type:"stream-result", …}` | tool call / tool result |
|
|
1230
1277
|
| `{type:"tokens", tokens}` / `{type:"context", pct}` | token usage / context fill |
|
|
1278
|
+
| `{type:"social-draft", draft}` | a post waiting for approval, or its new state (published with URL, discarded, expired, failed) — the approval card. Also replayed inside `history` on reload. Never carries a token |
|
|
1231
1279
|
| `{type:"parent", parent}` | the channel's parent changed (broadcast, so every tab follows) |
|
|
1232
1280
|
| `{type:"prompt-echo", text, origin?, from?}` | prompt sent by another client of the session. `from` is resolved SERVER-side for a web, agent or peer prompt (the signed-in account / the calling agent's tab name / the peer's name); a frame's `from` is believed only from the Telegram bridge |
|
|
1233
1281
|
| `{type:"dialog", question, options:[{n,label,hint,checked?}], multi}` | choice pending |
|
|
@@ -1263,6 +1311,17 @@ or door that caused it; names only, never a value; filters `secret`, `action`,
|
|
|
1263
1311
|
🕘 on each secret), `/telegram`, `/defaults`, `/first-agent` (GET —
|
|
1264
1312
|
`{pending, reason}`: whether this instance's lead agent is being started
|
|
1265
1313
|
right now), `/version`, `/autoupdate`,
|
|
1314
|
+
`/connect/status` (GET — `{available}`: is the broker reachable/configured),
|
|
1315
|
+
`/connect/linkedin/start` · `/connect/linkedin/complete` (POST, browser person
|
|
1316
|
+
only — the OAuth hand-back; `/connect/linkedin/done` (GET) is the page the
|
|
1317
|
+
broker returns the browser to), `/connected-accounts` (GET — the accounts
|
|
1318
|
+
you may use, never a token, plus `softLayer`; your own accounts also carry
|
|
1319
|
+
`expiringSoon` / `expired`, for the banner; `GET /:id/log` — that account's
|
|
1320
|
+
last 50 publication-log entries, newest first; `PUT /:id` changes share/policy,
|
|
1321
|
+
`DELETE /:id` disconnects — owner or admin, browser only),
|
|
1322
|
+
`/social/accounts` (GET) and `/social/posts` (POST) — the **agent** side,
|
|
1323
|
+
authenticated by `x-shadok-session-key` —, and `/social/drafts/:id/publish` ·
|
|
1324
|
+
`/social/drafts/:id/discard` (POST, browser person only),
|
|
1266
1325
|
`/update-channel` (POST `{channel}` — `alpha` or `beta`), `/permission-mode`, `/tweak/prepare` (POST — clone/refresh shadok-ai's own source,
|
|
1267
1326
|
returns the cwd to start the tweak agent in). The instance-wide writes —
|
|
1268
1327
|
`/autoupdate`, `/update-channel`, `/permission-mode`, `POST /ledger`, a bare
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>Connect LinkedIn</title>
|
|
7
|
+
<style>
|
|
8
|
+
body { font: 16px/1.5 system-ui, sans-serif; background: #0f1115; color: #e6e6e6; display: grid; place-items: center; min-height: 100vh; margin: 0; }
|
|
9
|
+
main { max-width: 28rem; padding: 2rem; text-align: center; }
|
|
10
|
+
a { color: #7aa2f7; }
|
|
11
|
+
</style>
|
|
12
|
+
</head>
|
|
13
|
+
<body>
|
|
14
|
+
<main>
|
|
15
|
+
<p id="msg">Finishing the LinkedIn connection…</p>
|
|
16
|
+
<p><a href="/">Back to the cockpit</a></p>
|
|
17
|
+
</main>
|
|
18
|
+
<!-- Served by GET /connect/linkedin/done with a per-request nonce (invariant 12).
|
|
19
|
+
Every URL is path-relative so it works behind a TLS proxy (invariant 20). -->
|
|
20
|
+
<script nonce="__CSP_NONCE__">
|
|
21
|
+
(async () => {
|
|
22
|
+
const msg = document.getElementById("msg");
|
|
23
|
+
const hash = location.hash;
|
|
24
|
+
// Drop the encrypted token from the address bar and the history at once.
|
|
25
|
+
history.replaceState(null, "", location.pathname + location.search);
|
|
26
|
+
let text = "The connection could not be finished — click Connect LinkedIn again.";
|
|
27
|
+
try {
|
|
28
|
+
const r = await fetch("/connect/linkedin/complete", {
|
|
29
|
+
method: "POST",
|
|
30
|
+
headers: { "content-type": "application/json" },
|
|
31
|
+
credentials: "same-origin",
|
|
32
|
+
body: JSON.stringify({ hash }),
|
|
33
|
+
});
|
|
34
|
+
const j = await r.json().catch(() => ({}));
|
|
35
|
+
if (r.ok && j.account) text = "LinkedIn connected as " + (j.account.label || "your account") + ".";
|
|
36
|
+
else if (j.message) text = j.message;
|
|
37
|
+
else if (j.error) text = j.error;
|
|
38
|
+
} catch { /* keep the generic sentence */ }
|
|
39
|
+
msg.textContent = text;
|
|
40
|
+
})();
|
|
41
|
+
</script>
|
|
42
|
+
</body>
|
|
43
|
+
</html>
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: shadok-social
|
|
3
|
+
description: Post on LinkedIn (or another social network) for the person you are talking to. Use when they ask you to post, publish or share something on LinkedIn or social networks.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# shadok-social
|
|
7
|
+
|
|
8
|
+
Publishes a post on a LinkedIn account the person connected in the cockpit.
|
|
9
|
+
You never hold the account's token and it is never available to you — do not
|
|
10
|
+
look for it. The server publishes on your behalf.
|
|
11
|
+
|
|
12
|
+
## Steps
|
|
13
|
+
|
|
14
|
+
### 1. Pick the account
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
node ~/.claude/skills/shadok-social/scripts/social.mjs accounts
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
One line per account: `<id> <label> <provider> policy=<policy> expires=<date>`.
|
|
21
|
+
If none is listed, tell the person to connect one in Secrets → Connected
|
|
22
|
+
accounts, or to share theirs with this agent's group. If an account is marked `EXPIRED`, say so; they must reconnect it.
|
|
23
|
+
|
|
24
|
+
### 2. Show the final text first
|
|
25
|
+
|
|
26
|
+
Show the final text in the chat FIRST, exactly as it will be posted, and
|
|
27
|
+
wait for their go-ahead if they have not already approved it.
|
|
28
|
+
|
|
29
|
+
### 3. Post it
|
|
30
|
+
|
|
31
|
+
The text goes through stdin, never argv:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
node ~/.claude/skills/shadok-social/scripts/social.mjs post --account <id> [--image /abs/path.png] --stdin <<'EOF'
|
|
35
|
+
the exact text
|
|
36
|
+
EOF
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`--image` must be an absolute path. The limit is 3000 characters.
|
|
40
|
+
|
|
41
|
+
## Never claim it is published until you are told
|
|
42
|
+
|
|
43
|
+
With `policy=approve` the post is only a **draft** waiting for the person to
|
|
44
|
+
approve it in the cockpit. The command says so ("Draft … is waiting for
|
|
45
|
+
approval"). Do not say it is published: a hidden notice reaches you when it is
|
|
46
|
+
published or discarded. Only a printed URL means it is already live.
|
|
47
|
+
|
|
48
|
+
If the server refuses, the script prints its sentence and exits 1 — relay it
|
|
49
|
+
as it is, and do not retry in a loop.
|
|
50
|
+
|
|
51
|
+
## Authenticating a direct API call
|
|
52
|
+
|
|
53
|
+
The command above does this for you. If you call the cockpit's API yourself,
|
|
54
|
+
send your session key — it is in your environment and it does not expire:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
curl -sS -H "x-shadok-session-key: $SHADOK_SESSION_KEY" \
|
|
58
|
+
"http://127.0.0.1:$SHADOK_PORT/social/accounts"
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
That key is your ONLY credential, and it does not expire. You are no longer
|
|
62
|
+
handed a cookie or the cockpit password, and a call made with the key is made
|
|
63
|
+
as YOU — an agent of your own group, never an admin: account, backend and
|
|
64
|
+
other cockpit-admin routes answer `403`, and so do the person-only (browser)
|
|
65
|
+
ones such as approving a draft. That is by design; ask the human. A
|
|
66
|
+
`401` means that header is missing — or that you were started before this
|
|
67
|
+
existed, in which case nothing you hold can authenticate any more and only a
|
|
68
|
+
human can fix it: ask them for *Reload agent* on your ⋯ menu.
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// List the LinkedIn accounts shared with this agent, and post on one.
|
|
3
|
+
//
|
|
4
|
+
// The OAuth token is never here: the server holds it and publishes on the
|
|
5
|
+
// agent's behalf. This script only ever sends the session key and the text.
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
|
|
8
|
+
const MAX_CHARS = 3000; // mirrors MAX_COMMENTARY in src/linkedin.ts
|
|
9
|
+
const USAGE = "usage: social.mjs accounts | post --account <id> [--image <abs path>] --stdin";
|
|
10
|
+
const die = (m) => { console.error(m); process.exit(1); };
|
|
11
|
+
|
|
12
|
+
async function readStdin() {
|
|
13
|
+
const chunks = [];
|
|
14
|
+
for await (const c of process.stdin) chunks.push(c);
|
|
15
|
+
return Buffer.concat(chunks).toString("utf8").replace(/\r?\n$/, "");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function connection() {
|
|
19
|
+
const port = process.env.SHADOK_PORT;
|
|
20
|
+
const key = process.env.SHADOK_SESSION_KEY;
|
|
21
|
+
if (!port) die("Not inside a shadok-ai agent (SHADOK_PORT unset).");
|
|
22
|
+
if (!key) die("SHADOK_SESSION_KEY is unset — ask the human to reload this agent.");
|
|
23
|
+
return { port, key };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function call(method, route, payload) {
|
|
27
|
+
const { port, key } = connection();
|
|
28
|
+
let res;
|
|
29
|
+
try {
|
|
30
|
+
res = await fetch(`http://127.0.0.1:${port}${route}`, {
|
|
31
|
+
method,
|
|
32
|
+
headers: { "content-type": "application/json", "x-shadok-session-key": key },
|
|
33
|
+
...(payload ? { body: JSON.stringify(payload) } : {}),
|
|
34
|
+
signal: AbortSignal.timeout(60_000),
|
|
35
|
+
});
|
|
36
|
+
} catch (e) {
|
|
37
|
+
die(`The cockpit did not answer (${e?.message ?? e}). It may be restarting — say so rather than working around it.`);
|
|
38
|
+
}
|
|
39
|
+
const body = await res.json().catch(() => ({}));
|
|
40
|
+
if (!res.ok) die(body.error ?? `Refused (${res.status}): no reason given`);
|
|
41
|
+
return body;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const day = (ms) => new Date(ms).toISOString().slice(0, 10);
|
|
45
|
+
|
|
46
|
+
async function accounts() {
|
|
47
|
+
const { accounts: list = [] } = await call("GET", "/social/accounts");
|
|
48
|
+
if (!list.length) {
|
|
49
|
+
console.log("No LinkedIn account is available to this agent. Ask the person to connect one in Secrets → Connected accounts, or to share theirs with this agent's group.");
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
// Only these fields are ever printed, whatever else the server sent.
|
|
53
|
+
for (const a of list) {
|
|
54
|
+
console.log(`${String(a.id).slice(0, 8)} ${a.label} ${a.provider} policy=${a.policy} expires=${day(a.expiresAt)}${a.status === "expired" ? " EXPIRED" : ""}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function post(args) {
|
|
59
|
+
let account, image, stdin = false;
|
|
60
|
+
for (let i = 0; i < args.length; i++) {
|
|
61
|
+
if (args[i] === "--account") account = args[++i];
|
|
62
|
+
else if (args[i] === "--image") image = args[++i];
|
|
63
|
+
else if (args[i] === "--stdin") stdin = true;
|
|
64
|
+
else die(USAGE);
|
|
65
|
+
}
|
|
66
|
+
if (!stdin) die("post requires --stdin: the text is read from stdin so it never sits in argv.");
|
|
67
|
+
if (!account) die("post requires --account <id> (see `accounts`).");
|
|
68
|
+
if (image !== undefined && !path.isAbsolute(image)) die(`The image path must be absolute; '${image}' is not.`);
|
|
69
|
+
const text = await readStdin();
|
|
70
|
+
if (!text.trim()) die("The post is empty.");
|
|
71
|
+
const n = [...text].length;
|
|
72
|
+
if (n > MAX_CHARS) die(`The post is ${n.toLocaleString("en-US")} characters; LinkedIn allows ${MAX_CHARS.toLocaleString("en-US")}.`);
|
|
73
|
+
const out = await call("POST", "/social/posts", { account, text, ...(image ? { image } : {}) });
|
|
74
|
+
if (out.status === "pending") {
|
|
75
|
+
console.log(`Draft ${out.draftId} is waiting for approval in the cockpit. Do not say it is published until you are told.`);
|
|
76
|
+
} else if (out.status === "published") {
|
|
77
|
+
console.log(`Published: ${out.url}`);
|
|
78
|
+
} else {
|
|
79
|
+
die("The cockpit gave an answer this script does not understand.");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const [cmd, ...rest] = process.argv.slice(2);
|
|
84
|
+
if (cmd === "accounts") await accounts();
|
|
85
|
+
else if (cmd === "post") await post(rest);
|
|
86
|
+
else die(USAGE);
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { test } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import http from "node:http";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { execFile } from "node:child_process";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
|
|
8
|
+
const SCRIPT = path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "scripts", "social.mjs");
|
|
9
|
+
|
|
10
|
+
async function stub(status, body) {
|
|
11
|
+
const seen = {};
|
|
12
|
+
const server = http.createServer((req, res) => {
|
|
13
|
+
let raw = "";
|
|
14
|
+
req.on("data", (c) => (raw += c));
|
|
15
|
+
req.on("end", () => {
|
|
16
|
+
seen.method = req.method;
|
|
17
|
+
seen.url = req.url;
|
|
18
|
+
seen.key = req.headers["x-shadok-session-key"];
|
|
19
|
+
seen.body = raw ? JSON.parse(raw) : undefined;
|
|
20
|
+
res.writeHead(status, { "content-type": "application/json" });
|
|
21
|
+
res.end(JSON.stringify(body));
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
await new Promise((r) => server.listen(0, "127.0.0.1", r));
|
|
25
|
+
return { port: server.address().port, seen, close: () => new Promise((r) => server.close(r)) };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function run(args, port, stdin = "") {
|
|
29
|
+
return new Promise((resolve) => {
|
|
30
|
+
const child = execFile(
|
|
31
|
+
process.execPath,
|
|
32
|
+
[SCRIPT, ...args],
|
|
33
|
+
{ env: { ...process.env, SHADOK_PORT: String(port), SHADOK_SESSION_KEY: "key-123" } },
|
|
34
|
+
(e, out, err) => resolve({ code: e ? (e.code ?? 1) : 0, out, err }),
|
|
35
|
+
);
|
|
36
|
+
child.stdin.end(stdin);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
test("post --stdin sends the body and the session key; pending is explained", async () => {
|
|
41
|
+
const s = await stub(200, { status: "pending", draftId: "ab12cd34" });
|
|
42
|
+
const r = await run(["post", "--account", "a1b2c3d4", "--image", "/tmp/x.png", "--stdin"], s.port, "Hello world\n");
|
|
43
|
+
await s.close();
|
|
44
|
+
assert.equal(r.code, 0, r.err);
|
|
45
|
+
assert.equal(s.seen.url, "/social/posts");
|
|
46
|
+
assert.equal(s.seen.key, "key-123");
|
|
47
|
+
assert.deepEqual(s.seen.body, { account: "a1b2c3d4", text: "Hello world", image: "/tmp/x.png" });
|
|
48
|
+
assert.match(r.out, /Draft ab12cd34 is waiting for approval in the cockpit\. Do not say it is published until you are told\./);
|
|
49
|
+
assert.doesNotMatch(r.out + r.err, /key-123/);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("published prints the URL", async () => {
|
|
53
|
+
const s = await stub(200, { status: "published", url: "https://linkedin.com/feed/update/1" });
|
|
54
|
+
const r = await run(["post", "--account", "a1", "--stdin"], s.port, "Hi");
|
|
55
|
+
await s.close();
|
|
56
|
+
assert.match(r.out, /https:\/\/linkedin\.com\/feed\/update\/1/);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("a relative --image is refused locally", async () => {
|
|
60
|
+
const s = await stub(200, {});
|
|
61
|
+
const r = await run(["post", "--account", "a1", "--image", "pic.png", "--stdin"], s.port, "Hi");
|
|
62
|
+
await s.close();
|
|
63
|
+
assert.notEqual(r.code, 0);
|
|
64
|
+
assert.match(r.err, /absolute/);
|
|
65
|
+
assert.equal(s.seen.body, undefined);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("without --stdin the post is refused", async () => {
|
|
69
|
+
const s = await stub(200, {});
|
|
70
|
+
const r = await run(["post", "--account", "a1"], s.port);
|
|
71
|
+
await s.close();
|
|
72
|
+
assert.notEqual(r.code, 0);
|
|
73
|
+
assert.match(r.err, /--stdin/);
|
|
74
|
+
assert.equal(s.seen.body, undefined);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("text over 3000 code points is refused locally; exactly 3000 goes", async () => {
|
|
78
|
+
const s = await stub(200, { status: "pending", draftId: "d" });
|
|
79
|
+
const over = await run(["post", "--account", "a1", "--stdin"], s.port, "😀".repeat(3001));
|
|
80
|
+
assert.notEqual(over.code, 0);
|
|
81
|
+
assert.match(over.err, /3,001 characters; LinkedIn allows 3,000\./);
|
|
82
|
+
assert.equal(s.seen.body, undefined);
|
|
83
|
+
const ok = await run(["post", "--account", "a1", "--stdin"], s.port, "😀".repeat(3000));
|
|
84
|
+
await s.close();
|
|
85
|
+
assert.equal(ok.code, 0, ok.err);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("a server refusal prints its sentence on stderr and exits 1", async () => {
|
|
89
|
+
const s = await stub(403, { error: "That account is not shared with you." });
|
|
90
|
+
const r = await run(["post", "--account", "a1", "--stdin"], s.port, "Hi");
|
|
91
|
+
await s.close();
|
|
92
|
+
assert.equal(r.code, 1);
|
|
93
|
+
assert.match(r.err, /That account is not shared with you\./);
|
|
94
|
+
assert.equal(r.out, "");
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test("accounts prints only the known fields, never a token", async () => {
|
|
98
|
+
const s = await stub(200, { accounts: [
|
|
99
|
+
{ id: "a1b2c3d4e5f6", label: "Me", provider: "linkedin", kind: "x", policy: "approve", expiresAt: Date.UTC(2027, 0, 5), status: "ok", token: "SECRET-TOK" },
|
|
100
|
+
{ id: "ffeeddcc", label: "Co", provider: "linkedin", policy: "autonomous", expiresAt: Date.UTC(2026, 0, 1), status: "expired" },
|
|
101
|
+
] });
|
|
102
|
+
const r = await run(["accounts"], s.port);
|
|
103
|
+
await s.close();
|
|
104
|
+
assert.equal(r.code, 0, r.err);
|
|
105
|
+
assert.equal(s.seen.key, "key-123");
|
|
106
|
+
assert.doesNotMatch(r.out, /SECRET-TOK|token/i);
|
|
107
|
+
const lines = r.out.trim().split("\n");
|
|
108
|
+
assert.equal(lines[0], "a1b2c3d4 Me linkedin policy=approve expires=2027-01-05");
|
|
109
|
+
assert.equal(lines[1], "ffeeddcc Co linkedin policy=autonomous expires=2026-01-01 EXPIRED");
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("accounts with none says how to connect one", async () => {
|
|
113
|
+
const s = await stub(200, { accounts: [] });
|
|
114
|
+
const r = await run(["accounts"], s.port);
|
|
115
|
+
await s.close();
|
|
116
|
+
assert.equal(r.out.trim(), "No LinkedIn account is available to this agent. Ask the person to connect one in Secrets → Connected accounts, or to share theirs with this agent's group.");
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test("SKILL.md code fences are copy-pasteable: heredoc terminators and commands start at column 0", async () => {
|
|
120
|
+
const { readFileSync } = await import("node:fs");
|
|
121
|
+
const md = readFileSync(new URL("../SKILL.md", import.meta.url), "utf8").split("\n");
|
|
122
|
+
let inFence = false;
|
|
123
|
+
for (const line of md) {
|
|
124
|
+
if (line.trim().startsWith("```")) { inFence = !inFence; continue; }
|
|
125
|
+
if (line.trim() === "EOF") assert.equal(line, "EOF", "indented heredoc terminator");
|
|
126
|
+
if (inFence && line.trim().startsWith("node ")) assert.ok(line.startsWith("node "), `indented command: ${line}`);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test("the local post limit equals the server's MAX_COMMENTARY", async () => {
|
|
131
|
+
const { readFileSync } = await import("node:fs");
|
|
132
|
+
const here = (p) => readFileSync(new URL(p, import.meta.url), "utf8");
|
|
133
|
+
const local = here("../scripts/social.mjs").match(/const MAX_CHARS = (\d+)/);
|
|
134
|
+
const server = here("../../../src/linkedin.ts").match(/export const MAX_COMMENTARY = (\d+)/);
|
|
135
|
+
assert.ok(local && server);
|
|
136
|
+
assert.equal(local[1], server[1]);
|
|
137
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ConnectedAccount } from "./connected-accounts.js";
|
|
2
|
+
import { type Draft } from "./social-drafts.js";
|
|
3
|
+
/**
|
|
4
|
+
* The hourly watch over connected accounts and drafts: which accounts are close
|
|
5
|
+
* to (or past) their expiry, which drafts timed out, which publishes were
|
|
6
|
+
* orphaned by a restart. Pure decisions up top, the warning memory below. The
|
|
7
|
+
* server applies them; nothing here touches a token.
|
|
8
|
+
*/
|
|
9
|
+
export declare const WARN_BEFORE_MS: number;
|
|
10
|
+
export declare const REWARN_AFTER_MS: number;
|
|
11
|
+
export declare const STALE_PUBLISHING_MS: number;
|
|
12
|
+
export declare const STALE_PUBLISHING_SENTENCE = "The cockpit restarted while publishing; check LinkedIn before retrying.";
|
|
13
|
+
export interface ExpiryActions {
|
|
14
|
+
warn: ConnectedAccount[];
|
|
15
|
+
expire: ConnectedAccount[];
|
|
16
|
+
expiredDrafts: Draft[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Warn once a day from 7 days before `expiresAt`; expire at `expiresAt`. An
|
|
20
|
+
* account already marked expired is neither warned nor expired again. The draft
|
|
21
|
+
* TTL is `expireDrafts`' — one definition.
|
|
22
|
+
*/
|
|
23
|
+
export declare function expiryActions(accounts: readonly ConnectedAccount[], drafts: readonly Draft[], now: number, lastWarned: Readonly<Record<string, number>>): ExpiryActions;
|
|
24
|
+
/** Drafts stuck `publishing` past the window (the process died mid-publish) → failed.
|
|
25
|
+
* Measured from `publishingAt` (legacy: createdAt); ids in `inFlight` are being
|
|
26
|
+
* published by this process right now, slow but alive, and are never failed. */
|
|
27
|
+
export declare function stalePublishing(list: readonly Draft[], now: number, inFlight?: ReadonlySet<string>): {
|
|
28
|
+
list: Draft[];
|
|
29
|
+
failed: Draft[];
|
|
30
|
+
};
|
|
31
|
+
export declare function expiryWarningText(a: Pick<ConnectedAccount, "label" | "expiresAt">): string;
|
|
32
|
+
export declare function draftExpiredNotice(d: Pick<Draft, "id">): string;
|
|
33
|
+
export declare function pendingDraftText(channel: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* What the cockpit's banner needs about an account, for its OWNER only: the
|
|
36
|
+
* DM reaches the operator alone, so every other owner learns of an expiry from
|
|
37
|
+
* the page (`GET /connected-accounts`). Someone else's account gets nothing —
|
|
38
|
+
* reconnecting it is not theirs to do.
|
|
39
|
+
*/
|
|
40
|
+
export declare function ownerExpiryFlags(a: Pick<ConnectedAccount, "owner" | "expiresAt" | "status">, viewerName: string | null, now: number): {
|
|
41
|
+
expiringSoon?: boolean;
|
|
42
|
+
expired?: boolean;
|
|
43
|
+
};
|
|
44
|
+
/** Only the instance operator (the bootstrap admin) is the Telegram DM owner. */
|
|
45
|
+
export declare function ownerIsOperator(owner: string, bootstrapAdmin: string): boolean;
|
|
46
|
+
export declare function warnedFileFor(cwd: string): string;
|
|
47
|
+
/** Missing or unparseable → {}. Never throws. */
|
|
48
|
+
export declare function loadWarned(file: string): Record<string, number>;
|
|
49
|
+
/** Drops ids no longer in the store; atomic, mode 600. Written only when its
|
|
50
|
+
* content changes — the watch runs hourly and almost always has nothing new. */
|
|
51
|
+
export declare function saveWarned(file: string, warned: Record<string, number>, liveIds: readonly string[]): void;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { randomBytes } from "node:crypto";
|
|
5
|
+
import { instanceKey } from "./paths.js";
|
|
6
|
+
import { expireDrafts } from "./social-drafts.js";
|
|
7
|
+
/**
|
|
8
|
+
* The hourly watch over connected accounts and drafts: which accounts are close
|
|
9
|
+
* to (or past) their expiry, which drafts timed out, which publishes were
|
|
10
|
+
* orphaned by a restart. Pure decisions up top, the warning memory below. The
|
|
11
|
+
* server applies them; nothing here touches a token.
|
|
12
|
+
*/
|
|
13
|
+
export const WARN_BEFORE_MS = 7 * 24 * 3600_000;
|
|
14
|
+
export const REWARN_AFTER_MS = 24 * 3600_000;
|
|
15
|
+
export const STALE_PUBLISHING_MS = 10 * 60_000;
|
|
16
|
+
export const STALE_PUBLISHING_SENTENCE = "The cockpit restarted while publishing; check LinkedIn before retrying.";
|
|
17
|
+
/**
|
|
18
|
+
* Warn once a day from 7 days before `expiresAt`; expire at `expiresAt`. An
|
|
19
|
+
* account already marked expired is neither warned nor expired again. The draft
|
|
20
|
+
* TTL is `expireDrafts`' — one definition.
|
|
21
|
+
*/
|
|
22
|
+
export function expiryActions(accounts, drafts, now, lastWarned) {
|
|
23
|
+
const warn = [];
|
|
24
|
+
const expire = [];
|
|
25
|
+
for (const a of accounts) {
|
|
26
|
+
if (a.status === "expired")
|
|
27
|
+
continue;
|
|
28
|
+
if (now >= a.expiresAt) {
|
|
29
|
+
expire.push(a);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const last = lastWarned[a.id];
|
|
33
|
+
if (a.expiresAt - now <= WARN_BEFORE_MS && (last === undefined || now - last >= REWARN_AFTER_MS))
|
|
34
|
+
warn.push(a);
|
|
35
|
+
}
|
|
36
|
+
return { warn, expire, expiredDrafts: expireDrafts(drafts, now).expired };
|
|
37
|
+
}
|
|
38
|
+
/** Drafts stuck `publishing` past the window (the process died mid-publish) → failed.
|
|
39
|
+
* Measured from `publishingAt` (legacy: createdAt); ids in `inFlight` are being
|
|
40
|
+
* published by this process right now, slow but alive, and are never failed. */
|
|
41
|
+
export function stalePublishing(list, now, inFlight = new Set()) {
|
|
42
|
+
const failed = [];
|
|
43
|
+
const out = list.map((d) => {
|
|
44
|
+
if (d.status !== "publishing" || inFlight.has(d.id) || now - (d.publishingAt ?? d.createdAt) < STALE_PUBLISHING_MS)
|
|
45
|
+
return d;
|
|
46
|
+
const f = { ...d, status: "failed", error: STALE_PUBLISHING_SENTENCE };
|
|
47
|
+
failed.push(f);
|
|
48
|
+
return f;
|
|
49
|
+
});
|
|
50
|
+
return { list: out, failed };
|
|
51
|
+
}
|
|
52
|
+
function isoDay(ms) {
|
|
53
|
+
return new Date(ms).toISOString().slice(0, 10);
|
|
54
|
+
}
|
|
55
|
+
export function expiryWarningText(a) {
|
|
56
|
+
return `Your LinkedIn connection '${a.label}' expires on ${isoDay(a.expiresAt)}. Reconnect it in Secrets → Connected accounts so posts keep going out.`;
|
|
57
|
+
}
|
|
58
|
+
export function draftExpiredNotice(d) {
|
|
59
|
+
return `Your LinkedIn draft ${d.id.slice(0, 8)} expired after 7 days without approval — it was not published.`;
|
|
60
|
+
}
|
|
61
|
+
export function pendingDraftText(channel) {
|
|
62
|
+
return `${channel} has a LinkedIn post waiting for your approval in the cockpit.`;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* What the cockpit's banner needs about an account, for its OWNER only: the
|
|
66
|
+
* DM reaches the operator alone, so every other owner learns of an expiry from
|
|
67
|
+
* the page (`GET /connected-accounts`). Someone else's account gets nothing —
|
|
68
|
+
* reconnecting it is not theirs to do.
|
|
69
|
+
*/
|
|
70
|
+
export function ownerExpiryFlags(a, viewerName, now) {
|
|
71
|
+
if (!viewerName || viewerName !== a.owner)
|
|
72
|
+
return {};
|
|
73
|
+
const expired = a.status === "expired" || now >= a.expiresAt;
|
|
74
|
+
return { expiringSoon: !expired && a.expiresAt - now <= WARN_BEFORE_MS, expired };
|
|
75
|
+
}
|
|
76
|
+
/** Only the instance operator (the bootstrap admin) is the Telegram DM owner. */
|
|
77
|
+
export function ownerIsOperator(owner, bootstrapAdmin) {
|
|
78
|
+
return owner === bootstrapAdmin;
|
|
79
|
+
}
|
|
80
|
+
// ---- the warning memory (sidecar: the account store's shape is fixed) -----
|
|
81
|
+
export function warnedFileFor(cwd) {
|
|
82
|
+
return path.join(os.homedir(), ".shadok-ai", "connected-accounts", `${instanceKey(cwd)}.warned.json`);
|
|
83
|
+
}
|
|
84
|
+
/** Missing or unparseable → {}. Never throws. */
|
|
85
|
+
export function loadWarned(file) {
|
|
86
|
+
try {
|
|
87
|
+
const p = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
88
|
+
if (!p || typeof p !== "object" || Array.isArray(p))
|
|
89
|
+
return {};
|
|
90
|
+
const out = {};
|
|
91
|
+
for (const [k, v] of Object.entries(p))
|
|
92
|
+
if (typeof v === "number")
|
|
93
|
+
out[k] = v;
|
|
94
|
+
return out;
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return {};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/** Drops ids no longer in the store; atomic, mode 600. Written only when its
|
|
101
|
+
* content changes — the watch runs hourly and almost always has nothing new. */
|
|
102
|
+
export function saveWarned(file, warned, liveIds) {
|
|
103
|
+
const keep = {};
|
|
104
|
+
for (const id of liveIds)
|
|
105
|
+
if (warned[id] !== undefined)
|
|
106
|
+
keep[id] = warned[id];
|
|
107
|
+
const before = fs.existsSync(file) ? loadWarned(file) : null;
|
|
108
|
+
if (before ? JSON.stringify(before) === JSON.stringify(keep) : Object.keys(keep).length === 0)
|
|
109
|
+
return;
|
|
110
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
111
|
+
const tmp = `${file}.${process.pid}.${randomBytes(4).toString("hex")}.tmp`;
|
|
112
|
+
fs.writeFileSync(tmp, JSON.stringify(keep, null, 2), { mode: 0o600 });
|
|
113
|
+
fs.chmodSync(tmp, 0o600);
|
|
114
|
+
fs.renameSync(tmp, file);
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=account-expiry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-expiry.js","sourceRoot":"","sources":["../src/account-expiry.ts"],"names":[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CAAC,CAAC;IACzB,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AAC3B,CAAC"}
|
package/dist/channels.d.ts
CHANGED
|
@@ -13,9 +13,10 @@ export interface Channel {
|
|
|
13
13
|
branch?: string | null;
|
|
14
14
|
/** Repo the worktree belongs to, to recreate a reclaimed checkout. */
|
|
15
15
|
repo?: string;
|
|
16
|
-
/** Id of the `Group` this agent
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
/** Id of the `Group` this agent lives in. Server-owned: a client PUT changes
|
|
17
|
+
* it only through `mergeChannels`' `mayMove` — freely in mono-tenant, and
|
|
18
|
+
* under multi-tenant only between groups that share an OS user (public ↔
|
|
19
|
+
* public/Main, `groupMoveRefusal`), never across an isolation wall. */
|
|
19
20
|
group?: string | null;
|
|
20
21
|
/** The environment's home base: pinned, never closable. Server-owned, so a
|
|
21
22
|
* stale client's PUT cannot clear it. See `isHomeChannel`. */
|
|
@@ -222,8 +223,16 @@ export declare function mergeChannels(stored: Channel[], clientList: Channel[],
|
|
|
222
223
|
* ignored, so a caller can neither drop nor rename what it cannot see.
|
|
223
224
|
* Omitted → every row is visible (mono-tenant, internal callers).
|
|
224
225
|
*/
|
|
225
|
-
canSee?: (c: Channel) => boolean
|
|
226
|
-
|
|
226
|
+
canSee?: (c: Channel) => boolean,
|
|
227
|
+
/**
|
|
228
|
+
* May the caller move this stored row to group `to`? `group` is SERVER_OWNED,
|
|
229
|
+
* so with no predicate a client can never change it (the safe default, and
|
|
230
|
+
* what every internal caller gets). `PUT /channels` passes one: anything in
|
|
231
|
+
* mono-tenant, where groups are cosmetic, and `groupMoveRefusal` under
|
|
232
|
+
* multi-tenant, where a group decides the OS user an agent runs as.
|
|
233
|
+
*/
|
|
234
|
+
mayMove?: (prev: Channel, to: string | null) => boolean): Channel[];
|
|
235
|
+
export declare function mergeClientChannels(clientList: Channel[], liveIds: Set<string>, canSee?: (c: Channel) => boolean, mayMove?: (prev: Channel, to: string | null) => boolean): Channel[];
|
|
227
236
|
/**
|
|
228
237
|
* Coerce whatever is on disk (or in a PUT body) into typed Groups. Legacy rows
|
|
229
238
|
* were cosmetic tab groups (`{id:number, name, collapsed, order}`); they become
|