graphcoding 0.2.0__tar.gz → 0.4.0__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: graphcoding
3
- Version: 0.2.0
3
+ Version: 0.4.0
4
4
  Summary: Draw the graph of the system you want — then code until the repo matches. Future files and scheduled deletions are graph data; a drift gate blocks commits until code and declared design converge.
5
5
  Author: Mosab Sayyed
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "graphcoding"
7
- version = "0.2.0"
7
+ version = "0.4.0"
8
8
  description = "Draw the graph of the system you want — then code until the repo matches. Future files and scheduled deletions are graph data; a drift gate blocks commits until code and declared design converge."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -3,4 +3,4 @@
3
3
  Query before you touch code. Design in the graph. Sync as you go.
4
4
  Drift is caught by tooling, not memory.
5
5
  """
6
- __version__ = "0.2.0"
6
+ __version__ = "0.4.0"
@@ -21,8 +21,9 @@ import sys
21
21
  from . import __version__
22
22
  from .drift import blocking_count, compute_drift, format_report
23
23
  from .scan import scan_repo, trackable
24
- from .store import (DEFAULT_CONFIG, EDGE_TYPES, GRAPH_DIR, NODE_TYPES, Graph,
25
- Node, config_path, find_root, load_config)
24
+ from .store import (DEFAULT_CONFIG, EDGE_TYPE_RE, EDGE_TYPES, GRAPH_DIR,
25
+ NODE_TYPES, Graph, Node, config_path, find_root,
26
+ load_config)
26
27
  from .sync import sync as run_sync
27
28
  from . import hooks as hooks_mod
28
29
 
@@ -109,8 +110,9 @@ def cmd_plan(args) -> None:
109
110
  except ValueError:
110
111
  sys.exit(f"bad --edge '{spec}' (want TYPE:target, e.g. IMPORTS:src/db.py)")
111
112
  etype = etype.upper()
112
- if etype not in EDGE_TYPES:
113
- sys.exit(f"unknown edge type {etype} (one of {', '.join(EDGE_TYPES)})")
113
+ if not EDGE_TYPE_RE.match(etype):
114
+ sys.exit(f"bad edge type {etype} (UPPER_SNAKE word; common: "
115
+ f"{', '.join(EDGE_TYPES)})")
114
116
  node.add_edge(target, etype)
115
117
  existing = g.nodes.get(args.name)
116
118
  if existing and existing.status != "planned" and not args.force:
@@ -136,8 +138,9 @@ def cmd_link(args) -> None:
136
138
  if not src:
137
139
  sys.exit(f"unknown source node {args.source} (plan or scan it first)")
138
140
  etype = args.type.upper()
139
- if etype not in EDGE_TYPES:
140
- sys.exit(f"unknown edge type {etype} (one of {', '.join(EDGE_TYPES)})")
141
+ if not EDGE_TYPE_RE.match(etype):
142
+ sys.exit(f"bad edge type {etype} (UPPER_SNAKE word; common: "
143
+ f"{', '.join(EDGE_TYPES)})")
141
144
  added = src.add_edge(args.target, etype)
142
145
  g.save()
143
146
  note = "" if args.target in g.nodes else " (target not in graph yet — planned work)"
@@ -326,7 +329,8 @@ def build_parser() -> argparse.ArgumentParser:
326
329
  s.add_argument("name", help="repo-relative path, path::Symbol, or an external "
327
330
  "name like db:orders / api:stripe (see external_prefixes)")
328
331
  s.add_argument("--summary", "-s", help="one line: what it will do")
329
- s.add_argument("--type", "-t", default="CodeFile", choices=NODE_TYPES)
332
+ s.add_argument("--type", "-t", default="CodeFile",
333
+ help=f"free-form; common: {', '.join(NODE_TYPES)}")
330
334
  s.add_argument("--edge", "-e", action="append",
331
335
  help="TYPE:target (repeatable), e.g. -e IMPORTS:src/db.py")
332
336
  s.add_argument("--existing", action="store_true",
@@ -21,6 +21,7 @@ from __future__ import annotations
21
21
 
22
22
  import json
23
23
  import os
24
+ import re
24
25
  from dataclasses import dataclass, field
25
26
 
26
27
  NODE_TYPES = [
@@ -28,11 +29,17 @@ NODE_TYPES = [
28
29
  "Component", "Hook", "TypeDef", "ServiceDef", "ConfigFile", "Doc",
29
30
  ]
30
31
 
32
+ # Common edge vocabulary — conventions, not a schema. Any UPPER_SNAKE word is
33
+ # a valid edge type (DEPLOYED_IN, PROMOTES_TO, MIRRORS, OWNS, ...). The
34
+ # scanner owns IMPORTS; everything else is human/agent vocabulary.
31
35
  EDGE_TYPES = [
32
36
  "IMPORTS", "CALLS", "CONTAINS", "INHERITS", "IMPLEMENTS",
33
37
  "REFERENCES", "DEPENDS_ON", "RELATED_TO",
38
+ "DEPLOYED_IN", "PROMOTES_TO", "CONFIGURES",
34
39
  ]
35
40
 
41
+ EDGE_TYPE_RE = re.compile(r"^[A-Z][A-Z0-9_]*$")
42
+
36
43
  STATUSES = ["ok", "planned", "needs-analysis", "to-be-deleted"]
37
44
 
38
45
  GRAPH_DIR = ".graphcoding"
@@ -52,20 +59,20 @@ DEFAULT_CONFIG = {
52
59
  ],
53
60
  "ignore_tests": True,
54
61
  "scan_symbols": False,
55
- # nodes whose names start with these prefixes describe architecture that
56
- # is not a repo file — drift never expects one on disk:
57
- # db: database objects (db:orders, db:settings::llm_provider)
58
- # mcp: MCP servers and their tools (mcp:router::get_blast_radius)
59
- # svc: deployed services / processes (svc:api-gateway)
60
- # queue: queues / topics (queue:invoice-events)
61
- # api: third-party APIs (api:stripe::charges)
62
- # ext: anything else outside the repo
63
- "external_prefixes": ["db:", "mcp:", "svc:", "queue:", "api:", "ext:"],
64
62
  }
65
63
 
64
+ # The classification is OPEN and binary: a node is either CODE (a repo-relative
65
+ # file path — scanned, drift-gated) or ANOTHER SYSTEM (any "scheme:" name —
66
+ # declared, never expected on disk). Invent whatever schemes fit your world:
67
+ # db:orders, mcp:router::search, svc:gateway, erp:sap::orders, team:payments,
68
+ # sensor:plant-7. The scheme is yours; the lifecycle and edges are the same.
69
+ _SCHEME = re.compile(r"^[A-Za-z][A-Za-z0-9_.+-]*:(?!//)")
70
+
66
71
 
67
- def is_external(name: str, cfg: dict) -> bool:
68
- return any(name.startswith(p) for p in cfg.get("external_prefixes", []))
72
+ def is_external(name: str, cfg: dict | None = None) -> bool:
73
+ """True for 'scheme:...' names (non-file architecture). File paths never
74
+ carry a scheme; URLs (scheme://) are also treated as external."""
75
+ return bool(_SCHEME.match(name)) or "://" in name
69
76
 
70
77
 
71
78
  @dataclass
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: graphcoding
3
- Version: 0.2.0
3
+ Version: 0.4.0
4
4
  Summary: Draw the graph of the system you want — then code until the repo matches. Future files and scheduled deletions are graph data; a drift gate blocks commits until code and declared design converge.
5
5
  Author: Mosab Sayyed
6
6
  License: MIT
@@ -238,6 +238,30 @@ def test_external_nodes_db_mcp(repo, capsys):
238
238
  g = Graph.load(repo)
239
239
  assert "mcp:router::search" not in g.nodes # externals retire immediately
240
240
  run(repo, "drift", expect_exit=0)
241
+ # the classification is OPEN — any invented scheme and type work
242
+ run(repo, "plan", "erp:sap::orders", "--existing", "-t", "ErpObject",
243
+ "-s", "SAP order master; synced nightly")
244
+ run(repo, "link", "src/app.py", "REFERENCES", "erp:sap::orders")
245
+ run(repo, "drift", expect_exit=0)
246
+ g = Graph.load(repo)
247
+ assert g.nodes["erp:sap::orders"].type == "ErpObject"
248
+
249
+
250
+ def test_environments_and_open_edge_types(repo, capsys):
251
+ run(repo, "init")
252
+ run(repo, "plan", "env:prod", "--existing", "-t", "Environment",
253
+ "-s", "Production. READ-ONLY for agents; deploys via ops/deploy.sh")
254
+ run(repo, "plan", "env:staging", "--existing", "-t", "Environment",
255
+ "-s", "Staging; safe for experiments")
256
+ run(repo, "link", "env:staging", "PROMOTES_TO", "env:prod") # open edge type
257
+ run(repo, "plan", "svc:api", "--existing", "-t", "ServiceDef",
258
+ "-s", "API service", "-e", "DEPLOYED_IN:env:prod")
259
+ run(repo, "link", "src/app.py", "BAD!TYPE", "env:prod", expect_exit=1)
260
+ run(repo, "drift", expect_exit=0)
261
+ capsys.readouterr()
262
+ run(repo, "show", "env:prod")
263
+ out = capsys.readouterr().out
264
+ assert "READ-ONLY" in out and "PROMOTES_TO" in out and "DEPLOYED_IN" in out
241
265
 
242
266
 
243
267
  def test_graph_file_is_sorted_and_stable(repo):
File without changes
File without changes
File without changes