@operad-io/memory 0.2.0 → 0.3.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/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@operad-io/memory",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/index.ts"
7
7
  },
8
8
  "dependencies": {
9
- "@operad-io/engine": "0.2.0"
9
+ "@operad-io/engine": "0.3.0"
10
10
  },
11
11
  "description": "operad: the memory plugin and the wiki",
12
12
  "repository": {
@@ -48,6 +48,12 @@ not write it into a note.
48
48
  - `memory/instructions.md`: a person's long-standing instructions to you, in
49
49
  their words.
50
50
 
51
+ Work that spans several runs (a follow-up, a scheduled prompt, a long
52
+ task) keeps one progress file under your `memory/`, such as
53
+ `memory/topics/progress-<name>.md`, with one line in the index. Update that file
54
+ at the end of each run (what is done, what is next) and read it at the start of
55
+ the next, instead of starting again.
56
+
51
57
  Write without asking. Keep edits small, supersede an old note instead of
52
58
  deleting it, and say in the new note what it replaces.
53
59
 
package/src/commit.ts CHANGED
@@ -133,6 +133,7 @@ export function commitChanges(
133
133
  message: string,
134
134
  options: { readonly allowEmpty?: boolean | undefined } = {},
135
135
  ): CommitInfo | undefined {
136
+ if (!repository.tracked) return undefined;
136
137
  const paths = pathIn(repository.root, directory);
137
138
  const status = memoryGit(repository.root, ["status", "--porcelain", "--", paths]);
138
139
  if (!status.ok) {
package/src/memory.ts CHANGED
@@ -10,6 +10,7 @@ import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from
10
10
  import { homedir } from "node:os";
11
11
  import { isAbsolute, join, relative, resolve } from "node:path";
12
12
  import { fileURLToPath } from "node:url";
13
+ import { findGit, GIT_NOT_INSTALLED, realGitFinderHost, type GitFinderHost } from "@operad-io/engine/platform";
13
14
  import { configPath, isRecord, prepareSettings, type ActionArgsSchema, type JsonValue } from "@operad-io/engine";
14
15
 
15
16
  /** The plugin name. */
@@ -107,6 +108,13 @@ export function wikiDirectoryOfHome(home: string, userHome: string = homedir()):
107
108
  }
108
109
  }
109
110
 
111
+ /** Test-only: the machine git is looked for on, when set. */
112
+ export const memoryTestHooks: { finder?: GitFinderHost | undefined } = {};
113
+
114
+ function findMemoryGit(env: Readonly<Record<string, string | undefined>>): string | undefined {
115
+ return findGit(memoryTestHooks.finder ?? { ...realGitFinderHost(), env });
116
+ }
117
+
110
118
  /** One git run. */
111
119
  export interface GitResult {
112
120
  readonly ok: boolean;
@@ -116,12 +124,15 @@ export interface GitResult {
116
124
 
117
125
  /** Runs git without a shell; output is trimmed. */
118
126
  export function memoryGit(cwd: string, args: readonly string[]): GitResult {
127
+ const env = { ...process.env, GIT_TERMINAL_PROMPT: "0" };
128
+ const program = findMemoryGit(env);
129
+ if (program === undefined) return { ok: false, out: "", err: GIT_NOT_INSTALLED };
119
130
  const result = Bun.spawnSync({
120
- cmd: ["git", "-C", cwd, ...args],
131
+ cmd: [program, "-C", cwd, ...args],
121
132
  stdin: "ignore",
122
133
  stdout: "pipe",
123
134
  stderr: "pipe",
124
- env: { ...process.env, GIT_TERMINAL_PROMPT: "0" },
135
+ env,
125
136
  timeout: 20_000,
126
137
  killSignal: "SIGKILL",
127
138
  });
@@ -140,6 +151,8 @@ export interface Repository {
140
151
  readonly directory: string;
141
152
  /** Whether this call made the repository. */
142
153
  readonly created: boolean;
154
+ /** False when no git program is on this machine: a plain folder with no history until git appears. */
155
+ readonly tracked: boolean;
143
156
  }
144
157
 
145
158
  /**
@@ -149,6 +162,8 @@ export interface Repository {
149
162
  */
150
163
  export function ensureRepository(directory: string): Repository {
151
164
  mkdirSync(directory, { recursive: true });
165
+ // No git program (on a Mac, no command line tools): a plain folder, no error.
166
+ if (findMemoryGit(process.env) === undefined) return { root: directory, directory, created: false, tracked: false };
152
167
  // git answers with a real path. Reading the directory through its real path
153
168
  // too keeps the two comparable, so a repository that is this directory keeps
154
169
  // the name the caller gave it.
@@ -156,13 +171,13 @@ export function ensureRepository(directory: string): Repository {
156
171
  const found = memoryGit(real, ["rev-parse", "--show-toplevel"]);
157
172
  if (found.ok && found.out.length > 0) {
158
173
  const same = found.out === real;
159
- return { root: same ? directory : found.out, directory: same ? directory : real, created: false };
174
+ return { root: same ? directory : found.out, directory: same ? directory : real, created: false, tracked: true };
160
175
  }
161
176
  const made = memoryGit(real, ["init", "--quiet"]);
162
177
  if (!made.ok) {
163
178
  throw new MemoryError(`git init in ${directory} failed: ${made.err || "git wrote nothing"}`);
164
179
  }
165
- return { root: directory, directory, created: true };
180
+ return { root: directory, directory, created: true, tracked: true };
166
181
  }
167
182
 
168
183
  /** The wiki: created when missing, and a repository when it is not one. */