conare 0.33.0 → 0.34.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.
- package/README.md +68 -18
- package/dist/cli/args.js +39 -9
- package/dist/cli/config.js +21 -1
- package/dist/cli/documents.js +3 -2
- package/dist/cli/legacy.js +111 -0
- package/dist/cli/main.js +147 -57
- package/dist/cli/others.js +46 -0
- package/dist/cli/schedule.js +74 -10
- package/dist/cli/scrub.js +28 -9
- package/dist/cli/sources/claude.js +19 -6
- package/dist/cli/sources/codex.js +5 -5
- package/dist/cli/sources/cursor.js +250 -0
- package/dist/cli/sources/pi.js +180 -0
- package/dist/cli/state.js +34 -10
- package/dist/cli/status.js +18 -14
- package/dist/cli/sync.js +61 -14
- package/dist/cli/transcript.js +68 -3
- package/dist/cli/upload.js +9 -5
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -424,31 +424,56 @@ npx conare sync --uninstall # stop the background sync
|
|
|
424
424
|
npx conare sync github owner/repo # issues, PRs and markdown docs (GITHUB_TOKEN or gh auth)
|
|
425
425
|
```
|
|
426
426
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
`
|
|
427
|
+
Create the key at https://conare.ai/dashboard/keys (access is by invitation:
|
|
428
|
+
https://conare.ai/request-access). Synced: Claude Code, Codex, Cursor (on Node 22.13 or newer, or
|
|
429
|
+
Bun: it is read with `node:sqlite`), Pi. Not synced yet: OpenCode, Grok; a sync that finds one of
|
|
430
|
+
them on the machine says so, and names Cursor when the runtime cannot read it.
|
|
431
|
+
|
|
432
|
+
**Sessions.** Each Claude Code, Codex, Pi session and Cursor chat becomes one document in the
|
|
433
|
+
namespace `sessions`: a readable transcript with the prompts, the answers, one line per tool call,
|
|
434
|
+
and the errors. Tool output that succeeded, images and thinking are left out, and secrets (API keys,
|
|
435
|
+
tokens, private keys, passwords) are replaced with `[REDACTED:<kind>]` before anything is sent. Ids
|
|
436
|
+
are `claude:<session>`, `claude:<session>:agent:<agent>` for a subagent, `codex:<rollout file
|
|
437
|
+
name>`, `pi:<session file name>` and `cursor:<composer id>`; a session over 250 KB is sent as
|
|
438
|
+
`<id>:part:000001`, `:part:000002`, and so on (one layout per session, never both), so a sync sends
|
|
439
|
+
only the parts that changed. Metadata: `source` (`claude-code`, `codex`, `pi` or `cursor`),
|
|
440
|
+
`session_id`, `agent_id`, `project`, `cwd`, `git_branch`, `started_at`, `date` (the last activity)
|
|
441
|
+
and `content_hash`. A Cursor chat records no directory, so it has no `project` or `cwd`.
|
|
436
442
|
|
|
437
443
|
```ts
|
|
438
444
|
const sessions = conare.namespace("sessions");
|
|
439
445
|
await sessions.query("why did we drop the Redis cache?", { filter: { project: "shop" } });
|
|
440
446
|
```
|
|
441
447
|
|
|
442
|
-
It reads `~/.claude/projects` (or `$CLAUDE_CONFIG_DIR`)
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
448
|
+
It reads `~/.claude/projects` (or `$CLAUDE_CONFIG_DIR`), `~/.codex/sessions` (or `$CODEX_HOME`),
|
|
449
|
+
`~/.pi/agent/sessions` (or `$PI_CODING_AGENT_SESSION_DIR`, or `sessions` in `$PI_CODING_AGENT_DIR`)
|
|
450
|
+
and Cursor's `User/globalStorage/state.vscdb` (in `~/Library/Application Support/Cursor` on macOS,
|
|
451
|
+
`~/.config/Cursor` on Linux), opened read-only. Cursor keeps every chat in that one database, so each
|
|
452
|
+
chat is tracked by its own last update; the list of chats is kept in `~/.conare/cursor-composers.json`
|
|
453
|
+
and the database is not opened while it is unchanged.
|
|
454
|
+
The key comes from `--key`, else `CONARE_API_KEY`, else `~/.conare/sync.json`; a key of several
|
|
455
|
+
organizations needs `--org org_…` (or `CONARE_ORG`). What the server already has is kept in
|
|
456
|
+
`~/.conare/sync-state.json` and checked against the namespace's listing once a day: a session deleted
|
|
457
|
+
on the server (in the console, say) is uploaded again within a day, unless its project is in
|
|
458
|
+
`~/.conare/sync-exclude`. Sessions of an excluded project, and transcripts with no message this
|
|
459
|
+
version can read, are recorded there too and not read again until they change (or, for the latter,
|
|
460
|
+
another version runs). One run at a time holds `~/.conare/sync.lock`; `~/.conare` is readable by
|
|
461
|
+
you alone.
|
|
446
462
|
`--install` copies the command to `~/.conare/sync/<version>/`, checks the copy file by file, runs
|
|
447
|
-
it once, and only then adds a launchd agent (`ai.conare.sync`) on macOS or a
|
|
448
|
-
|
|
463
|
+
it once with the key it saved, and only then adds a launchd agent (`ai.conare.sync`) on macOS or a
|
|
464
|
+
systemd user timer on Linux; a key that may not write `sessions` (exit 3) or an organization out of
|
|
465
|
+
credits (exit 5) schedules nothing. On Linux without a systemd user manager, and on Windows, it
|
|
466
|
+
schedules nothing and prints the cron or `schtasks` line to add yourself; on Linux it says when the
|
|
467
|
+
timer stops at logout (`loginctl enable-linger`). The schedule does not update itself: `sync` and
|
|
468
|
+
`sync status` say when it runs an older version than the one you ran. Every run adds a line to
|
|
469
|
+
`~/.conare/sync.log` (uploaded, skipped and failed counts, duration).
|
|
449
470
|
With `--install --via <command>` the schedule runs the sync through that command, which supplies
|
|
450
|
-
`CONARE_API_KEY` (for example a secrets manager's wrapper such as `ops`), and no key is saved to disk
|
|
451
|
-
|
|
471
|
+
`CONARE_API_KEY` (for example a secrets manager's wrapper such as `ops`), and no key is saved to disk;
|
|
472
|
+
the first run goes through it too.
|
|
473
|
+
Up to four batches upload at once. On a machine that has the old Conare CLI (0.7 and earlier, `cmem_`
|
|
474
|
+
keys, retired on 2026-10-02), `--install` also removes its background job (`ai.conare.ingest`, its
|
|
475
|
+
systemd timer or its cron line) and its program in `~/.conare/bin`, and points its `conare` command
|
|
476
|
+
at this version; `~/.conare/config.json` is left as it is.
|
|
452
477
|
|
|
453
478
|
**GitHub.** `conare sync github owner/repo` writes every issue and PR thread (body, comments and
|
|
454
479
|
review comments; bots other than `greptile-apps[bot]` and `claude[bot]` are left out) into
|
|
@@ -460,7 +485,32 @@ and files whose content changed; docs whose file was deleted are deleted. `--sta
|
|
|
460
485
|
where that is kept (default `~/.conare/github-state.json`). `<repo>` is the repository's name
|
|
461
486
|
lowercased, with any character other than letters, digits, `_` and `-` as `-` (`vercel/next.js`
|
|
462
487
|
writes `next-js-github`). A namespace that already holds another owner's repository of the same
|
|
463
|
-
name is left alone, and that repository's sync stops with an error.
|
|
488
|
+
name is left alone, and that repository's sync stops with an error. A GitHub source connected in the
|
|
489
|
+
dashboard keeps a repository in sync without this command.
|
|
490
|
+
|
|
491
|
+
## Changes in 0.34.0
|
|
492
|
+
|
|
493
|
+
Nothing to change in code that uses the library. The `conare` command:
|
|
494
|
+
|
|
495
|
+
- `conare sync` also uploads Pi sessions and Cursor chats (Cursor on Node 22.13 or newer, or Bun; on
|
|
496
|
+
an older Node it says Cursor is not synced and why). The schedule passes on `PI_CODING_AGENT_DIR`
|
|
497
|
+
and `PI_CODING_AGENT_SESSION_DIR`.
|
|
498
|
+
- `conare --key sk-conare-…` without a command syncs, as `conare sync --key` does. The old CLI's
|
|
499
|
+
flags and commands (`--install-sync`, `--config-file`, `doctor`, a `cmem_` key, …) say how to move to
|
|
500
|
+
this one instead of "Unknown argument"; `sync --install` retires the old CLI where it is installed.
|
|
501
|
+
- Exit codes: a key that may not write the namespace (403) or acts for several organizations without
|
|
502
|
+
`--org` exits 3, not 4; an organization out of credits or over its cap (402) exits 5, with the
|
|
503
|
+
billing page. `--install` schedules nothing after 3 or 5, and checks the platform before copying
|
|
504
|
+
anything. A held lock in `sync github` exits 4, a GitHub token or repository GitHub refuses 1.
|
|
505
|
+
- A 400 that names no document (a key of several organizations without `--org`) stops the run, where
|
|
506
|
+
every document used to be sent again alone and reported "Not accepted" on every run. `--org` (or
|
|
507
|
+
`CONARE_ORG`) is new, and the schedule keeps it.
|
|
508
|
+
- The namespace is listed once a day rather than on every run (a no-op run took about a minute on
|
|
509
|
+
4,400 sessions), and sessions left out on purpose are recorded, so `sync status` no longer reports
|
|
510
|
+
them as missed forever.
|
|
511
|
+
- `--dry-run` without a key counts against the saved state rather than calling everything new.
|
|
512
|
+
- `~/.conare` is made readable by you alone, and `sync.log` 0600.
|
|
513
|
+
- The key page is https://conare.ai/dashboard/keys.
|
|
464
514
|
|
|
465
515
|
## Changes in 0.33.0
|
|
466
516
|
|
package/dist/cli/args.js
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
// Command line: `conare sync [sessions]`, `conare sync status`, `conare sync github <owner/repo>...`.
|
|
2
|
-
export const HELP = `
|
|
3
|
-
|
|
2
|
+
export const HELP = `Start: create a key at https://conare.ai/dashboard/keys (access is by invitation:
|
|
3
|
+
https://conare.ai/request-access), then run
|
|
4
|
+
npx conare sync --key sk-conare-… --install
|
|
5
|
+
|
|
6
|
+
Usage:
|
|
7
|
+
conare sync [options] coding agent sessions -> namespace "sessions"
|
|
4
8
|
conare sync status the last sessions sync; exits 1 when its last success is over 1 h old or it missed transcripts
|
|
5
9
|
conare sync github <owner/repo>... [opts] issues, PRs and markdown docs -> "<repo>-github", "<repo>-docs"
|
|
6
10
|
|
|
11
|
+
Synced: Claude Code, Codex, Cursor (on Node 22.13 or newer, or Bun), Pi. Not synced yet: OpenCode, Grok.
|
|
12
|
+
|
|
7
13
|
Run it as npx conare … or bunx conare …. Only new or changed sessions, threads and docs are
|
|
8
14
|
sent; secrets are redacted first. To leave a project's sessions out, put its name (its git
|
|
9
15
|
repository's, else its directory's) on a line of ~/.conare/sync-exclude; sessions it already
|
|
10
|
-
uploaded stay until you delete them.
|
|
16
|
+
uploaded stay until you delete them. A session deleted in the console is uploaded again by a
|
|
17
|
+
later run (within a day) unless its project is in that file.
|
|
11
18
|
|
|
12
19
|
Options:
|
|
13
20
|
--dry-run count what would upload; upload nothing
|
|
@@ -16,17 +23,27 @@ Options:
|
|
|
16
23
|
--uninstall sessions: stop the background sync
|
|
17
24
|
--via <command> with --install: the schedule runs \`<command> node … sync\`, which
|
|
18
25
|
supplies CONARE_API_KEY (e.g. --via ops); no key is saved to disk
|
|
26
|
+
--org <org_…> the organization to write to, for a key of several (else CONARE_ORG)
|
|
19
27
|
--state <file> github: what was synced (default ~/.conare/github-state.json)
|
|
20
28
|
--key <key> save an API key (sk-conare-…) to ~/.conare/sync.json, then sync
|
|
21
29
|
-v, --version print the version
|
|
22
30
|
-h, --help show this help
|
|
23
31
|
|
|
24
|
-
Exit codes: 0 done; 1 error
|
|
25
|
-
|
|
32
|
+
Exit codes: 0 done; 1 error (a GitHub token or repository refused included); 2 bad arguments;
|
|
33
|
+
3 the API key was refused, may not write the namespace, or acts for several organizations
|
|
34
|
+
without --org; 4 incomplete (documents refused, the API unreachable, or another sync running),
|
|
35
|
+
tried again next run; 5 out of credits or over a spend cap (https://conare.ai/dashboard/billing).
|
|
36
|
+
With --quiet, a sessions sync that finds another running exits 0. --install schedules the sync
|
|
37
|
+
only after a first run that exits 0 or 4.
|
|
26
38
|
|
|
27
39
|
The key comes from --key, else CONARE_API_KEY, else ~/.conare/sync.json.
|
|
28
|
-
Create one at https://conare.ai/
|
|
40
|
+
Create one at https://conare.ai/dashboard/keys. GitHub: GITHUB_TOKEN, else \`gh auth token\`.
|
|
29
41
|
`;
|
|
42
|
+
/** What the old CLI's flags and commands get (it was retired with its API, cmem_ keys and all). */
|
|
43
|
+
export const LEGACY_USAGE = `That is the old Conare CLI, retired on 2026-10-02 (cmem_ keys no longer work). Create a key at https://conare.ai/dashboard/keys (access is by invitation: https://conare.ai/request-access), then run:
|
|
44
|
+
npx conare@latest sync --key sk-conare-… --install`;
|
|
45
|
+
const LEGACY_FLAGS = new Set(["--install-sync", "--uninstall-sync", "--ingest-only", "--config-only", "--interactive", "--index", "--project", "--changed", "--force", "--source", "--sync-interval", "--wasm-dir", "--config-file", "--persist-bundle"]);
|
|
46
|
+
const LEGACY_COMMANDS = new Set(["install", "logout", "doctor", "savings"]);
|
|
30
47
|
const REPO = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/;
|
|
31
48
|
/**
|
|
32
49
|
* The name "<name>-github" and "<name>-docs" start with, for owner/repo: the repository's name
|
|
@@ -75,6 +92,8 @@ export function parseArgs(argv) {
|
|
|
75
92
|
const key = value();
|
|
76
93
|
if (!key)
|
|
77
94
|
return { error: "--key needs a value: --key sk-conare-…" };
|
|
95
|
+
if (key.startsWith("cmem_"))
|
|
96
|
+
return { error: LEGACY_USAGE };
|
|
78
97
|
if (!key.startsWith("sk-conare-"))
|
|
79
98
|
return { error: "The key should start with sk-conare-." };
|
|
80
99
|
args.key = key;
|
|
@@ -94,7 +113,16 @@ export function parseArgs(argv) {
|
|
|
94
113
|
args.state = state;
|
|
95
114
|
break;
|
|
96
115
|
}
|
|
116
|
+
case "--org": {
|
|
117
|
+
const org = value();
|
|
118
|
+
if (!org)
|
|
119
|
+
return { error: "--org needs an organization id: --org org_…" };
|
|
120
|
+
args.org = org;
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
97
123
|
default:
|
|
124
|
+
if (LEGACY_FLAGS.has(flag))
|
|
125
|
+
return { error: LEGACY_USAGE };
|
|
98
126
|
if (flag.startsWith("-"))
|
|
99
127
|
return { error: `Unknown argument: ${arg}` };
|
|
100
128
|
words.push(arg);
|
|
@@ -103,9 +131,11 @@ export function parseArgs(argv) {
|
|
|
103
131
|
if (args.help || args.version)
|
|
104
132
|
return args;
|
|
105
133
|
const [command, sub, ...more] = words;
|
|
106
|
-
if (command === undefined)
|
|
107
|
-
return { ...args, help: true };
|
|
108
|
-
if (command !==
|
|
134
|
+
if (command === undefined && !args.key)
|
|
135
|
+
return { ...args, help: true }; // a bare --key means sync
|
|
136
|
+
if (command !== undefined && LEGACY_COMMANDS.has(command))
|
|
137
|
+
return { error: LEGACY_USAGE };
|
|
138
|
+
if (command !== undefined && command !== "sync")
|
|
109
139
|
return { error: `Unknown command: ${command}` };
|
|
110
140
|
if (sub === undefined || sub === "sessions" || sub === "status") {
|
|
111
141
|
if (more.length > 0)
|
package/dist/cli/config.js
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
import { chmodSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { dirname, join } from "node:path";
|
|
5
|
-
export function resolvePaths(env = process.env, home = homedir()) {
|
|
5
|
+
export function resolvePaths(env = process.env, home = homedir(), platform = process.platform) {
|
|
6
6
|
const dir = join(home, ".conare");
|
|
7
|
+
const tilde = (p) => (p.startsWith("~/") ? join(home, p.slice(2)) : p); // Pi expands "~" in its own variables
|
|
7
8
|
return {
|
|
8
9
|
dir,
|
|
9
10
|
keyFile: join(dir, "sync.json"),
|
|
@@ -16,8 +17,18 @@ export function resolvePaths(env = process.env, home = homedir()) {
|
|
|
16
17
|
installRoot: join(dir, "sync"),
|
|
17
18
|
claudeDir: env.CLAUDE_CONFIG_DIR || join(home, ".claude"),
|
|
18
19
|
codexDir: env.CODEX_HOME || join(home, ".codex"),
|
|
20
|
+
piDir: env.PI_CODING_AGENT_SESSION_DIR
|
|
21
|
+
? tilde(env.PI_CODING_AGENT_SESSION_DIR)
|
|
22
|
+
: join(env.PI_CODING_AGENT_DIR ? tilde(env.PI_CODING_AGENT_DIR) : join(home, ".pi", "agent"), "sessions"),
|
|
23
|
+
cursorDb: cursorDbPath(home, platform),
|
|
24
|
+
cursorListFile: join(dir, "cursor-composers.json"),
|
|
19
25
|
};
|
|
20
26
|
}
|
|
27
|
+
/** Where Cursor keeps its chats: under ~/Library/Application Support on macOS, else ~/.config. */
|
|
28
|
+
export function cursorDbPath(home, platform) {
|
|
29
|
+
const base = platform === "darwin" ? join(home, "Library", "Application Support") : join(home, ".config");
|
|
30
|
+
return join(base, "Cursor", "User", "globalStorage", "state.vscdb");
|
|
31
|
+
}
|
|
21
32
|
export function readSavedKey(keyFile) {
|
|
22
33
|
try {
|
|
23
34
|
const key = JSON.parse(readFileSync(keyFile, "utf8")).api_key;
|
|
@@ -47,6 +58,15 @@ export function readExcluded(file) {
|
|
|
47
58
|
export function saveKey(keyFile, key) {
|
|
48
59
|
writePrivate(keyFile, `${JSON.stringify({ api_key: key }, null, 2)}\n`);
|
|
49
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* ~/.conare readable by the user only: it holds the key, the state and the log of what was
|
|
63
|
+
* synced. mkdir's mode applies only when it creates the directory, so one made by an older
|
|
64
|
+
* version or another tool is narrowed here.
|
|
65
|
+
*/
|
|
66
|
+
export function privateDir(dir) {
|
|
67
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
68
|
+
chmodSync(dir, 0o700);
|
|
69
|
+
}
|
|
50
70
|
/** Atomic write readable only by the user (the directory too). */
|
|
51
71
|
export function writePrivate(path, content) {
|
|
52
72
|
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
package/dist/cli/documents.js
CHANGED
|
@@ -13,9 +13,9 @@ export const NAMESPACE = "sessions";
|
|
|
13
13
|
*/
|
|
14
14
|
export const PART_BYTES = 250_000;
|
|
15
15
|
const METADATA_VALUE_BYTES = 4096;
|
|
16
|
-
/** claude:<session>, claude:<session>:agent:<agent>, codex:<session>. */
|
|
16
|
+
/** claude:<session>, claude:<session>:agent:<agent>, codex:<session>, pi:<session>, cursor:<composer>. */
|
|
17
17
|
export function baseId(t) {
|
|
18
|
-
const prefix = t.source === "
|
|
18
|
+
const prefix = t.source === "claude-code" ? "claude" : t.source;
|
|
19
19
|
return `${prefix}:${idSegment(t.sessionId)}${t.agentId ? `:agent:${idSegment(t.agentId)}` : ""}`;
|
|
20
20
|
}
|
|
21
21
|
/** <base>:part:000001 for n = 1. */
|
|
@@ -42,6 +42,7 @@ export function toDocuments(t, project) {
|
|
|
42
42
|
set("source", t.source);
|
|
43
43
|
set("session_id", t.sessionId);
|
|
44
44
|
set("agent_id", t.agentId);
|
|
45
|
+
set("entrypoint", t.entrypoint); // what started it: "claude-desktop", "sdk-go" (an Agent SDK app), …
|
|
45
46
|
set("project", project);
|
|
46
47
|
set("cwd", t.cwd);
|
|
47
48
|
set("git_branch", t.branch);
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// The old Conare CLI (npm conare 0.7.x and earlier, cmem_ keys) installed itself with
|
|
2
|
+
// --install-sync: ~/.conare/bin/conare-ingest.mjs, a `conare` command (~/.conare/bin/conare,
|
|
3
|
+
// linked from /usr/local/bin or put on PATH) and a job running it every 10 minutes. Its API was
|
|
4
|
+
// removed on 2026-10-02, so that job fails every run and the command answers "Invalid API key".
|
|
5
|
+
// retireLegacy removes the job and the old program, and points the command at this CLI.
|
|
6
|
+
import { execFileSync } from "node:child_process";
|
|
7
|
+
import { chmodSync, existsSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { homedir } from "node:os";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { UNIT, systemdDir } from "./schedule.js";
|
|
11
|
+
export const LEGACY_LABEL = "ai.conare.ingest";
|
|
12
|
+
/** What the old CLI copied to ~/.conare/bin besides the command. ~/.conare/config.json stays. */
|
|
13
|
+
const LEGACY_FILES = ["conare-ingest.mjs", "run.sh", "run.cmd", "run.vbs", "node_modules"];
|
|
14
|
+
const exec = (cmd, args, input) => execFileSync(cmd, args, { input, encoding: "utf8", stdio: ["pipe", "pipe", "ignore"] });
|
|
15
|
+
/**
|
|
16
|
+
* Remove the old CLI's background job and program files, and point its `conare` command (only
|
|
17
|
+
* where it exists) at `script` run by node. Returns a line per thing done; nothing on a machine
|
|
18
|
+
* without the old CLI. Never throws: a failed cleanup must not fail the caller.
|
|
19
|
+
*/
|
|
20
|
+
export function retireLegacy(runtime, script, s) {
|
|
21
|
+
// Windows is left alone: --install does not run there, and deleting run.vbs under the old
|
|
22
|
+
// scheduled task would put a script error on screen every 10 minutes.
|
|
23
|
+
if (s.platform !== "darwin" && s.platform !== "linux")
|
|
24
|
+
return [];
|
|
25
|
+
const r = s.run ?? exec;
|
|
26
|
+
const home = s.home ?? homedir();
|
|
27
|
+
const bin = join(home, ".conare", "bin");
|
|
28
|
+
const out = [];
|
|
29
|
+
const jobs = [];
|
|
30
|
+
const attempt = (f) => {
|
|
31
|
+
try {
|
|
32
|
+
f();
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
// Best effort: the rest still runs.
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
attempt(() => {
|
|
39
|
+
const wrapper = join(bin, "conare");
|
|
40
|
+
if (!existsSync(wrapper))
|
|
41
|
+
return;
|
|
42
|
+
// Rewritten in place, so the /usr/local/bin link or the PATH entry the old CLI made still finds it.
|
|
43
|
+
const text = `#!/bin/sh
|
|
44
|
+
# The conare command: the Conare CLI installed in ~/.conare/sync (each npx conare sync --install rewrites this).
|
|
45
|
+
NODE=$(command -v node) || NODE=${sh(runtime)}
|
|
46
|
+
exec "$NODE" ${sh(script)} "$@"
|
|
47
|
+
`;
|
|
48
|
+
if (readFileSync(wrapper, "utf8") === text)
|
|
49
|
+
return;
|
|
50
|
+
const tmp = `${wrapper}.${process.pid}.tmp`;
|
|
51
|
+
writeFileSync(tmp, text);
|
|
52
|
+
chmodSync(tmp, 0o755);
|
|
53
|
+
renameSync(tmp, wrapper);
|
|
54
|
+
out.push("The conare command now runs this version.");
|
|
55
|
+
});
|
|
56
|
+
if (existsSync(bin)) {
|
|
57
|
+
for (const f of LEGACY_FILES)
|
|
58
|
+
attempt(() => rmSync(join(bin, f), { recursive: true, force: true }));
|
|
59
|
+
attempt(() => {
|
|
60
|
+
// Its cron line (Linux without systemd; older macOS installs): `*/10 * * * * "~/.conare/bin/run.sh" # conare-sync`.
|
|
61
|
+
let tab;
|
|
62
|
+
try {
|
|
63
|
+
tab = r("crontab", ["-l"]);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return; // no crontab
|
|
67
|
+
}
|
|
68
|
+
const lines = tab.split("\n");
|
|
69
|
+
const kept = lines.filter((l) => !l.endsWith("# conare-sync") && !l.includes(".conare/bin/run.sh"));
|
|
70
|
+
if (kept.length === lines.length)
|
|
71
|
+
return;
|
|
72
|
+
r("crontab", ["-"], kept.join("\n"));
|
|
73
|
+
jobs.push("cron");
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
if (s.platform === "linux") {
|
|
77
|
+
attempt(() => {
|
|
78
|
+
// The old units share the new one's name (conare-sync); they are the old CLI's only while
|
|
79
|
+
// the service still runs ~/.conare/bin/run.sh. The old CLI wrote them under ~/.config always.
|
|
80
|
+
const dir = join(home, ".config", "systemd", "user");
|
|
81
|
+
const service = join(dir, `${UNIT}.service`);
|
|
82
|
+
if (!existsSync(service) || !readFileSync(service, "utf8").includes(".conare/bin/run.sh"))
|
|
83
|
+
return;
|
|
84
|
+
// A new timer in $XDG_CONFIG_HOME is the one systemctl would act on: leave it running.
|
|
85
|
+
const ours = systemdDir(s.env, home) !== dir && existsSync(join(systemdDir(s.env, home), `${UNIT}.timer`));
|
|
86
|
+
if (!ours)
|
|
87
|
+
attempt(() => r("systemctl", ["--user", "disable", "--now", `${UNIT}.timer`]));
|
|
88
|
+
rmSync(join(dir, `${UNIT}.timer`), { force: true });
|
|
89
|
+
rmSync(service, { force: true });
|
|
90
|
+
attempt(() => r("systemctl", ["--user", "daemon-reload"]));
|
|
91
|
+
jobs.push(`systemd ${UNIT}.timer`);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (s.platform === "darwin") {
|
|
95
|
+
attempt(() => {
|
|
96
|
+
const plist = join(home, "Library", "LaunchAgents", `${LEGACY_LABEL}.plist`);
|
|
97
|
+
if (!existsSync(plist))
|
|
98
|
+
return;
|
|
99
|
+
rmSync(plist, { force: true });
|
|
100
|
+
jobs.push(LEGACY_LABEL);
|
|
101
|
+
attempt(() => r("launchctl", ["bootout", `gui/${s.uid ?? process.getuid?.() ?? 0}/${LEGACY_LABEL}`]));
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
if (jobs.length > 0)
|
|
105
|
+
out.unshift(`Removed the old Conare CLI's background job (${jobs.join(", ")}).`);
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
/** A single-quoted sh word. */
|
|
109
|
+
function sh(s) {
|
|
110
|
+
return `'${s.replace(/'/g, `'\\''`)}'`;
|
|
111
|
+
}
|