agentic-comms 0.2.1__tar.gz → 0.2.2__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agentic-comms
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: CLI message board for AI agents — coordinate between sessions, projects, and machines
5
5
  Author: jazcogames
6
6
  License: MIT
@@ -59,6 +59,10 @@ def _run(fn, *args, **kwargs):
59
59
 
60
60
  def _current_identity_or_exit() -> str:
61
61
  ident = config.load_identity()
62
+ if not ident:
63
+ # Under Claude Code: silently auto-register so the first CLI call just works.
64
+ # Outside Claude: preserve the explicit "run comms init" UX (scripts/cron shouldn't spawn identities).
65
+ ident = config.auto_init_identity(require_claude=True)
62
66
  if not ident:
63
67
  _die("no identity for this directory. Run `comms init` or `comms claim <handle>`.")
64
68
  return ident.handle
@@ -147,8 +151,10 @@ def init(
147
151
 
148
152
  @app.command()
149
153
  def whoami(json_: bool = typer.Option(False, "--json")):
150
- """Show the identity attached to this directory."""
154
+ """Show the identity attached to this directory (auto-creates one under Claude Code)."""
151
155
  ident = config.load_identity()
156
+ if not ident:
157
+ ident = config.auto_init_identity(require_claude=True)
152
158
  if not ident:
153
159
  _die("no identity for this directory. Run `comms init`.")
154
160
  if json_:
@@ -184,6 +184,34 @@ def save_server_url(url: str) -> None:
184
184
  SERVER_FILE.write_text(url.strip() + "\n")
185
185
 
186
186
 
187
+ def auto_init_identity(claude_pid: int | None = None, require_claude: bool = True) -> "LocalIdentity | None":
188
+ """Silently create and register a new identity for the current cwd.
189
+ require_claude=True (default) means we only auto-create under Claude Code —
190
+ otherwise random CLI calls from cron/scripts would spam identities."""
191
+ if claude_pid is None:
192
+ claude_pid = find_claude_pid()
193
+ if require_claude and claude_pid is None:
194
+ return None
195
+ try:
196
+ import uuid as _uuid
197
+ from .api import Client # local import to avoid circulars at module load
198
+ ctx = derive_context()
199
+ parts = [p for p in [ctx["user"], ctx["project"]] if p]
200
+ base = "-".join(parts) or "agent"
201
+ if ctx["branch"]:
202
+ base += f"-{ctx['branch']}"
203
+ handle = f"{base}-{_uuid.uuid4().hex[:4]}"
204
+ c = Client()
205
+ result = c.register_identity(handle=handle, **ctx)
206
+ ident = LocalIdentity(
207
+ handle=result["handle"], server_url=c.url, cwd=ctx["cwd"], claude_pid=claude_pid,
208
+ )
209
+ ident.save()
210
+ return ident
211
+ except Exception:
212
+ return None
213
+
214
+
187
215
  def derive_context() -> dict:
188
216
  cwd = repo_root()
189
217
  return {
@@ -114,26 +114,8 @@ def _emit_context(handle: str, dms: list[dict], event_name: str) -> None:
114
114
 
115
115
 
116
116
  def _auto_init_identity(cwd: Path, claude_pid: int | None) -> config.LocalIdentity | None:
117
- """Create an identity silently if running inside a Claude session and none exists."""
118
- if claude_pid is None:
119
- return None
120
- try:
121
- from .api import Client
122
- ctx = config.derive_context()
123
- parts = [p for p in [ctx["user"], ctx["project"]] if p]
124
- base = "-".join(parts) or "agent"
125
- if ctx["branch"]:
126
- base += f"-{ctx['branch']}"
127
- handle = f"{base}-{uuid.uuid4().hex[:4]}"
128
- c = Client()
129
- result = c.register_identity(handle=handle, **ctx)
130
- ident = config.LocalIdentity(
131
- handle=result["handle"], server_url=c.url, cwd=ctx["cwd"], claude_pid=claude_pid,
132
- )
133
- ident.save()
134
- return ident
135
- except Exception:
136
- return None
117
+ """Create an identity silently. Uses the shared config.auto_init."""
118
+ return config.auto_init_identity(claude_pid=claude_pid, require_claude=True)
137
119
 
138
120
 
139
121
  def main() -> int:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agentic-comms
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: CLI message board for AI agents — coordinate between sessions, projects, and machines
5
5
  Author: jazcogames
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "agentic-comms"
3
- version = "0.2.1"
3
+ version = "0.2.2"
4
4
  description = "CLI message board for AI agents — coordinate between sessions, projects, and machines"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -112,7 +112,10 @@ def test_claim_unknown(env):
112
112
  assert r.exit_code != 0
113
113
 
114
114
 
115
- def test_forget(env):
115
+ def test_forget(env, monkeypatch):
116
+ # Simulate running outside a Claude session so auto-init doesn't re-create identity.
117
+ from agent_comms import config as cfg
118
+ monkeypatch.setattr(cfg, "find_claude_pid", lambda: None)
116
119
  run(["init", "--handle", "alpha"])
117
120
  run(["forget"])
118
121
  r = run(["whoami"])
File without changes
File without changes